Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move github api requests out of the way #711

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34310,7 +34310,7 @@ async function main() {
if (!process.env.GITHUB_TOKEN) {
core.setFailed(
`GITHUB_TOKEN is not configured. Make sure you made it available to your action

uses: gr2m/create-or-update-pull-request-action@master
env:
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}`
Expand All @@ -34331,10 +34331,6 @@ async function main() {
return;
}

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});

const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");

try {
Expand Down Expand Up @@ -34366,15 +34362,6 @@ async function main() {
process.exit(1);
}

const {
data: { default_branch },
} = await octokit.request(`GET /repos/{owner}/{repo}`, {
owner,
repo,
});
const DEFAULT_BRANCH = default_branch;
core.debug(`DEFAULT_BRANCH: ${DEFAULT_BRANCH}`);

const { hasChanges } = await getLocalChanges(inputs.path);

if (!hasChanges) {
Expand Down Expand Up @@ -34425,6 +34412,19 @@ async function main() {
`git rev-parse --abbrev-ref HEAD`
);

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});

const {
data: { default_branch },
} = await octokit.request(`GET /repos/{owner}/{repo}`, {
owner,
repo,
});
const DEFAULT_BRANCH = default_branch;
core.debug(`DEFAULT_BRANCH: ${DEFAULT_BRANCH}`);

if (currentBranch === DEFAULT_BRANCH) {
core.info(`Already in base branch "${currentBranch}".`);
} else {
Expand Down
28 changes: 14 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async function main() {
if (!process.env.GITHUB_TOKEN) {
core.setFailed(
`GITHUB_TOKEN is not configured. Make sure you made it available to your action

uses: gr2m/create-or-update-pull-request-action@master
env:
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}`
Expand All @@ -36,10 +36,6 @@ async function main() {
return;
}

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});

const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");

try {
Expand Down Expand Up @@ -71,15 +67,6 @@ async function main() {
process.exit(1);
}

const {
data: { default_branch },
} = await octokit.request(`GET /repos/{owner}/{repo}`, {
owner,
repo,
});
const DEFAULT_BRANCH = default_branch;
core.debug(`DEFAULT_BRANCH: ${DEFAULT_BRANCH}`);

const { hasChanges } = await getLocalChanges(inputs.path);

if (!hasChanges) {
Expand Down Expand Up @@ -130,6 +117,19 @@ async function main() {
`git rev-parse --abbrev-ref HEAD`
);

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});

const {
data: { default_branch },
} = await octokit.request(`GET /repos/{owner}/{repo}`, {
owner,
repo,
});
const DEFAULT_BRANCH = default_branch;
core.debug(`DEFAULT_BRANCH: ${DEFAULT_BRANCH}`);

if (currentBranch === DEFAULT_BRANCH) {
core.info(`Already in base branch "${currentBranch}".`);
} else {
Expand Down
Loading