Skip to content

Commit

Permalink
feat: Skipping the job on PRs to non-default branches (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrunkat authored Aug 4, 2023
1 parent 006f81c commit e0a0f84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,16 @@ async function run() {
core.warning(`Skipping toolkit action for PR from external fork: ${(_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.head.repo.full_name}`);
return;
}
core.info('Pull request is from apify organization, not from an external fork.');
core.info('Pull request is from an apify organization, not from an external fork.');
// Skip when PR is not into the default branch. We only want to run this on PRs to develop or main when develop is not used but we
// don't want to run this on releases or PR chains.
const defaultBranch = github.context.payload.pull_request.head.repo.default_branch;
const targetBranch = github.context.payload.pull_request.base.ref;
if (defaultBranch !== targetBranch) {
core.info(`Skipping toolkit action for PR not into the default branch "${defaultBranch}" but "${targetBranch}" instead.`);
return;
}
core.info(`Pull request is into the default branch "${defaultBranch}"`);
// Octokit configured with repository token - this can be used to modify pull-request.
const repoToken = core.getInput('repo-token');
const repoOctokit = github.getOctokit(repoToken);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,17 @@ async function run(): Promise<void> {
core.warning(`Skipping toolkit action for PR from external fork: ${github.context.payload.pull_request?.head.repo.full_name}`);
return;
}
core.info('Pull request is from apify organization, not from an external fork.');
core.info('Pull request is from an apify organization, not from an external fork.');

// Skip when PR is not into the default branch. We only want to run this on PRs to develop or main when develop is not used but we
// don't want to run this on releases or PR chains.
const defaultBranch = github.context.payload.pull_request.head.repo.default_branch;
const targetBranch = github.context.payload.pull_request.base.ref;
if (defaultBranch !== targetBranch) {
core.info(`Skipping toolkit action for PR not into the default branch "${defaultBranch}" but "${targetBranch}" instead.`);
return;
}
core.info(`Pull request is into the default branch "${defaultBranch}"`);

// Octokit configured with repository token - this can be used to modify pull-request.
const repoToken = core.getInput('repo-token');
Expand Down

0 comments on commit e0a0f84

Please sign in to comment.