Skip to content

Commit

Permalink
Add skip-labeled-prs option
Browse files Browse the repository at this point in the history
This option skips labeling pull requests which already have labels
present.
  • Loading branch information
fjeremic committed Apr 27, 2020
1 parent ede4d1e commit 640daaf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ inputs:
configuration-path:
description: 'The path for the label configurations'
default: '.github/labeler.yml'
skip-labeled-prs:
description: 'Determines whether the action should skip labelling pull requests which have labels already present'
default: true
operations-per-run:
description: 'The maximum number of operations per run, used to control rate limiting'
default: 30
Expand Down
5 changes: 5 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6261,6 +6261,10 @@ function processPrs(client, labelGlobs, args, operationsLeft, page = 1) {
}
for (const pr of prs.data.values()) {
console.log(`found pr #${pr.number}: ${pr.title}`);
if (args.skipLabeledPrs && pr.labels.length > 0) {
console.log(`skipping pr #${pr.number} since it has labels already`);
continue;
}
console.log(`fetching changed files for pr #${pr.number}`);
const listFilesResponse = yield client.pulls.listFiles({
owner: github.context.repo.owner,
Expand Down Expand Up @@ -6320,6 +6324,7 @@ function getAndValidateArgs() {
const args = {
repoToken: core.getInput("repo-token", { required: true }),
configurationPath: core.getInput("configuration-path"),
skipLabeledPrs: core.getInput("skip-labeled-prs", { required: true }) === 'true',
operationsPerRun: parseInt(core.getInput("operations-per-run", { required: true }))
};
for (const numberInput of ["operations-per-run"]) {
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type PullLabel = Octokit.PullsListResponseItemLabelsItem;
interface Args {
repoToken: string;
configurationPath: string;
skipLabeledPrs: boolean;
operationsPerRun: number;
}

Expand Down Expand Up @@ -84,6 +85,12 @@ async function processPrs(

for (const pr of prs.data.values()) {
console.log(`found pr #${pr.number}: ${pr.title}`);

if (args.skipLabeledPrs && pr.labels.length > 0) {
console.log(`skipping pr #${pr.number} since it has labels already`);
continue;
}

console.log(`fetching changed files for pr #${pr.number}`);

const listFilesResponse = await client.pulls.listFiles({
Expand Down Expand Up @@ -159,6 +166,7 @@ function getAndValidateArgs(): Args {
const args = {
repoToken: core.getInput("repo-token", { required: true }),
configurationPath: core.getInput("configuration-path"),
skipLabeledPrs: core.getInput("skip-labeled-prs", { required: true }) === 'true',
operationsPerRun: parseInt(
core.getInput("operations-per-run", { required: true })
)
Expand Down

0 comments on commit 640daaf

Please sign in to comment.