Skip to content

Commit

Permalink
v9.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Sep 3, 2023
1 parent 52bcafe commit 8489273
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Backport Action
uses: sqren/backport-github-action@v9.2.1
uses: sqren/backport-github-action@v9.3.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
auto_backport_label_prefix: backport-to-
Expand Down
166 changes: 113 additions & 53 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27100,11 +27100,12 @@ const addAssigneesToPullRequest_1 = __nccwpck_require__(40419);
const addLabelsToPullRequest_1 = __nccwpck_require__(12557);
const addReviewersToPullRequest_1 = __nccwpck_require__(66313);
const createPullRequest_1 = __nccwpck_require__(48366);
const syncSourcePullRequestReviewersToTargetPullRequest_1 = __nccwpck_require__(18209);
const validateTargetBranch_1 = __nccwpck_require__(11915);
const logger_1 = __nccwpck_require__(57129);
const sequentially_1 = __nccwpck_require__(48882);
const autoMergeNowOrLater_1 = __nccwpck_require__(44224);
const copySourcePullRequestLabels_1 = __nccwpck_require__(66672);
const copySourcePullRequestReviewersToTargetPullRequest_1 = __nccwpck_require__(82105);
const getBackportBranchName_1 = __nccwpck_require__(64209);
const getMergeCommit_1 = __nccwpck_require__(14246);
const getTargetPRLabels_1 = __nccwpck_require__(35865);
Expand Down Expand Up @@ -27152,8 +27153,8 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
await (0, addReviewersToPullRequest_1.addReviewersToPullRequest)(options, targetPullRequest.number, options.reviewers);
}
// add reviewers of the original PRs to the target pull request
if (options.addOriginalReviewers) {
await (0, syncSourcePullRequestReviewersToTargetPullRequest_1.syncSourcePullRequestReviewersToTargetPullRequest)(options, commits, targetPullRequest.number);
if (options.copySourcePRReviewers) {
await (0, copySourcePullRequestReviewersToTargetPullRequest_1.copySourcePullRequestReviewersToTargetPullRequest)(options, commits, targetPullRequest.number);
}
// add labels to target pull request
if (options.targetPRLabels.length > 0) {
Expand All @@ -27169,6 +27170,9 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
labels,
});
}
if (options.copySourcePRLabels) {
await (0, copySourcePullRequestLabels_1.copySourcePullRequestLabelsToTargetPullRequest)(options, commits, targetPullRequest.number);
}
// make PR auto mergable
if (options.autoMerge && !hasAnyCommitWithConflicts) {
await (0, autoMergeNowOrLater_1.autoMergeNowOrLater)(options, targetPullRequest.number);
Expand All @@ -27194,6 +27198,62 @@ exports.cherrypickAndCreateTargetPullRequest = cherrypickAndCreateTargetPullRequ

/***/ }),

/***/ 66672:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.copySourcePullRequestLabelsToTargetPullRequest = void 0;
const addLabelsToPullRequest_1 = __nccwpck_require__(12557);
async function copySourcePullRequestLabelsToTargetPullRequest(options, commits, pullNumber) {
const labels = getNonBackportLabels(commits);
if (labels.length > 0) {
await (0, addLabelsToPullRequest_1.addLabelsToPullRequest)({ ...options, pullNumber, labels });
}
}
exports.copySourcePullRequestLabelsToTargetPullRequest = copySourcePullRequestLabelsToTargetPullRequest;
function getNonBackportLabels(commits) {
return commits.flatMap((commit) => {
if (!commit.sourcePullRequest) {
return [];
}
const backportLabels = commit.targetPullRequestStates.map((pr) => pr.label);
const labels = commit.sourcePullRequest.labels.filter((label) => !backportLabels.includes(label));
return labels;
});
}
//# sourceMappingURL=copySourcePullRequestLabels.js.map

/***/ }),

/***/ 82105:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.copySourcePullRequestReviewersToTargetPullRequest = void 0;
const filterEmpty_1 = __nccwpck_require__(97085);
const addReviewersToPullRequest_1 = __nccwpck_require__(66313);
const getReviewersFromPullRequests_1 = __nccwpck_require__(42202);
async function copySourcePullRequestReviewersToTargetPullRequest(options, commits, pullNumber) {
const pullNumbers = commits
.map((commit) => commit.sourcePullRequest?.number)
.filter(filterEmpty_1.filterNil);
const reviewers = await (0, getReviewersFromPullRequests_1.getReviewersFromPullRequests)({
options,
pullNumbers,
});
if (reviewers) {
await (0, addReviewersToPullRequest_1.addReviewersToPullRequest)(options, pullNumber, reviewers);
}
}
exports.copySourcePullRequestReviewersToTargetPullRequest = copySourcePullRequestReviewersToTargetPullRequest;
//# sourceMappingURL=copySourcePullRequestReviewersToTargetPullRequest.js.map

/***/ }),

/***/ 64209:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

Expand Down Expand Up @@ -27337,18 +27397,28 @@ const filterEmpty_1 = __nccwpck_require__(97085);
const getSourceBranchFromCommits_1 = __nccwpck_require__(66035);
const logger_1 = __nccwpck_require__(57129);
function getTargetPRLabels({ interactive, targetPRLabels, commits, targetBranch, }) {
const labels = getLabels({
commits,
targetBranch,
targetPRLabels,
interactive,
});
return (0, lodash_1.uniq)(labels);
}
exports.getTargetPRLabels = getTargetPRLabels;
function getLabels({ commits, targetBranch, targetPRLabels, interactive, }) {
const sourceBranch = (0, getSourceBranchFromCommits_1.getSourceBranchFromCommits)(commits);
const labels = commits
.flatMap((c) => {
const targetPullRequest = c.targetPullRequestStates.find((pr) => pr.branch === targetBranch);
if (!targetPullRequest?.labelRegex) {
logger_1.logger.info('Missing labelRegex for target pull request');
if (!targetPullRequest?.branchLabelMappingKey) {
logger_1.logger.info('Missing branchLabelMappingKey for target pull request');
// remove dynamic labels like `$1` in interactive mode
return targetPRLabels.filter((l) => {
return l.match(/\$\d/) === null || !interactive;
});
}
const regex = new RegExp(targetPullRequest.labelRegex);
const regex = new RegExp(targetPullRequest.branchLabelMappingKey);
return targetPRLabels.map((targetPRLabel) => {
return targetPullRequest.label?.replace(regex, targetPRLabel);
});
Expand All @@ -27359,9 +27429,8 @@ function getTargetPRLabels({ interactive, targetPRLabels, commits, targetBranch,
.replaceAll('{{targetBranch}}', targetBranch)
.replaceAll('{{sourceBranch}}', sourceBranch);
});
return (0, lodash_1.uniq)(labels);
return labels;
}
exports.getTargetPRLabels = getTargetPRLabels;
//# sourceMappingURL=getTargetPRLabels.js.map

/***/ }),
Expand Down Expand Up @@ -28608,6 +28677,7 @@ function getPullRequestBody({ options, commits, targetBranch, }) {
?.replaceAll('{{commitsStringified}}', JSON.stringify(commits));
const template = handlebars_1.default.compile(customPrDescription ?? defaultPrDescription);
return template({
sourcePullRequest: commits[0].sourcePullRequest,
sourceBranch,
targetBranch,
commitMessages,
Expand All @@ -28623,7 +28693,9 @@ function getTitle({ options, commits, targetBranch, }) {
.join(' | ');
const defaultPrTitle = '[{{targetBranch}}] {{commitMessages}}';
const template = handlebars_1.default.compile(options.prTitle ?? defaultPrTitle);
commits[0].author.name;
return template({
sourcePullRequest: commits[0].sourcePullRequest,
sourceBranch,
targetBranch,
commitMessages,
Expand Down Expand Up @@ -28898,33 +28970,6 @@ exports.mergePullRequest = mergePullRequest;

/***/ }),

/***/ 18209:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {

"use strict";

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.syncSourcePullRequestReviewersToTargetPullRequest = void 0;
const filterEmpty_1 = __nccwpck_require__(97085);
const addReviewersToPullRequest_1 = __nccwpck_require__(66313);
const getReviewersFromPullRequests_1 = __nccwpck_require__(42202);
async function syncSourcePullRequestReviewersToTargetPullRequest(options, commits, pullNumber) {
const pullNumbers = commits
.map((commit) => commit.sourcePullRequest?.number)
.filter(filterEmpty_1.filterNil);
const reviewers = await (0, getReviewersFromPullRequests_1.getReviewersFromPullRequests)({
options,
pullNumbers,
});
if (reviewers) {
await (0, addReviewersToPullRequest_1.addReviewersToPullRequest)(options, pullNumber, reviewers);
}
}
exports.syncSourcePullRequestReviewersToTargetPullRequest = syncSourcePullRequestReviewersToTargetPullRequest;
//# sourceMappingURL=syncSourcePullRequestReviewersToTargetPullRequest.js.map

/***/ }),

/***/ 58605:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

Expand Down Expand Up @@ -30538,27 +30583,32 @@ function getTargetBranchesFromLabels(sourcePullRequest, branchLabelMapping) {
.map((label) => {
const res = getTargetBranchFromLabel({ branchLabelMapping, label });
if (res) {
const { labelRegex, targetBranch } = res;
const { branchLabelMappingKey, targetBranch } = res;
const isSourceBranch = targetBranch === sourcePullRequest.baseRefName;
return { branch: targetBranch, label, labelRegex, isSourceBranch };
return {
branch: targetBranch,
label,
branchLabelMappingKey,
isSourceBranch,
};
}
})
.filter(filterEmpty_1.filterNil);
return (0, lodash_1.uniqBy)(targetBranchesFromLabels, ({ branch }) => branch);
}
function getTargetBranchFromLabel({ branchLabelMapping, label, }) {
// only get first match
const result = Object.entries(branchLabelMapping).find(([labelRegex]) => {
const regex = new RegExp(labelRegex);
const result = Object.entries(branchLabelMapping).find(([key]) => {
const regex = new RegExp(key);
const isMatch = label.match(regex) !== null;
return isMatch;
});
if (result) {
const [labelRegex, targetBranchReplaceValue] = result;
const regex = new RegExp(labelRegex);
const targetBranch = label.replace(regex, targetBranchReplaceValue);
const [branchLabelMappingKey, branchLabelMappingValue] = result;
const regex = new RegExp(branchLabelMappingKey);
const targetBranch = label.replace(regex, branchLabelMappingValue);
if (targetBranch) {
return { targetBranch, labelRegex };
return { targetBranch, branchLabelMappingKey };
}
}
}
Expand Down Expand Up @@ -31002,10 +31052,6 @@ function getOptionsFromCliArgs(processArgs) {
description: 'Add reviewer to the target PR',
type: 'array',
string: true,
})
.option('addOriginalReviewers', {
description: 'Add reviewers of the original PRs to the target PR',
type: 'boolean',
})
.option('repoForkOwner', {
description: 'The owner of the fork where the backport branch is pushed. Defaults to the currently authenticated user',
Expand All @@ -31026,6 +31072,7 @@ function getOptionsFromCliArgs(processArgs) {
})
.option('repo', {
description: 'Repo owner and name',
alias: 'upstream',
type: 'string',
conflicts: ['repoName', 'repoOwner'],
})
Expand All @@ -31044,6 +31091,16 @@ function getOptionsFromCliArgs(processArgs) {
alias: 'sourcePrLabel',
type: 'array',
string: true,
})
.option('copySourcePRLabels', {
description: 'Copy labels from source PR to the target PR',
alias: 'copySourcePrLabels',
type: 'boolean',
})
.option('copySourcePRReviewers', {
description: 'Copy reviewers from the source PR to the target PR',
alias: ['copySourcePrReviewers', 'addOriginalReviewers'],
type: 'boolean',
})
.option('targetBranch', {
description: 'Branch(es) to backport to',
Expand Down Expand Up @@ -31292,7 +31349,7 @@ async function readConfigFile(filepath) {
}
exports.readConfigFile = readConfigFile;
// ensure backwards compatability when config options are renamed
function withConfigMigrations({ upstream, labels, branches, ...config }) {
function withConfigMigrations({ upstream, labels, branches, addOriginalReviewers, ...config }) {
const { repoName, repoOwner } = parseUpstream(upstream, config);
return (0, excludeUndefined_1.excludeUndefined)({
...config,
Expand All @@ -31301,6 +31358,8 @@ function withConfigMigrations({ upstream, labels, branches, ...config }) {
// `upstream` has been renamed to `repoOwner`/`repoName`
repoName,
repoOwner,
// `addOriginalReviewers` has been renamed to `copySourcePRReviewers`
copySourcePRReviewers: config.copySourcePRReviewers ?? addOriginalReviewers,
// `labels` was renamed `targetPRLabels`
targetPRLabels: config.targetPRLabels ?? labels,
});
Expand Down Expand Up @@ -31338,7 +31397,6 @@ const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/do
const GLOBAL_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/config-file-options.md#global-config-backportconfigjson';
exports.defaultConfigOptions = {
assignees: [],
addOriginalReviewers: false,
autoAssign: false,
autoMerge: false,
autoMergeMethod: 'merge',
Expand All @@ -31350,7 +31408,6 @@ exports.defaultConfigOptions = {
dateSince: null,
dateUntil: null,
details: false,
telemetry: true,
fork: true,
gitHostname: 'github.com',
interactive: true,
Expand All @@ -31359,15 +31416,18 @@ exports.defaultConfigOptions = {
multipleCommits: false,
noVerify: true,
publishStatusCommentOnAbort: false,
publishStatusCommentOnSuccess: true,
publishStatusCommentOnFailure: false,
publishStatusCommentOnSuccess: true,
resetAuthor: false,
reviewers: [],
signoff: false,
sourcePRLabels: [],
copySourcePRLabels: false,
copySourcePRReviewers: false,
targetBranchChoices: [],
targetBranches: [],
targetPRLabels: [],
signoff: false,
telemetry: true,
};
async function getOptions({ optionsFromCliArgs, optionsFromModule, }) {
const optionsFromConfigFiles = await (0, config_1.getOptionsFromConfigFiles)({
Expand Down Expand Up @@ -31648,7 +31708,7 @@ exports.maybe = maybe;

Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.PACKAGE_VERSION = void 0;
exports.PACKAGE_VERSION = '9.2.2';
exports.PACKAGE_VERSION = '9.3.0';
//# sourceMappingURL=packageVersion.js.map

/***/ }),
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "backport-github-action",
"version": "9.2.2",
"version": "9.3.0",
"private": true,
"scripts": {
"build": "yarn ncc build src/index.ts",
Expand All @@ -15,7 +15,7 @@
"@actions/github": "^5.1.1",
"@octokit/action": "^4.0.8",
"@octokit/graphql": "^5.0.1",
"backport": "9.2.2",
"backport": "9.3.0",
"husky": "^8.0.3",
"lodash": "^4.17.21"
},
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1700,10 +1700,10 @@ babel-preset-jest@^29.6.3:
babel-plugin-jest-hoist "^29.6.3"
babel-preset-current-node-syntax "^1.0.0"

backport@9.2.2:
version "9.2.2"
resolved "https://registry.yarnpkg.com/backport/-/backport-9.2.2.tgz#8b374fba1b16c1044711fe7d11f3b9f662ce0571"
integrity sha512-WZjmJca9Pmm0fb7i6fwPV0GmG3B5Z99ndNtVj7jwRQFG7SQYVcY0H8pv58/C0mlOhbIGyI5R+4MXzvZeTi/iwg==
backport@9.3.0:
version "9.3.0"
resolved "https://registry.yarnpkg.com/backport/-/backport-9.3.0.tgz#5cf7227629305fc266d347922b330cff25d4ef55"
integrity sha512-nUFV+R/d0NA0OXFYWMhjHtTNTMcjDUehuMEVuWc7hob3NC/6akt9H4szWpcgTImzvKkSaQwGnC7yjMVoLb5PZg==
dependencies:
"@octokit/rest" "^19.0.7"
axios "^1.4.0"
Expand Down

0 comments on commit 8489273

Please sign in to comment.