diff --git a/README.md b/README.md index 5bfe8c92e..8bde9f6ef 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ jobs: - uses: actions/labeler@v4 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" + label-fork: "${{ secrets.LABEL_FORK }}" ``` _Note: This grants access to the `GITHUB_TOKEN` so the action can make calls to GitHub's rest API_ diff --git a/action.yml b/action.yml index 92496a4d6..2fb060ee2 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,10 @@ inputs: description: 'Whether or not to remove labels when matching files are reverted' default: 'false' required: false + label-fork: + description: 'Label fork' + default: 'false' + required: false runs: using: 'node16' diff --git a/dist/index.js b/dist/index.js index cb0f54f90..1977ede03 100644 --- a/dist/index.js +++ b/dist/index.js @@ -54,11 +54,17 @@ function stringToBoolean(input) { return input.toLowerCase() === 'true' || input === '1'; } function run() { + var _a; return __awaiter(this, void 0, void 0, function* () { try { const token = core.getInput("repo-token", { required: true }); const configPath = core.getInput("configuration-path", { required: true }); const syncLabels = stringToBoolean(core.getInput("sync-labels", { required: false })); + const labelFork = stringToBoolean(core.getInput("label-fork", { required: false })); + if (!labelFork && ((_a = github.context.payload.repository) === null || _a === void 0 ? void 0 : _a.fork)) { + console.log("Workflow is not configured to label forks, exiting"); + return; + } const prNumber = getPrNumber(); if (!prNumber) { console.log("Could not get pull request number from context, exiting"); diff --git a/package.json b/package.json index 5f6995dd7..72c013078 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "labeler", - "version": "4.1.2", + "version": "5.0.0", "description": "Labels pull requests by files altered", "main": "lib/main.js", "scripts": { diff --git a/src/labeler.ts b/src/labeler.ts index 152cce1fc..ba2c2e853 100644 --- a/src/labeler.ts +++ b/src/labeler.ts @@ -27,6 +27,12 @@ export async function run() { const token = core.getInput("repo-token", { required: true }); const configPath = core.getInput("configuration-path", { required: true }); const syncLabels = stringToBoolean(core.getInput("sync-labels", { required: false })); + const labelFork = stringToBoolean(core.getInput("label-fork", { required: false })); + + if (!labelFork && github.context.payload.repository?.fork) { + console.log("Workflow is not configured to label forks, exiting"); + return; + } const prNumber = getPrNumber(); if (!prNumber) {