backport 6.1.3 → 6.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/entrypoint.module.d.ts +2 -0
  2. package/dist/entrypoint.module.js +5 -1
  3. package/dist/entrypoint.module.private.test.js +4 -1
  4. package/dist/main.js +1 -1
  5. package/dist/options/cliArgs.d.ts +2 -0
  6. package/dist/options/cliArgs.js +14 -1
  7. package/dist/options/config/globalConfig.js +1 -1
  8. package/dist/options/options.d.ts +4 -0
  9. package/dist/options/options.js +3 -1
  10. package/dist/options/options.test.js +3 -1
  11. package/dist/runSequentially.test.js +7 -5
  12. package/dist/services/HandledError.d.ts +1 -1
  13. package/dist/services/git.d.ts +2 -1
  14. package/dist/services/git.js +4 -2
  15. package/dist/services/github/v3/createPullRequest.test.js +3 -3
  16. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  17. package/dist/services/github/v3/createStatusComment.js +31 -11
  18. package/dist/services/github/v3/createStatusComment.test.js +139 -86
  19. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  20. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  21. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  22. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  23. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  24. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  25. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  26. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  27. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  28. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  29. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  30. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  31. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  32. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  33. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  34. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
  35. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  36. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  37. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  38. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  39. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  40. package/dist/test/integration/integration.private.test.js +2 -2
  41. package/dist/test/nockHelpers.js +1 -3
  42. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  43. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -2
  44. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +6 -4
  45. package/dist/ui/getCommits.js +1 -1
  46. package/dist/ui/getCommitsWithoutBackports.js +17 -2
  47. package/package.json +3 -3
  48. package/yarn.lock +462 -284
@@ -16,4 +16,6 @@ export declare function getCommits(options: {
16
16
  sha?: string;
17
17
  skipRemoteConfig?: boolean;
18
18
  sourceBranch?: string;
19
+ dateUntil?: string;
20
+ dateSince?: string;
19
21
  }): Promise<import("./services/sourceCommit/parseSourceCommit").Commit[]>;
@@ -7,6 +7,7 @@ const fetchCommitBySha_1 = require("./services/github/v4/fetchCommits/fetchCommi
7
7
  const fetchCommitsByAuthor_1 = require("./services/github/v4/fetchCommits/fetchCommitsByAuthor");
8
8
  const getOptionsFromGithub_1 = require("./services/github/v4/getOptionsFromGithub/getOptionsFromGithub");
9
9
  const logger_1 = require("./services/logger");
10
+ const excludeUndefined_1 = require("./utils/excludeUndefined");
10
11
  (0, logger_1.initLogger)();
11
12
  var fetchProjectConfig_1 = require("./services/github/v4/fetchProjectConfig");
12
13
  Object.defineProperty(exports, "fetchProjectConfig", { enumerable: true, get: function () { return fetchProjectConfig_1.fetchProjectConfig; } });
@@ -19,7 +20,7 @@ function backportRun(options,
19
20
  // backportRun(options, args)
20
21
  //
21
22
  args = []) {
22
- return (0, main_1.main)(args, options);
23
+ return (0, main_1.main)(args, (0, excludeUndefined_1.excludeUndefined)(options));
23
24
  }
24
25
  exports.backportRun = backportRun;
25
26
  async function getCommits(options) {
@@ -45,7 +46,10 @@ async function getCommits(options) {
45
46
  return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
46
47
  ...optionsFromGithub,
47
48
  ...options,
49
+ // filters
48
50
  author: options.author ?? null,
51
+ dateSince: options.dateSince ?? null,
52
+ dateUntil: options.dateUntil ?? null,
49
53
  });
50
54
  }
51
55
  exports.getCommits = getCommits;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- jest.unmock('./services/logger');
4
3
  const entrypoint_module_1 = require("./entrypoint.module");
5
4
  const getDevAccessToken_1 = require("./test/private/getDevAccessToken");
6
5
  describe('entrypoint.module', () => {
@@ -21,6 +20,10 @@ describe('entrypoint.module', () => {
21
20
  number: 4,
22
21
  state: 'MERGED',
23
22
  url: 'https://github.com/backport-org/backport-e2e/pull/4',
23
+ mergeCommit: {
24
+ message: 'Add family emoji (#2) (#4)',
25
+ sha: 'f8b4f6ae7ffaf2732fa5e33e98b3ea772bdfff1d',
26
+ },
24
27
  },
25
28
  ],
26
29
  originalMessage: 'Add family emoji (#2)',
package/dist/main.js CHANGED
@@ -39,7 +39,7 @@ async function main(argv, optionsFromModule) {
39
39
  errorMessage: e.message,
40
40
  error: e,
41
41
  };
42
- if (options?.ci) {
42
+ if (options) {
43
43
  await (0, createStatusComment_1.createStatusComment)({
44
44
  options,
45
45
  backportResponse,
@@ -38,4 +38,6 @@ export declare function getOptionsFromCliArgs(argv: readonly string[], { exitOnE
38
38
  targetBranches?: string[] | undefined;
39
39
  targetPRLabels?: string[] | undefined;
40
40
  mainline?: number | undefined;
41
+ dateSince?: string | undefined;
42
+ dateUntil?: string | undefined;
41
43
  };
@@ -56,6 +56,14 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
56
56
  description: 'Append commit message with "(cherry picked from commit...)',
57
57
  type: 'boolean',
58
58
  conflicts: ['noCherrypickRef'],
59
+ })
60
+ .option('since', {
61
+ description: 'ISO-8601 date for filtering commits',
62
+ type: 'string',
63
+ })
64
+ .option('until', {
65
+ description: 'ISO-8601 date for filtering commits',
66
+ type: 'string',
59
67
  })
60
68
  .option('details', {
61
69
  description: 'Show details about each commit',
@@ -256,14 +264,19 @@ function getOptionsFromCliArgs(argv, { exitOnError = true } = {}) {
256
264
  /* eslint-disable @typescript-eslint/no-unused-vars */
257
265
  $0, _,
258
266
  /* eslint-enable @typescript-eslint/no-unused-vars */
259
- multiple, multipleBranches, multipleCommits, all, author,
267
+ multiple, multipleBranches, multipleCommits, all,
268
+ // filters
269
+ author, since, until,
260
270
  // negations
261
271
  verify, noVerify, noCherrypickRef, noFork,
262
272
  // array types (should be renamed to plural form)
263
273
  assignee, path, reviewer, sourcePRLabel, targetBranch, targetBranchChoice, targetPRLabel, ...restOptions } = yargsInstance.parseSync();
264
274
  return (0, excludeUndefined_1.excludeUndefined)({
265
275
  ...restOptions,
276
+ // filters
266
277
  author: all ? null : author,
278
+ dateSince: since,
279
+ dateUntil: until,
267
280
  // `multiple` is a cli-only flag to override `multipleBranches` and `multipleCommits`
268
281
  multipleBranches: multiple ?? multipleBranches,
269
282
  multipleCommits: multiple ?? multipleCommits,
@@ -50,7 +50,7 @@ async function createGlobalConfigIfNotExist(globalConfigPath, configTemplate) {
50
50
  exports.createGlobalConfigIfNotExist = createGlobalConfigIfNotExist;
51
51
  function getConfigTemplate() {
52
52
  return `{
53
- // Github personal access token. Must be created here: https://github.com/settings/tokens
53
+ // Create a personal access token here: https://github.com/settings/tokens
54
54
  // Must have "Repo: Full control of private repositories"
55
55
  "accessToken": ""
56
56
  }`;
@@ -9,6 +9,8 @@ export declare const defaultConfigOptions: {
9
9
  cherrypickRef: boolean;
10
10
  ci: boolean;
11
11
  commitPaths: string[];
12
+ dateSince: null;
13
+ dateUntil: null;
12
14
  details: boolean;
13
15
  fork: boolean;
14
16
  maxNumber: number;
@@ -60,6 +62,8 @@ export declare function getOptions(argv: string[], optionsFromModule?: ConfigFil
60
62
  targetBranches: string[];
61
63
  targetPRLabels: string[];
62
64
  mainline?: number | undefined;
65
+ dateSince: string | null;
66
+ dateUntil: string | null;
63
67
  historicalBranchLabelMappings: {
64
68
  branchLabelMapping: Record<string, string>;
65
69
  committedDate: string;
@@ -19,6 +19,8 @@ exports.defaultConfigOptions = {
19
19
  cherrypickRef: true,
20
20
  ci: false,
21
21
  commitPaths: [],
22
+ dateSince: null,
23
+ dateUntil: null,
22
24
  details: false,
23
25
  fork: true,
24
26
  maxNumber: 10,
@@ -85,7 +87,7 @@ function requireAccessToken(combinedOptions) {
85
87
  // accessToken must be supplied in config or via cli args
86
88
  if (!combinedOptions.accessToken) {
87
89
  const globalConfigPath = (0, env_1.getGlobalConfigPath)();
88
- throw new HandledError_1.HandledError(`Please update your config file: ${globalConfigPath}.\nIt must contain a valid "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
90
+ throw new HandledError_1.HandledError(`Please update your config file: "${globalConfigPath}".\nIt must contain a valid "accessToken".\n\nRead more: ${GLOBAL_CONFIG_DOCS_LINK}`);
89
91
  }
90
92
  return combinedOptions.accessToken;
91
93
  }
@@ -57,7 +57,7 @@ describe('getOptions', () => {
57
57
  });
58
58
  await expect(() => (0, options_1.getOptions)([])).rejects
59
59
  .toThrowErrorMatchingInlineSnapshot(`
60
- "Please update your config file: /Users/sqren/.backport/config.json.
60
+ "Please update your config file: \\"/Users/sqren/.backport/config.json\\".
61
61
  It must contain a valid \\"accessToken\\".
62
62
 
63
63
  Read more: https://github.com/sqren/backport/blob/main/docs/configuration.md#global-config-backportconfigjson"
@@ -136,6 +136,8 @@ describe('getOptions', () => {
136
136
  cherrypickRef: true,
137
137
  ci: false,
138
138
  commitPaths: [],
139
+ dateSince: null,
140
+ dateUntil: null,
139
141
  details: false,
140
142
  editor: 'code',
141
143
  fork: true,
@@ -56,25 +56,27 @@ describe('runSequentially', () => {
56
56
  jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
57
57
  const options = {
58
58
  accessToken: 'myAccessToken',
59
- authenticatedUsername: 'sqren_authenticated',
60
59
  assignees: [],
60
+ authenticatedUsername: 'sqren_authenticated',
61
+ author: 'sqren',
61
62
  autoAssign: false,
62
63
  autoFixConflicts: undefined,
63
64
  autoMerge: false,
64
65
  autoMergeMethod: 'merge',
65
66
  backportBinary: 'node scripts/backport',
66
67
  branchLabelMapping: undefined,
67
- historicalBranchLabelMappings: [],
68
68
  cherrypickRef: true,
69
69
  ci: false,
70
70
  commitPaths: [],
71
+ dateSince: null,
72
+ dateUntil: null,
71
73
  details: false,
72
74
  editor: 'code',
73
- skipRemoteConfig: undefined,
74
75
  fork: true,
75
76
  gitHostname: 'github.com',
76
77
  githubApiBaseUrlV3: 'https://api.github.com',
77
78
  githubApiBaseUrlV4: 'http://localhost/graphql',
79
+ historicalBranchLabelMappings: [],
78
80
  mainline: undefined,
79
81
  maxNumber: 10,
80
82
  multipleBranches: false,
@@ -89,6 +91,7 @@ describe('runSequentially', () => {
89
91
  resetAuthor: false,
90
92
  reviewers: [],
91
93
  sha: undefined,
94
+ skipRemoteConfig: undefined,
92
95
  sourceBranch: 'my-source-branch-from-options',
93
96
  sourcePRLabels: [],
94
97
  targetBranches: [],
@@ -100,7 +103,6 @@ describe('runSequentially', () => {
100
103
  { name: '5.4' },
101
104
  ],
102
105
  targetPRLabels: [],
103
- author: 'sqren',
104
106
  verbose: false,
105
107
  };
106
108
  rpcExecMock = jest
@@ -146,7 +148,7 @@ describe('runSequentially', () => {
146
148
  "base": "7.x",
147
149
  "body": "# Backport
148
150
 
149
- This is an automatic backport to 7.x of:
151
+ This is an automatic backport to \`7.x\` of:
150
152
  - #55
151
153
 
152
154
  ### Questions ?
@@ -1,6 +1,6 @@
1
1
  import { Commit } from './sourceCommit/parseSourceCommit';
2
2
  declare type Meta = {
3
- type: 'commitsWithoutBackports';
3
+ type: 'merge-conflict-due-to-missing-backports';
4
4
  commitsWithoutBackports: {
5
5
  formatted: string;
6
6
  commit: Commit;
@@ -1,4 +1,5 @@
1
1
  import { ValidConfigOptions } from '../options/options';
2
+ import { ExpectedTargetPullRequest } from './sourceCommit/getExpectedTargetPullRequests';
2
3
  import { Commit } from './sourceCommit/parseSourceCommit';
3
4
  export declare function repoExists(options: ValidConfigOptions): Promise<boolean>;
4
5
  export declare function deleteRepo(options: ValidConfigOptions): Promise<string[]>;
@@ -15,7 +16,7 @@ export declare function getIsCommitInBranch(options: ValidConfigOptions, commitS
15
16
  export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
16
17
  export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
17
18
  export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
18
- export declare function cherrypick(options: ValidConfigOptions, sha: Commit['sha']): Promise<{
19
+ export declare function cherrypick(options: ValidConfigOptions, sha: Commit['sha'], mergedTargetPullRequest?: ExpectedTargetPullRequest): Promise<{
19
20
  conflictingFiles: {
20
21
  absolute: string;
21
22
  relative: string;
@@ -158,7 +158,7 @@ async function fetchBranch(options, branch) {
158
158
  });
159
159
  }
160
160
  exports.fetchBranch = fetchBranch;
161
- async function cherrypick(options, sha) {
161
+ async function cherrypick(options, sha, mergedTargetPullRequest) {
162
162
  const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
163
163
  const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
164
164
  const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${sha}`;
@@ -174,7 +174,9 @@ async function cherrypick(options, sha) {
174
174
  // commit was already backported
175
175
  if (e.message.includes('The previous cherry-pick is now empty')) {
176
176
  const shortSha = (0, commitFormatters_1.getShortSha)(sha);
177
- throw new HandledError_1.HandledError(`Cherrypick failed because the selected commit (${shortSha}) is empty. Did you already backport this commit?`);
177
+ throw new HandledError_1.HandledError(`Cherrypick failed because the selected commit (${shortSha}) is empty. ${mergedTargetPullRequest?.url
178
+ ? `It looks like the commit was already backported in ${mergedTargetPullRequest.url}`
179
+ : 'Did you already backport this commit? '}`);
178
180
  }
179
181
  // git info missing
180
182
  if (e.message.includes('Please tell me who you are')) {
@@ -16,7 +16,7 @@ describe('getPullRequestBody', () => {
16
16
  })).toMatchInlineSnapshot(`
17
17
  "# Backport
18
18
 
19
- This is an automatic backport to 7.x of:
19
+ This is an automatic backport to \`7.x\` of:
20
20
  - #55
21
21
 
22
22
  ### Questions ?
@@ -37,7 +37,7 @@ describe('getPullRequestBody', () => {
37
37
  })).toMatchInlineSnapshot(`
38
38
  "# Backport
39
39
 
40
- This is an automatic backport to 7.x of:
40
+ This is an automatic backport to \`7.x\` of:
41
41
  - My commit message (abcdefgh)
42
42
 
43
43
  ### Questions ?
@@ -63,7 +63,7 @@ describe('getPullRequestBody', () => {
63
63
  })).toMatchInlineSnapshot(`
64
64
  "# Backport
65
65
 
66
- This is an automatic backport to 7.x of:
66
+ This is an automatic backport to \`7.x\` of:
67
67
  - #55
68
68
  - Another commit message (qwertyui)
69
69
 
@@ -8,4 +8,4 @@ export declare function getCommentBody({ options, pullNumber, backportResponse,
8
8
  options: ValidConfigOptions;
9
9
  pullNumber: number;
10
10
  backportResponse: BackportResponse;
11
- }): string;
11
+ }): string | undefined;
@@ -12,13 +12,6 @@ async function createStatusComment({ options, backportResponse, }) {
12
12
  baseUrl: githubApiBaseUrlV3,
13
13
  log: logger_1.logger,
14
14
  });
15
- // don't post update if there are no new pull requests created
16
- if (backportResponse.status === 'success') {
17
- const hasOnlyUpdates = backportResponse.results.every((result) => result.status === 'success' && result.didUpdate);
18
- if (hasOnlyUpdates) {
19
- return;
20
- }
21
- }
22
15
  await Promise.all(backportResponse.commits.map((commit) => {
23
16
  if (!commit.pullNumber) {
24
17
  return;
@@ -28,6 +21,10 @@ async function createStatusComment({ options, backportResponse, }) {
28
21
  pullNumber: commit.pullNumber,
29
22
  backportResponse,
30
23
  });
24
+ // only post comment if there is a body
25
+ if (!body) {
26
+ return;
27
+ }
31
28
  return octokit.issues.createComment({
32
29
  owner: repoOwner,
33
30
  repo: repoName,
@@ -43,6 +40,18 @@ async function createStatusComment({ options, backportResponse, }) {
43
40
  exports.createStatusComment = createStatusComment;
44
41
  function getCommentBody({ options, pullNumber, backportResponse, }) {
45
42
  const { repoName, repoOwner, autoMerge } = options;
43
+ // custom handling when running backport locally (as opposed to on CI)
44
+ if (!options.ci) {
45
+ // don't post comment when the overall process failed
46
+ if (backportResponse.status === 'failure') {
47
+ return;
48
+ }
49
+ // only post a comment if all backports succeeded
50
+ const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
51
+ if (!didAllBackportsSucceed) {
52
+ return;
53
+ }
54
+ }
46
55
  const backportPRCommand = `\n### How to fix\nRe-run the backport manually:\n\`\`\`\n${options.backportBinary} --pr ${pullNumber}\n\`\`\``;
47
56
  const supportSection = '\n\n### Questions ?\nPlease refer to the [Backport tool documentation](https://github.com/sqren/backport)';
48
57
  if (backportResponse.status === 'failure') {
@@ -52,6 +61,10 @@ The pull request could not be backported due to the following error:
52
61
  ${backportPRCommand}${supportSection}`;
53
62
  }
54
63
  const tableBody = backportResponse.results
64
+ .filter((result) => {
65
+ // only post status updates for successful backports when running manually (non-ci)
66
+ return options.ci || result.status === 'success';
67
+ })
55
68
  .map((result) => {
56
69
  if (result.status === 'success') {
57
70
  return [
@@ -60,7 +73,7 @@ ${backportPRCommand}${supportSection}`;
60
73
  `[<img src="https://img.shields.io/github/pulls/detail/state/${repoOwner}/${repoName}/${result.pullRequestNumber}">](${result.pullRequestUrl})`,
61
74
  ];
62
75
  }
63
- if (result.error.meta?.type === 'commitsWithoutBackports') {
76
+ if (result.error.meta?.type === 'merge-conflict-due-to-missing-backports') {
64
77
  const conflictingPullRequests = result.error.meta.commitsWithoutBackports.map((c) => {
65
78
  return ` - [${(0, commitFormatters_1.getFirstLine)(c.commit.originalMessage)}](${c.commit.pullUrl})`;
66
79
  });
@@ -80,9 +93,16 @@ ${backportPRCommand}${supportSection}`;
80
93
  : '';
81
94
  const didAllBackportsSucceed = backportResponse.results.every((r) => r.status === 'success');
82
95
  const didAnyBackportsSucceed = backportResponse.results.some((r) => r.status === 'success');
83
- const header = didAllBackportsSucceed
84
- ? '## 💚 All backports created successfully'
85
- : '## 💔 Some backports could not be created';
96
+ let header = '';
97
+ if (didAllBackportsSucceed) {
98
+ header = '## 💚 All backports created successfully';
99
+ }
100
+ else if (didAnyBackportsSucceed) {
101
+ header = '## 💔 Some backports could not be created';
102
+ }
103
+ else {
104
+ header = '## 💔 All backports failed';
105
+ }
86
106
  const autoMergeMessage = autoMerge && didAnyBackportsSucceed
87
107
  ? '\nNote: Successful backport PRs will be merged automatically after passing CI.'
88
108
  : '';