Skip to content

Commit

Permalink
fix: move github api requests to after git checks (#713)
Browse files Browse the repository at this point in the history
Co-authored-by: Filip Skokan <panva.ip@gmail.com>
  • Loading branch information
gr2m and panva authored Nov 14, 2024
1 parent 488876a commit 0940fc1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
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

0 comments on commit 0940fc1

Please sign in to comment.