backport 8.2.0 → 8.3.1

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 (43) hide show
  1. package/dist/backportRun.js +6 -2
  2. package/dist/entrypoint.module.d.ts +2 -2
  3. package/dist/entrypoint.module.js +2 -0
  4. package/dist/entrypoint.module.private.test.js +32 -10
  5. package/dist/lib/getCommits.js +1 -1
  6. package/dist/lib/git.js +2 -1
  7. package/dist/lib/github/v3/createStatusComment.js +3 -2
  8. package/dist/lib/github/v3/createStatusComment.test.js +61 -0
  9. package/dist/lib/github/v4/apiRequestV4.js +1 -1
  10. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +2 -1
  11. package/dist/lib/github/v4/enablePullRequestAutoMerge.mutation.test.d.ts +1 -0
  12. package/dist/lib/github/v4/enablePullRequestAutoMerge.mutation.test.js +138 -0
  13. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +5 -3
  14. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +0 -1
  15. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +0 -1
  16. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +5 -6
  17. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +7 -3
  18. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +2 -0
  19. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +23 -7
  20. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -0
  21. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +1 -0
  22. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +2 -0
  23. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +1 -0
  24. package/dist/lib/github/v4/getOptionsFromGithub/query.js +1 -0
  25. package/dist/lib/github/v4/validateTargetBranches.d.ts +2 -7
  26. package/dist/lib/github/v4/validateTargetBranches.js +1 -1
  27. package/dist/lib/github/v4/validateTargetBranches.private.test.js +8 -8
  28. package/dist/lib/remoteConfig.d.ts +1 -1
  29. package/dist/lib/remoteConfig.js +4 -0
  30. package/dist/options/cliArgs.d.ts +2 -2
  31. package/dist/options/cliArgs.js +16 -6
  32. package/dist/options/options.d.ts +3 -2
  33. package/dist/options/options.js +0 -5
  34. package/dist/options/options.test.js +2 -0
  35. package/dist/test/e2e/cli/date-filters.d.ts +1 -0
  36. package/dist/test/e2e/cli/date-filters.js +43 -0
  37. package/dist/test/e2e/cli/date-filters.private.test.d.ts +1 -0
  38. package/dist/test/e2e/cli/date-filters.private.test.js +47 -0
  39. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +2 -18
  40. package/dist/utils/packageVersion.d.ts +1 -1
  41. package/dist/utils/packageVersion.js +1 -1
  42. package/package.json +13 -13
  43. package/yarn.lock +165 -171
@@ -10,9 +10,9 @@ describe('validateTargetBranches', () => {
10
10
  repoOwner: 'backport-org',
11
11
  repoName: 'repo-with-target-branches',
12
12
  accessToken,
13
- targetBranches: [],
14
13
  };
15
- expect(await (0, validateTargetBranches_1.validateTargetBranches)(options)).toEqual(undefined);
14
+ const targetBranches = [];
15
+ expect(await (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).toEqual(undefined);
16
16
  });
17
17
  });
18
18
  describe('one invalid and one valid branch', () => {
@@ -21,9 +21,9 @@ describe('validateTargetBranches', () => {
21
21
  repoOwner: 'backport-org',
22
22
  repoName: 'repo-with-target-branches',
23
23
  accessToken,
24
- targetBranches: ['production', 'foo'],
25
24
  };
26
- await expect(() => (0, validateTargetBranches_1.validateTargetBranches)(options)).rejects.toThrowError('The branch "foo" does not exist');
25
+ const targetBranches = ['production', 'foo'];
26
+ await expect(() => (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).rejects.toThrowError('The branch "foo" does not exist');
27
27
  });
28
28
  });
29
29
  describe('two valid branches', () => {
@@ -32,9 +32,9 @@ describe('validateTargetBranches', () => {
32
32
  repoOwner: 'backport-org',
33
33
  repoName: 'repo-with-target-branches',
34
34
  accessToken,
35
- targetBranches: ['production', 'staging'],
36
35
  };
37
- expect(await (0, validateTargetBranches_1.validateTargetBranches)(options)).toEqual(undefined);
36
+ const targetBranches = ['production', 'staging'];
37
+ expect(await (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).toEqual(undefined);
38
38
  });
39
39
  });
40
40
  describe('two invalid branches', () => {
@@ -43,9 +43,9 @@ describe('validateTargetBranches', () => {
43
43
  repoOwner: 'backport-org',
44
44
  repoName: 'repo-with-target-branches',
45
45
  accessToken,
46
- targetBranches: ['foo', 'bar'],
47
46
  };
48
- await expect(() => (0, validateTargetBranches_1.validateTargetBranches)(options)).rejects.toThrow(/The branch "(foo|bar)" does not exist/);
47
+ const targetBranches = ['foo', 'bar'];
48
+ await expect(() => (0, validateTargetBranches_1.validateTargetBranches)(options, targetBranches)).rejects.toThrow(/The branch "(foo|bar)" does not exist/);
49
49
  });
50
50
  });
51
51
  });
@@ -17,4 +17,4 @@ export interface RemoteConfigHistory {
17
17
  };
18
18
  }
19
19
  export declare function parseRemoteConfig(remoteConfig: RemoteConfig): ConfigFileOptions | undefined;
20
- export declare function swallowMissingConfigFileException<T>(error: GithubV4Exception<T>): T;
20
+ export declare function swallowMissingConfigFileException<T>(error: GithubV4Exception<T> | unknown): T;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.swallowMissingConfigFileException = exports.parseRemoteConfig = exports.RemoteConfigHistoryFragment = void 0;
7
7
  const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const readConfigFile_1 = require("../options/config/readConfigFile");
9
+ const apiRequestV4_1 = require("./github/v4/apiRequestV4");
9
10
  const logger_1 = require("./logger");
10
11
  exports.RemoteConfigHistoryFragment = (0, graphql_tag_1.default) `
11
12
  fragment RemoteConfigHistoryFragment on Commit {
@@ -38,6 +39,9 @@ function parseRemoteConfig(remoteConfig) {
38
39
  }
39
40
  exports.parseRemoteConfig = parseRemoteConfig;
40
41
  function swallowMissingConfigFileException(error) {
42
+ if (!(error instanceof apiRequestV4_1.GithubV4Exception)) {
43
+ throw error;
44
+ }
41
45
  const { data, errors } = error.githubResponse.data;
42
46
  const missingConfigError = errors?.some((error) => {
43
47
  return error.path?.includes('remoteConfig') && error.type === 'NOT_FOUND';
@@ -15,6 +15,8 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[]): {
15
15
  cherrypickRef?: boolean | undefined;
16
16
  projectConfigFile?: string | undefined;
17
17
  globalConfigFile?: string | undefined;
18
+ dateSince?: string | undefined;
19
+ dateUntil?: string | undefined;
18
20
  details?: boolean | undefined;
19
21
  dryRun?: boolean | undefined;
20
22
  editor?: string | undefined;
@@ -41,8 +43,6 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[]): {
41
43
  repoOwner?: string | undefined;
42
44
  repoName?: string | undefined;
43
45
  sourceBranch?: string | undefined;
44
- dateSince?: string | undefined;
45
- dateUntil?: string | undefined;
46
46
  commitPaths?: string[] | undefined;
47
47
  reviewers?: string[] | undefined;
48
48
  sourcePRLabels?: string[] | undefined;
@@ -76,13 +76,25 @@ function getOptionsFromCliArgs(processArgs) {
76
76
  description: 'Path to global config',
77
77
  type: 'string',
78
78
  })
79
- .option('since', {
79
+ .option('dateSince', {
80
+ alias: 'since',
80
81
  description: 'ISO-8601 date for filtering commits',
81
82
  type: 'string',
83
+ coerce: (since) => {
84
+ if (since) {
85
+ return new Date(since).toISOString();
86
+ }
87
+ },
82
88
  })
83
- .option('until', {
89
+ .option('dateUntil', {
90
+ alias: 'until',
84
91
  description: 'ISO-8601 date for filtering commits',
85
92
  type: 'string',
93
+ coerce: (until) => {
94
+ if (until) {
95
+ return new Date(until).toISOString();
96
+ }
97
+ },
86
98
  })
87
99
  .option('dir', {
88
100
  description: 'Path to temporary backport repo',
@@ -230,7 +242,7 @@ function getOptionsFromCliArgs(processArgs) {
230
242
  type: 'string',
231
243
  })
232
244
  .option('prFilter', {
233
- conflicts: ['pullNumber', 'sha'],
245
+ conflicts: ['pullNumber', 'sha', 'path'],
234
246
  description: `Filter source pull requests by a query`,
235
247
  type: 'string',
236
248
  })
@@ -329,7 +341,7 @@ function getOptionsFromCliArgs(processArgs) {
329
341
  // shorthands
330
342
  repo,
331
343
  // filters
332
- author, since, until,
344
+ author,
333
345
  // negations
334
346
  noCherrypickRef, noFork, noStatusComment, noVerify, verify, nonInteractive,
335
347
  // array types (should be renamed to plural form)
@@ -345,8 +357,6 @@ function getOptionsFromCliArgs(processArgs) {
345
357
  repoName,
346
358
  // filters
347
359
  author: all ? null : author,
348
- dateSince: since ? new Date(since).toISOString() : undefined,
349
- dateUntil: until ? new Date(until).toISOString() : undefined,
350
360
  // `multiple` is a cli-only flag to override `multipleBranches` and `multipleCommits`
351
361
  multipleBranches: multiple ?? multipleBranches,
352
362
  multipleCommits: multiple ?? multipleCommits,
@@ -50,6 +50,8 @@ export declare function getOptions({ optionsFromCliArgs, optionsFromModule, }: {
50
50
  cherrypickRef: boolean;
51
51
  projectConfigFile?: string | undefined;
52
52
  globalConfigFile?: string | undefined;
53
+ dateSince: string | null;
54
+ dateUntil: string | null;
53
55
  details: boolean;
54
56
  dryRun?: boolean | undefined;
55
57
  editor?: string | undefined;
@@ -74,8 +76,6 @@ export declare function getOptions({ optionsFromCliArgs, optionsFromModule, }: {
74
76
  sha?: string | string[] | undefined;
75
77
  resetAuthor: boolean;
76
78
  sourceBranch: string;
77
- dateSince: string | null;
78
- dateUntil: string | null;
79
79
  commitPaths: string[];
80
80
  reviewers: string[];
81
81
  sourcePRLabels: string[];
@@ -101,4 +101,5 @@ export declare function getOptions({ optionsFromCliArgs, optionsFromModule, }: {
101
101
  branches?: TargetBranchChoiceOrString[] | undefined;
102
102
  labels?: string[] | undefined;
103
103
  authenticatedUsername: string;
104
+ isRepoPrivate: boolean;
104
105
  }>;
@@ -6,7 +6,6 @@ const BackportError_1 = require("../lib/BackportError");
6
6
  const env_1 = require("../lib/env");
7
7
  const getOptionsFromGithub_1 = require("../lib/github/v4/getOptionsFromGithub/getOptionsFromGithub");
8
8
  const getRepoOwnerAndNameFromGitRemotes_1 = require("../lib/github/v4/getRepoOwnerAndNameFromGitRemotes");
9
- const validateTargetBranches_1 = require("../lib/github/v4/validateTargetBranches");
10
9
  const logger_1 = require("../lib/logger");
11
10
  const config_1 = require("./config/config");
12
11
  const PROJECT_CONFIG_DOCS_LINK = 'https://github.com/sqren/backport/blob/main/docs/configuration.md#project-config-backportrcjson';
@@ -79,9 +78,6 @@ async function getOptions({ optionsFromCliArgs, optionsFromModule, }) {
79
78
  repoOwner,
80
79
  };
81
80
  throwForRequiredOptions(options);
82
- if (options.targetBranches.length > 0) {
83
- await (0, validateTargetBranches_1.validateTargetBranches)(options);
84
- }
85
81
  return options;
86
82
  }
87
83
  exports.getOptions = getOptions;
@@ -130,7 +126,6 @@ function throwForRequiredOptions(options) {
130
126
  'githubApiBaseUrlV4',
131
127
  'logFilePath',
132
128
  'prDescription',
133
- 'prFilter',
134
129
  'projectConfigFile',
135
130
  'prTitle',
136
131
  'repoForkOwner',
@@ -199,6 +199,7 @@ describe('getOptions', () => {
199
199
  gitHostname: 'github.com',
200
200
  githubApiBaseUrlV4: 'http://localhost/graphql',
201
201
  interactive: true,
202
+ isRepoPrivate: false,
202
203
  maxNumber: 10,
203
204
  multipleBranches: true,
204
205
  multipleCommits: false,
@@ -397,6 +398,7 @@ function mockGithubConfigOptions({ viewerLogin = 'DO_NOT_USE-sqren', defaultBran
397
398
  login: viewerLogin,
398
399
  },
399
400
  repository: {
401
+ isPrivate: false,
400
402
  illegalBackportBranch: hasBackportBranch ? { id: 'foo' } : null,
401
403
  defaultBranchRef: {
402
404
  name: defaultBranchRef,
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
4
+ const runBackportViaCli_1 = require("./runBackportViaCli");
5
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
+ describe('date filters (dateSince, dateUntil)', () => {
7
+ it(`filters commits by "since" and "until"`, async () => {
8
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
9
+ '--branch=7.x',
10
+ '--repo=backport-org/backport-e2e',
11
+ `--accessToken=${accessToken}`,
12
+ '--since=2020-08-15T10:00:00.000Z',
13
+ '--until=2020-08-15T10:30:00.000Z',
14
+ ], { waitForString: 'Select commit' });
15
+ expect(output).toMatchInlineSnapshot(`
16
+ "? Select commit (Use arrow keys)
17
+ ❯ 1. Bump to 8.0.0
18
+ 2. Add package.json
19
+ 3. Update .backportrc.json
20
+ 4. Create .backportrc.json"
21
+ `);
22
+ });
23
+ it('works with --pr-filter', async () => {
24
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
25
+ '--branch=7.x',
26
+ '--repo=elastic/kibana',
27
+ `--accessToken=${accessToken}`,
28
+ `--author=sqren`,
29
+ '--since=2021-09-20',
30
+ '--until=2021-10-01',
31
+ ]);
32
+ const { output: output2 } = await (0, runBackportViaCli_1.runBackportViaCli)([
33
+ '--branch=7.x',
34
+ '--repo=elastic/kibana',
35
+ `--accessToken=${accessToken}`,
36
+ `--pr-filter="author:sqren"`,
37
+ '--since=2021-09-20',
38
+ '--until=2021-10-01',
39
+ ]);
40
+ expect(output).toMatchInlineSnapshot();
41
+ expect(output2).toMatchInlineSnapshot();
42
+ });
43
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../private/getDevAccessToken");
4
+ const runBackportViaCli_1 = require("./runBackportViaCli");
5
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
6
+ describe('date filters (dateSince, dateUntil)', () => {
7
+ it(`filters commits by "since" and "until"`, async () => {
8
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
9
+ '--branch=7.x',
10
+ '--repo=backport-org/backport-e2e',
11
+ `--accessToken=${accessToken}`,
12
+ '--since=2020-08-15T10:00:00.000Z',
13
+ '--until=2020-08-15T10:30:00.000Z',
14
+ ], { waitForString: 'Select commit' });
15
+ expect(output).toMatchInlineSnapshot(`
16
+ "? Select commit (Use arrow keys)
17
+ ❯ 1. Bump to 8.0.0
18
+ 2. Add package.json
19
+ 3. Update .backportrc.json
20
+ 4. Create .backportrc.json"
21
+ `);
22
+ });
23
+ it('combined with --pr-filter', async () => {
24
+ const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
25
+ '--branch=7.x',
26
+ '--repo=elastic/kibana',
27
+ `--accessToken=${accessToken}`,
28
+ `--author=sqren`,
29
+ '--since=2021-09-20',
30
+ '--until=2021-10-01',
31
+ ], { waitForString: 'Select commit' });
32
+ const { output: outputFromPrFilter } = await (0, runBackportViaCli_1.runBackportViaCli)([
33
+ '--branch=7.x',
34
+ '--repo=elastic/kibana',
35
+ `--accessToken=${accessToken}`,
36
+ `--pr-filter="author:sqren"`,
37
+ '--since=2021-09-20',
38
+ '--until=2021-10-01',
39
+ '--source-branch=master',
40
+ ], { waitForString: 'Select commit' });
41
+ expect(output).toMatchInlineSnapshot(`
42
+ "? Select commit (Use arrow keys)
43
+ ❯ 1. [APM] Add link to officials docs for APM UI settings (#113396) 7.x"
44
+ `);
45
+ expect(output).toEqual(outputFromPrFilter);
46
+ });
47
+ });
@@ -65,8 +65,8 @@ describe('entrypoint cli', () => {
65
65
  [boolean]
66
66
  --projectConfigFile, --config Path to project config [string]
67
67
  --globalConfigFile Path to global config [string]
68
- --since ISO-8601 date for filtering commits [string]
69
- --until ISO-8601 date for filtering commits [string]
68
+ --dateSince, --since ISO-8601 date for filtering commits [string]
69
+ --dateUntil, --until ISO-8601 date for filtering commits [string]
70
70
  --dir Path to temporary backport repo [string]
71
71
  --details Show details about each commit [boolean]
72
72
  --dryRun Run backport locally without pushing to Github [boolean]
@@ -159,22 +159,6 @@ describe('entrypoint cli', () => {
159
159
  6. Merge pull request #1 from backport-org/add-heart-emoji"
160
160
  `);
161
161
  });
162
- it(`filters commits by "since" and "until"`, async () => {
163
- const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
164
- '--branch=7.x',
165
- '--repo=backport-org/backport-e2e',
166
- `--accessToken=${accessToken}`,
167
- '--since=2020-08-15T10:00:00.000Z',
168
- '--until=2020-08-15T10:30:00.000Z',
169
- ], { waitForString: 'Select commit' });
170
- expect(output).toMatchInlineSnapshot(`
171
- "? Select commit (Use arrow keys)
172
- ❯ 1. Bump to 8.0.0
173
- 2. Add package.json
174
- 3. Update .backportrc.json
175
- 4. Create .backportrc.json"
176
- `);
177
- });
178
162
  it(`lists commits from 7.x`, async () => {
179
163
  const { output } = await (0, runBackportViaCli_1.runBackportViaCli)([
180
164
  '--branch=7.x',
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "8.2.0";
1
+ export declare const PACKAGE_VERSION = "8.3.1";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PACKAGE_VERSION = void 0;
4
- exports.PACKAGE_VERSION = '8.2.0';
4
+ exports.PACKAGE_VERSION = '8.3.1';
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "8.2.0",
17
+ "version": "8.3.1",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {
@@ -34,7 +34,7 @@
34
34
  "test-mutation": "jest --config ./jest.config.mutation.js",
35
35
  "test-private": "jest --config ./jest.config.private.js",
36
36
  "test": "jest",
37
- "docker-run": "./docker/backport.sh"
37
+ "docker-run": "./docker/build-and-run-dockerfile.sh"
38
38
  },
39
39
  "lint-staged": {
40
40
  "*.ts": [
@@ -72,7 +72,7 @@
72
72
  "find-up": "^5.0.0",
73
73
  "graphql": "^16.3.0",
74
74
  "graphql-tag": "^2.12.6",
75
- "inquirer": "^8.2.1",
75
+ "inquirer": "^8.2.2",
76
76
  "lodash": "^4.17.21",
77
77
  "make-dir": "^3.1.0",
78
78
  "ora": "^5.4.1",
@@ -87,30 +87,30 @@
87
87
  "devDependencies": {
88
88
  "@types/core-js": "^2.5.5",
89
89
  "@types/dedent": "^0.7.0",
90
- "@types/inquirer": "^8.2.0",
90
+ "@types/inquirer": "^8.2.1",
91
91
  "@types/jest": "^27.4.1",
92
- "@types/lodash": "^4.14.180",
92
+ "@types/lodash": "^4.14.181",
93
93
  "@types/node": "^17.0.23",
94
94
  "@types/safe-json-stringify": "^1.1.2",
95
95
  "@types/yargs": "^17.0.10",
96
96
  "@types/yargs-parser": "^21.0.0",
97
- "@typescript-eslint/eslint-plugin": "^5.16.0",
98
- "@typescript-eslint/parser": "^5.16.0",
99
- "eslint": "^8.11.0",
97
+ "@typescript-eslint/eslint-plugin": "^5.17.0",
98
+ "@typescript-eslint/parser": "^5.17.0",
99
+ "eslint": "^8.12.0",
100
100
  "eslint-config-prettier": "^8.5.0",
101
101
  "eslint-plugin-import": "^2.25.4",
102
- "eslint-plugin-jest": "^26.1.2",
102
+ "eslint-plugin-jest": "^26.1.3",
103
103
  "eslint-plugin-prettier": "^4.0.0",
104
- "graphql-config": "^4.1.0",
104
+ "graphql-config": "^4.2.0",
105
105
  "husky": "^7.0.4",
106
106
  "jest": "^27.5.1",
107
107
  "jest-snapshot-serializer-ansi": "^1.0.0",
108
108
  "lint-staged": "^12.3.7",
109
109
  "nock": "^13.2.4",
110
- "prettier": "^2.6.0",
110
+ "prettier": "^2.6.2",
111
111
  "strip-ansi": "^6.0.1",
112
- "ts-jest": "^27.1.3",
112
+ "ts-jest": "^27.1.4",
113
113
  "ts-node": "^10.7.0",
114
- "typescript": "^4.6.2"
114
+ "typescript": "^4.6.3"
115
115
  }
116
116
  }