Skip to content

Commit

Permalink
Add failure labels (#8)
Browse files Browse the repository at this point in the history
Signed-off-by: Miki <miki@amazon.com>
  • Loading branch information
AMoo-Miki authored Jun 14, 2023
1 parent ec2ff51 commit 3a8b1f9
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 58 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/.idea
/dist
/node_modules
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ For example, if a pull request has the labels `backport staging` and `backport p
This fork has some new features on top of the original Github Action. Following is a list of new features and how to use them:

1. `files_to_skip`: This optional input option can be added to the Github Action in order to pass a list of files that can be skipped during backport.
2. `failure_labels`: This optional parameter can be used to provide a comma seperated list of labels that get added to PRs with failing backports.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ inputs:
- number: original PR's number
- title: original PR's title
default: "[Backport <%= base %>] <%= title %>"
failure_labels:
description: Comma seperated list of labels to add to the PR with failing backports
required: false
outputs:
created_pull_requests:
description: A JSON stringified object mapping the base branch of the created pull requests to their number.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backport",
"version": "2.1.0",
"version": "2.2.0",
"license": "MIT",
"main": "dist/index.js",
"files": [
Expand Down
14 changes: 14 additions & 0 deletions src/backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const getFailedBackportCommentBody = ({
};

const backport = async ({
failureLabels,
filesToSkip,
getBody,
getHead,
Expand All @@ -211,6 +212,7 @@ const backport = async ({
payload,
token,
}: {
failureLabels: string[];
filesToSkip: string[];
getBody: (
props: Readonly<{
Expand Down Expand Up @@ -345,6 +347,18 @@ const backport = async ({
repo,
},
);

if (failureLabels.length > 0) {
await github.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/labels",
{
issue_number: number,
labels: failureLabels,
owner,
repo,
},
);
}
}
});
}
Expand Down
14 changes: 0 additions & 14 deletions src/get-files-to-skip.ts

This file was deleted.

11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { context } from "@actions/github";
import type { PullRequestEvent } from "@octokit/webhooks-types";
import ensureError from "ensure-error";
import { template } from "lodash-es";
import { backport } from "./backport.js";
import { getFilesToSkip } from "./get-files-to-skip.js";
import { backport } from "./backport";
import { parseCommaDelimitedStrings } from "./utils";

const run = async () => {
try {
Expand Down Expand Up @@ -34,8 +34,12 @@ const run = async () => {
const labelRegExp = new RegExp(labelPattern);

const token = getInput("github_token", { required: true });

const filesInput = getInput("files_to_skip");
const filesToSkip = getFilesToSkip(filesInput);
const filesToSkip = parseCommaDelimitedStrings(filesInput);

const failureLabelsInput = getInput("failure_labels");
const failureLabels = parseCommaDelimitedStrings(failureLabelsInput);

if (!context.payload.pull_request) {
throw new Error(`Unsupported event action: ${context.payload.action}.`);
Expand All @@ -50,6 +54,7 @@ const run = async () => {
}

const createdPullRequestBaseBranchToNumber = await backport({
failureLabels,
filesToSkip,
getBody,
getHead,
Expand Down
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Converts a comma-delimited string into an array of strings while eliminating
* empty strings.
*/
export const parseCommaDelimitedStrings = (input?: string): string[] =>
input
?.split?.(",")
.map((item) => item.trim())
.filter((item) => item)
.filter((item, idx, labels) => labels.indexOf(item) === idx) ?? [];
1 change: 1 addition & 0 deletions xo.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
"@typescript-eslint/naming-convention": "off",
// Forbid function declarations.
"func-style": ["error", "expression", { allowArrowFunctions: true }],
"import/extensions": "off",
// Already taken care of by TypeScript.
"import/namespace": "off",
// Named export are better for static analysis.
Expand Down
89 changes: 49 additions & 40 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ ansi-styles@^3.2.1:
dependencies:
color-convert "^1.9.0"

ansi-styles@^4.1.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937"
integrity sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==
dependencies:
color-convert "^2.0.1"

argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
Expand Down Expand Up @@ -531,9 +538,8 @@ chalk@^4.0.0, chalk@^4.1.0:
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
dependencies:
ansi-styles "^3.2.1"
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"
ansi-styles "^4.1.0"
supports-color "^7.1.0"

ci-info@^3.3.0:
version "3.3.0"
Expand All @@ -545,13 +551,7 @@ clean-regexp@^1.0.0:
resolved "https://registry.yarnpkg.com/clean-regexp/-/clean-regexp-1.0.0.tgz#8df7c7aae51fd36874e8f8d05b9180bc11a3fed7"
integrity sha1-jffHquUf02h06PjQW5GAvBGj/tc=
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

clean-stack@^2.0.0:
version "2.2.0"
resolved "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz"
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==
escape-string-regexp "^1.0.5"

color-convert@^1.9.0:
version "1.9.3"
Expand All @@ -560,6 +560,13 @@ color-convert@^1.9.0:
dependencies:
color-name "1.1.3"

color-convert@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==
dependencies:
color-name "~1.1.4"

color-name@1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
Expand Down Expand Up @@ -601,7 +608,7 @@ cosmiconfig@^7.0.1:
path-type "^4.0.0"
yaml "^1.10.0"

cross-spawn@^7.0.0, cross-spawn@^7.0.2:
cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
Expand All @@ -610,12 +617,12 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2:
shebang-command "^2.0.0"
which "^2.0.1"

cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
dependencies:
safe-buffer "~5.1.1"
ms "2.0.0"

debug@^3.2.7:
version "3.2.7"
Expand All @@ -629,7 +636,7 @@ debug@^4.1.1, debug@^4.3.2:
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.0.0"
ms "2.1.2"

decamelize-keys@^1.1.0:
version "1.1.0"
Expand Down Expand Up @@ -669,7 +676,12 @@ define-properties@^1.1.3:
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"
integrity sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==
dependencies:
ms "2.1.2"
object-keys "^1.0.12"

deprecation@^2.0.0, deprecation@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/deprecation/-/deprecation-2.3.1.tgz#6368cbdb40abf3373b525ac87e4a260c3a700919"
integrity sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==

detect-indent@^6.0.0:
version "6.1.0"
Expand All @@ -686,7 +698,7 @@ dir-glob@^3.0.1:
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-3.0.1.tgz#56dbf73d992a4a93ba1584f4534063fd2e41717f"
integrity sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==
dependencies:
object-keys "^1.0.12"
path-type "^4.0.0"

doctrine@^2.1.0:
version "2.1.0"
Expand Down Expand Up @@ -738,9 +750,9 @@ error-ex@^1.3.1:
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.2.tgz#b4ac40648107fdcdcfae242f428bea8a14d4f1bf"
integrity sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==
dependencies:
ansi-colors "^4.1.1"
is-arrayish "^0.2.1"

es-abstract@^1.18.0-next.1, es-abstract@^1.19.0, es-abstract@^1.19.1:
es-abstract@^1.19.0, es-abstract@^1.19.1:
version "1.19.2"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.19.2.tgz#8f7b696d8f15b167ae3640b4060670f3d054143f"
integrity sha512-gfSBJoZdlL2xRiOCy0g8gLMryhoe1TlimjzU99L/31Z8QEGIhVQI+EWwt5lT+AuU9SnorVupXFqqOGqGfsyO6w==
Expand All @@ -766,6 +778,15 @@ es-abstract@^1.18.0-next.1, es-abstract@^1.19.0, es-abstract@^1.19.1:
string.prototype.trimstart "^1.0.4"
unbox-primitive "^1.0.1"

es-to-primitive@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.2.1.tgz#e55cd4c9cdc188bcefb03b366c736323fc5c898a"
integrity sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==
dependencies:
is-callable "^1.1.4"
is-date-object "^1.0.1"
is-symbol "^1.0.2"

escape-string-regexp@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
Expand Down Expand Up @@ -923,19 +944,7 @@ eslint-plugin-sort-destructure-keys@^1.4.0:
resolved "https://registry.yarnpkg.com/eslint-plugin-sort-destructure-keys/-/eslint-plugin-sort-destructure-keys-1.4.0.tgz#45924521e556692002522468a75b6a9fbac11316"
integrity sha512-txU9l22mblz7YpyjJNYFy4wb5PVXiRMbc9lqFPPhvY4wKyBBYQvb31TIcduf7iRb4Bv01aiXcJiuCkOOrVY48Q==
dependencies:
array-includes "^3.1.1"
array.prototype.flat "^1.2.3"
contains-path "^0.1.0"
debug "^2.6.9"
doctrine "1.5.0"
eslint-import-resolver-node "^0.3.4"
eslint-module-utils "^2.6.0"
has "^1.0.3"
minimatch "^3.0.4"
object.values "^1.1.1"
read-pkg-up "^2.0.0"
resolve "^1.17.0"
tsconfig-paths "^3.9.0"
natural-compare-lite "^1.4.0"

eslint-plugin-typescript-sort-keys@^2.1.0:
version "2.1.0"
Expand Down Expand Up @@ -1100,6 +1109,11 @@ estraverse@^5.1.0, estraverse@^5.2.0:
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-5.3.0.tgz#2eea5290702f26ab8fe5370370ff86c965d21123"
integrity sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==

esutils@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

execa@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd"
Expand Down Expand Up @@ -2363,16 +2377,11 @@ safe-regex@^2.1.1:
dependencies:
regexp-tree "~0.1.1"

"semver@2 || 3 || 4 || 5":
"semver@2 || 3 || 4 || 5", semver@^5.7.1:
version "5.7.1"
resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

semver@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

semver@^6.0.0, semver@^6.1.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
Expand Down

0 comments on commit 3a8b1f9

Please sign in to comment.