-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
remove_label_when_approval_missing
input. (#6)
Removing label when you lost or never had an approval status might not be what you desire to do. In some workflows when the label is manually set, removing it is automatically is harmful and it's better to leave the decision about removal to the commiters. Adding the parameter solves the problem.
- Loading branch information
Showing
11 changed files
with
2,725 additions
and
640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,8 @@ Setting label is optional that only output can be used in the workflow. | |
|
||
The required input `require_committers_approval` says is approval can be done by people with read access to the repo | ||
or by anyone. It may be useful in repositories which requires committers approvals like [Apache Software Foundation](https://github.com/apache/) | ||
projects. | ||
projects. By default, when the PR does not have "approved" status or looses its aproval status the label is removed. | ||
This behaviour can be disabled when `remove_label_when_approval_missing` is set to false. | ||
|
||
It can be used in workflows triggered by "pull_request_review" or "workflow_run". | ||
When used on "pull_request_review" any workflows triggered from pull request created from fork will fail | ||
|
@@ -43,19 +44,20 @@ Pull request number can be obtained by using [potiuk/get-workflow-origin)](https | |
|
||
## Inputs | ||
|
||
| Input | Required | Example | Comment | | ||
|-------------------------------|----------|-------------------------------------------------------------------|-------------------------------------------------------------------------------| | ||
| `token` | yes | `${{ secrets.GITHUB_TOKEN }}` | The github token passed from `${{ secrets.GITHUB_TOKEN }}` | | ||
| `label` | no | `Approved by committers` | Label to be added/removed to the Pull Request if approved/not approved | | ||
| `require_committers_approval` | no | `true` | Is approval from user with write permission required | | ||
| `comment` | no | `PR approved by at least one committer and no changes requested.` | Add optional comment to the PR when approved (requires label input to be set) | | ||
| `pullRequestNumber` | no | `${{ steps.source-run-info.outputs.pullRequestNumber }}` | Pull request number if triggered by "worfklow_run" | | ||
| Input | Required | Example | Comment | | ||
|--------------------------------------|----------|-------------------------------------------------------------------|-------------------------------------------------------------------------------| | ||
| `token` | yes | `${{ secrets.GITHUB_TOKEN }}` | The github token passed from `${{ secrets.GITHUB_TOKEN }}` | | ||
| `label` | no | `Approved by committers` | Label to be added/removed to the Pull Request if approved/not approved | | ||
| `require_committers_approval` | no | `true` | Is approval from user with write permission required | | ||
| `remove_label_when_approval_missing` | no | `true` | Should label be removed when approval is missing | | ||
| `comment` | no | `PR approved by at least one committer and no changes requested.` | Add optional comment to the PR when approved (requires label input to be set) | | ||
| `pullRequestNumber` | no | `${{ steps.source-run-info.outputs.pullRequestNumber }}` | Pull request number if triggered by "worfklow_run" | | ||
|
||
## Outputs | ||
|
||
| Output | | | ||
|----------------|------------------------------| | ||
| `isApproved` | is Pull Reqeuest approved | | ||
| `isApproved` | is Pull Request approved | | ||
| `labelSet` | was label set | | ||
| `labelRemoved` | was label removed | | ||
|
||
|
@@ -115,6 +117,7 @@ jobs: | |
token: ${{ secrets.GITHUB_TOKEN }} | ||
label: 'ready to merge (committers)' | ||
require_committers_approval: 'true' | ||
remove_label_when_approval_missing: 'false' | ||
comment: 'PR approved by at least one committer and no changes requested.' | ||
- name: Label when approved by anyone | ||
uses: TobKed/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1483,10 +1483,7 @@ function getPullRequest(octokit, owner, repo, pullRequestNumber) { | |
}); | ||
} | ||
function getPullRequestLabels(pullRequest) { | ||
const labelNames = pullRequest | ||
? pullRequest.labels.map(label => label.name) | ||
: []; | ||
return labelNames; | ||
return pullRequest ? pullRequest.labels.map(label => label.name) : []; | ||
} | ||
function getReviews(octokit, owner, repo, number, getComitters) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
|
@@ -1591,17 +1588,19 @@ function addComment(octokit, owner, repo, pullRequestNumber, comment) { | |
}); | ||
}); | ||
} | ||
function printDebug(item, description = '') { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const itemJson = JSON.stringify(item); | ||
core.debug(`\n ######### ${description} ######### \n: ${itemJson}\n\n`); | ||
}); | ||
} | ||
// async function printDebug( | ||
// item: object | string | boolean | number, | ||
// description: string = '' | ||
// ): Promise<void> { | ||
// const itemJson = JSON.stringify(item) | ||
// core.debug(`\n ######### ${description} ######### \n: ${itemJson}\n\n`) | ||
// } | ||
function run() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const token = core.getInput('token', { required: true }); | ||
const userLabel = core.getInput('label') || 'not set'; | ||
const requireCommittersApproval = core.getInput('require_committers_approval') === 'true'; | ||
const removeLabelWhenApprovalMissing = core.getInput('remove_label_when_approval_missing') === 'true'; | ||
const comment = core.getInput('comment') || ''; | ||
const pullRequestNumberInput = core.getInput('pullRequestNumber') || 'not set'; | ||
const octokit = new github.GitHub(token); | ||
|
@@ -1649,7 +1648,10 @@ function run() { | |
let isLabelShouldBeRemoved = false; | ||
if (userLabel !== 'not set') { | ||
isLabelShouldBeSet = isApproved && !labelNames.includes(userLabel); | ||
isLabelShouldBeRemoved = !isApproved && labelNames.includes(userLabel); | ||
isLabelShouldBeRemoved = | ||
!isApproved && | ||
labelNames.includes(userLabel) && | ||
removeLabelWhenApprovalMissing; | ||
if (isLabelShouldBeSet) { | ||
yield setLabel(octokit, owner, repo, pullRequest.number, userLabel); | ||
if (comment !== '') { | ||
|
@@ -2237,7 +2239,7 @@ module.exports = require("https"); | |
/***/ 215: | ||
/***/ (function(module) { | ||
|
||
module.exports = {"name":"@octokit/rest","version":"16.43.0","publishConfig":{"access":"public"},"description":"GitHub REST API client for Node.js","keywords":["octokit","github","rest","api-client"],"author":"Gregor Martynus (https://github.com/gr2m)","contributors":[{"name":"Mike de Boer","email":"[email protected]"},{"name":"Fabian Jakobs","email":"[email protected]"},{"name":"Joe Gallo","email":"[email protected]"},{"name":"Gregor Martynus","url":"https://github.com/gr2m"}],"repository":"https://github.com/octokit/rest.js","dependencies":{"@octokit/auth-token":"^2.4.0","@octokit/plugin-paginate-rest":"^1.1.1","@octokit/plugin-request-log":"^1.0.0","@octokit/plugin-rest-endpoint-methods":"2.4.0","@octokit/request":"^5.2.0","@octokit/request-error":"^1.0.2","atob-lite":"^2.0.0","before-after-hook":"^2.0.0","btoa-lite":"^1.0.0","deprecation":"^2.0.0","lodash.get":"^4.4.2","lodash.set":"^4.3.2","lodash.uniq":"^4.5.0","octokit-pagination-methods":"^1.1.0","once":"^1.4.0","universal-user-agent":"^4.0.0"},"devDependencies":{"@gimenete/type-writer":"^0.1.3","@octokit/auth":"^1.1.1","@octokit/fixtures-server":"^5.0.6","@octokit/graphql":"^4.2.0","@types/node":"^13.1.0","bundlesize":"^0.18.0","chai":"^4.1.2","compression-webpack-plugin":"^3.1.0","cypress":"^3.0.0","glob":"^7.1.2","http-proxy-agent":"^4.0.0","lodash.camelcase":"^4.3.0","lodash.merge":"^4.6.1","lodash.upperfirst":"^4.3.1","lolex":"^5.1.2","mkdirp":"^1.0.0","mocha":"^7.0.1","mustache":"^4.0.0","nock":"^11.3.3","npm-run-all":"^4.1.2","nyc":"^15.0.0","prettier":"^1.14.2","proxy":"^1.0.0","semantic-release":"^17.0.0","sinon":"^8.0.0","sinon-chai":"^3.0.0","sort-keys":"^4.0.0","string-to-arraybuffer":"^1.0.0","string-to-jsdoc-comment":"^1.0.0","typescript":"^3.3.1","webpack":"^4.0.0","webpack-bundle-analyzer":"^3.0.0","webpack-cli":"^3.0.0"},"types":"index.d.ts","scripts":{"coverage":"nyc report --reporter=html && open coverage/index.html","lint":"prettier --check '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","lint:fix":"prettier --write '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","pretest":"npm run -s lint","test":"nyc mocha test/mocha-node-setup.js \"test/*/**/*-test.js\"","test:browser":"cypress run --browser chrome","build":"npm-run-all build:*","build:ts":"npm run -s update-endpoints:typescript","prebuild:browser":"mkdirp dist/","build:browser":"npm-run-all build:browser:*","build:browser:development":"webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-rest.js --profile --json > dist/bundle-stats.json","build:browser:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-rest.min.js --devtool source-map","generate-bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","update-endpoints":"npm-run-all update-endpoints:*","update-endpoints:fetch-json":"node scripts/update-endpoints/fetch-json","update-endpoints:typescript":"node scripts/update-endpoints/typescript","prevalidate:ts":"npm run -s build:ts","validate:ts":"tsc --target es6 --noImplicitAny index.d.ts","postvalidate:ts":"tsc --noEmit --target es6 test/typescript-validate.ts","start-fixtures-server":"octokit-fixtures-server"},"license":"MIT","files":["index.js","index.d.ts","lib","plugins"],"nyc":{"ignore":["test"]},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"bundlesize":[{"path":"./dist/octokit-rest.min.js.gz","maxSize":"33 kB"}],"_resolved":"https://registry.npmjs.org/@octokit/rest/-/rest-16.43.0.tgz","_integrity":"sha512-u+OwrTxHuppVcssGmwCmb4jgPNzsRseJ2rS5PrZk2ASC+WkaF5Q7wu8zVtJ4OA24jK6aRymlwA2uwL36NU9nAA==","_from":"@octokit/[email protected]"}; | ||
module.exports = {"_args":[["@octokit/[email protected]","/home/jarek/code/label-when-approved-action"]],"_from":"@octokit/[email protected]","_id":"@octokit/[email protected]","_inBundle":false,"_integrity":"sha512-u+OwrTxHuppVcssGmwCmb4jgPNzsRseJ2rS5PrZk2ASC+WkaF5Q7wu8zVtJ4OA24jK6aRymlwA2uwL36NU9nAA==","_location":"/@octokit/rest","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"@octokit/[email protected]","name":"@octokit/rest","escapedName":"@octokit%2frest","scope":"@octokit","rawSpec":"16.43.0","saveSpec":null,"fetchSpec":"16.43.0"},"_requiredBy":["/@actions/github"],"_resolved":"https://registry.npmjs.org/@octokit/rest/-/rest-16.43.0.tgz","_spec":"16.43.0","_where":"/home/jarek/code/label-when-approved-action","author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"bugs":{"url":"https://github.com/octokit/rest.js/issues"},"bundlesize":[{"path":"./dist/octokit-rest.min.js.gz","maxSize":"33 kB"}],"contributors":[{"name":"Mike de Boer","email":"[email protected]"},{"name":"Fabian Jakobs","email":"[email protected]"},{"name":"Joe Gallo","email":"[email protected]"},{"name":"Gregor Martynus","url":"https://github.com/gr2m"}],"dependencies":{"@octokit/auth-token":"^2.4.0","@octokit/plugin-paginate-rest":"^1.1.1","@octokit/plugin-request-log":"^1.0.0","@octokit/plugin-rest-endpoint-methods":"2.4.0","@octokit/request":"^5.2.0","@octokit/request-error":"^1.0.2","atob-lite":"^2.0.0","before-after-hook":"^2.0.0","btoa-lite":"^1.0.0","deprecation":"^2.0.0","lodash.get":"^4.4.2","lodash.set":"^4.3.2","lodash.uniq":"^4.5.0","octokit-pagination-methods":"^1.1.0","once":"^1.4.0","universal-user-agent":"^4.0.0"},"description":"GitHub REST API client for Node.js","devDependencies":{"@gimenete/type-writer":"^0.1.3","@octokit/auth":"^1.1.1","@octokit/fixtures-server":"^5.0.6","@octokit/graphql":"^4.2.0","@types/node":"^13.1.0","bundlesize":"^0.18.0","chai":"^4.1.2","compression-webpack-plugin":"^3.1.0","cypress":"^3.0.0","glob":"^7.1.2","http-proxy-agent":"^4.0.0","lodash.camelcase":"^4.3.0","lodash.merge":"^4.6.1","lodash.upperfirst":"^4.3.1","lolex":"^5.1.2","mkdirp":"^1.0.0","mocha":"^7.0.1","mustache":"^4.0.0","nock":"^11.3.3","npm-run-all":"^4.1.2","nyc":"^15.0.0","prettier":"^1.14.2","proxy":"^1.0.0","semantic-release":"^17.0.0","sinon":"^8.0.0","sinon-chai":"^3.0.0","sort-keys":"^4.0.0","string-to-arraybuffer":"^1.0.0","string-to-jsdoc-comment":"^1.0.0","typescript":"^3.3.1","webpack":"^4.0.0","webpack-bundle-analyzer":"^3.0.0","webpack-cli":"^3.0.0"},"files":["index.js","index.d.ts","lib","plugins"],"homepage":"https://github.com/octokit/rest.js#readme","keywords":["octokit","github","rest","api-client"],"license":"MIT","name":"@octokit/rest","nyc":{"ignore":["test"]},"publishConfig":{"access":"public"},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"repository":{"type":"git","url":"git+https://github.com/octokit/rest.js.git"},"scripts":{"build":"npm-run-all build:*","build:browser":"npm-run-all build:browser:*","build:browser:development":"webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-rest.js --profile --json > dist/bundle-stats.json","build:browser:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-rest.min.js --devtool source-map","build:ts":"npm run -s update-endpoints:typescript","coverage":"nyc report --reporter=html && open coverage/index.html","generate-bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","lint":"prettier --check '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","lint:fix":"prettier --write '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","postvalidate:ts":"tsc --noEmit --target es6 test/typescript-validate.ts","prebuild:browser":"mkdirp dist/","pretest":"npm run -s lint","prevalidate:ts":"npm run -s build:ts","start-fixtures-server":"octokit-fixtures-server","test":"nyc mocha test/mocha-node-setup.js \"test/*/**/*-test.js\"","test:browser":"cypress run --browser chrome","update-endpoints":"npm-run-all update-endpoints:*","update-endpoints:fetch-json":"node scripts/update-endpoints/fetch-json","update-endpoints:typescript":"node scripts/update-endpoints/typescript","validate:ts":"tsc --target es6 --noImplicitAny index.d.ts"},"types":"index.d.ts","version":"16.43.0"}; | ||
|
||
/***/ }), | ||
|
||
|
@@ -3628,6 +3630,12 @@ function convertBody(buffer, headers) { | |
// html4 | ||
if (!res && str) { | ||
res = /<meta[\s]+?http-equiv=(['"])content-type\1[\s]+?content=(['"])(.+?)\2/i.exec(str); | ||
if (!res) { | ||
res = /<meta[\s]+?content=(['"])(.+?)\1[\s]+?http-equiv=(['"])content-type\3/i.exec(str); | ||
if (res) { | ||
res.pop(); // drop last quote | ||
} | ||
} | ||
|
||
if (res) { | ||
res = /charset=(.*)/i.exec(res.pop()); | ||
|
@@ -4635,7 +4643,7 @@ function fetch(url, opts) { | |
// HTTP fetch step 5.5 | ||
switch (request.redirect) { | ||
case 'error': | ||
reject(new FetchError(`redirect mode is set to error: ${request.url}`, 'no-redirect')); | ||
reject(new FetchError(`uri requested responds with a redirect, redirect mode is set to error: ${request.url}`, 'no-redirect')); | ||
finalize(); | ||
return; | ||
case 'manual': | ||
|
@@ -4674,7 +4682,8 @@ function fetch(url, opts) { | |
method: request.method, | ||
body: request.body, | ||
signal: request.signal, | ||
timeout: request.timeout | ||
timeout: request.timeout, | ||
size: request.size | ||
}; | ||
|
||
// HTTP-redirect fetch step 9 | ||
|
Oops, something went wrong.