From 640daafc8ea7f2b94acdfbcc4845e150571aea85 Mon Sep 17 00:00:00 2001 From: Filip Jeremic Date: Mon, 27 Apr 2020 10:56:50 -0400 Subject: [PATCH] Add skip-labeled-prs option This option skips labeling pull requests which already have labels present. --- action.yml | 3 +++ dist/index.js | 5 +++++ src/index.ts | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/action.yml b/action.yml index 95017b8..a55b801 100644 --- a/action.yml +++ b/action.yml @@ -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 diff --git a/dist/index.js b/dist/index.js index a8a0da4..8197195 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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, @@ -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"]) { diff --git a/src/index.ts b/src/index.ts index 8b20ce7..2b2c3c1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ type PullLabel = Octokit.PullsListResponseItemLabelsItem; interface Args { repoToken: string; configurationPath: string; + skipLabeledPrs: boolean; operationsPerRun: number; } @@ -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({ @@ -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 }) )