backport 7.0.1 → 7.1.0

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 (64) hide show
  1. package/dist/backportRun.d.ts +1 -0
  2. package/dist/backportRun.js +3 -2
  3. package/dist/entrypoint.cli.js +12 -1
  4. package/dist/options/cliArgs.d.ts +1 -1
  5. package/dist/options/config/readConfigFile.d.ts +1 -1
  6. package/dist/options/options.d.ts +1 -5
  7. package/dist/options/options.test.js +26 -28
  8. package/dist/runSequentially.test.js +0 -1
  9. package/dist/services/HandledError.js +3 -1
  10. package/dist/services/git.js +5 -8
  11. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  12. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
  13. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  14. package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
  15. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
  16. package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
  17. package/dist/services/github/v3/createPullRequest.js +2 -5
  18. package/dist/services/github/v4/FetchPullRequestId.js +5 -1
  19. package/dist/services/github/v4/apiRequestV4.d.ts +3 -1
  20. package/dist/services/github/v4/apiRequestV4.js +7 -7
  21. package/dist/services/github/v4/apiRequestV4.test.js +38 -11
  22. package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
  23. package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
  24. package/dist/services/github/v4/fetchAuthorId.js +5 -1
  25. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -3
  26. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
  27. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +6 -2
  28. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +3 -12
  29. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
  30. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +6 -2
  31. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -11
  32. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
  33. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +6 -2
  34. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +7 -12
  35. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -1
  36. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +6 -2
  37. package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
  38. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
  39. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
  40. package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
  41. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -4
  42. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +14 -55
  43. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -19
  44. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
  45. package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
  46. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
  47. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +5 -0
  48. package/dist/services/logger.d.ts +5 -5
  49. package/dist/services/logger.js +24 -23
  50. package/dist/services/remoteConfig.d.ts +18 -0
  51. package/dist/services/remoteConfig.js +39 -0
  52. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
  53. package/dist/services/sourceCommit/getMockSourceCommit.js +20 -6
  54. package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
  55. package/dist/services/sourceCommit/parseSourceCommit.js +73 -71
  56. package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
  57. package/dist/test/nockHelpers.js +6 -2
  58. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
  59. package/dist/ui/getCommits.js +2 -2
  60. package/dist/ui/ora.d.ts +9 -0
  61. package/dist/ui/ora.js +21 -0
  62. package/dist/utils/packageVersion.d.ts +1 -1
  63. package/dist/utils/packageVersion.js +1 -1
  64. package/package.json +1 -1
@@ -13,7 +13,6 @@ describe('allFetchers', () => {
13
13
  const commitsByAuthor = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
14
14
  accessToken: devAccessToken,
15
15
  author: 'sqren',
16
- historicalBranchLabelMappings: [],
17
16
  maxNumber: 1,
18
17
  repoName: 'kibana',
19
18
  repoOwner: 'elastic',
@@ -34,7 +33,6 @@ describe('allFetchers', () => {
34
33
  accessToken: devAccessToken,
35
34
  pullNumber: commitByAuthor.sourcePullRequest.number,
36
35
  sourceBranch: 'master',
37
- historicalBranchLabelMappings: [],
38
36
  });
39
37
  expect(commitByAuthor).toEqual(commitByPullNumber);
40
38
  });
@@ -45,7 +43,6 @@ describe('allFetchers', () => {
45
43
  accessToken: devAccessToken,
46
44
  sha: commitByAuthor.sourceCommit.sha,
47
45
  sourceBranch: 'main',
48
- historicalBranchLabelMappings: [],
49
46
  });
50
47
  expect(commitByAuthor).toEqual(commitBySha);
51
48
  });
@@ -4,7 +4,6 @@ export declare function fetchCommitByPullNumber(options: {
4
4
  accessToken: string;
5
5
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
6
6
  githubApiBaseUrlV4?: string;
7
- historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
8
7
  pullNumber: number;
9
8
  repoName: string;
10
9
  repoOwner: string;
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchCommitByPullNumber = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const HandledError_1 = require("../../../HandledError");
5
9
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
6
10
  const apiRequestV4_1 = require("../apiRequestV4");
7
11
  async function fetchCommitByPullNumber(options) {
8
12
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', pullNumber, repoName, repoOwner, } = options;
9
- const query = /* GraphQL */ `
13
+ const query = (0, graphql_tag_1.default) `
10
14
  query CommitByPullNumber(
11
15
  $repoOwner: String!
12
16
  $repoName: String!
@@ -21,7 +25,7 @@ async function fetchCommitByPullNumber(options) {
21
25
  }
22
26
  }
23
27
 
24
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
28
+ ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
25
29
  `;
26
30
  const res = await (0, apiRequestV4_1.apiRequestV4)({
27
31
  githubApiBaseUrlV4,
@@ -18,11 +18,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
21
  Object.defineProperty(exports, "__esModule", { value: true });
25
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
22
+ const graphql_1 = require("graphql");
26
23
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
27
24
  const apiRequestV4Module = __importStar(require("../apiRequestV4"));
28
25
  const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
@@ -42,16 +39,13 @@ describe('fetchCommitByPullNumber', () => {
42
39
  accessToken: devAccessToken,
43
40
  pullNumber: 121633,
44
41
  sourceBranch: 'master',
45
- historicalBranchLabelMappings: [],
46
42
  });
47
43
  });
48
44
  it('makes the right queries', () => {
49
45
  const queries = spy.mock.calls.reduce((acc, call) => {
50
46
  const query = call[0].query;
51
- const ast = (0, graphql_tag_1.default)(query);
52
- //@ts-expect-error
53
- const name = ast.definitions[0].name.value;
54
- return { ...acc, [name]: query };
47
+ const name = apiRequestV4Module.getQueryName(query);
48
+ return { ...acc, [name]: (0, graphql_1.print)(query) };
55
49
  }, {});
56
50
  const queryNames = Object.keys(queries);
57
51
  expect(queryNames).toEqual(['CommitByPullNumber']);
@@ -71,7 +65,6 @@ describe('fetchCommitByPullNumber', () => {
71
65
  repoName: 'backport-e2e',
72
66
  repoOwner: 'backport-org',
73
67
  sourceBranch: 'main',
74
- historicalBranchLabelMappings: [],
75
68
  };
76
69
  const expectedCommit = {
77
70
  sourceCommit: {
@@ -122,7 +115,6 @@ describe('fetchCommitByPullNumber', () => {
122
115
  repoName: 'backport-e2e',
123
116
  repoOwner: 'backport-org',
124
117
  sourceBranch: 'main',
125
- historicalBranchLabelMappings: [],
126
118
  };
127
119
  await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
128
120
  });
@@ -135,7 +127,6 @@ describe('fetchCommitByPullNumber', () => {
135
127
  repoName: 'backport-e2e',
136
128
  repoOwner: 'backport-org',
137
129
  sourceBranch: 'main',
138
- historicalBranchLabelMappings: [],
139
130
  };
140
131
  await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Github API v4)`);
141
132
  });
@@ -4,7 +4,6 @@ export declare function fetchCommitBySha(options: {
4
4
  accessToken: string;
5
5
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
6
6
  githubApiBaseUrlV4?: string;
7
- historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
8
7
  repoName: string;
9
8
  repoOwner: string;
10
9
  sha: string;
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchCommitBySha = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const HandledError_1 = require("../../../HandledError");
5
9
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
6
10
  const apiRequestV4_1 = require("../apiRequestV4");
7
11
  async function fetchCommitBySha(options) {
8
12
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
9
- const query = /* GraphQL */ `
13
+ const query = (0, graphql_tag_1.default) `
10
14
  query CommitsBySha($repoOwner: String!, $repoName: String!, $sha: String!) {
11
15
  repository(owner: $repoOwner, name: $repoName) {
12
16
  object(expression: $sha) {
@@ -15,7 +19,7 @@ async function fetchCommitBySha(options) {
15
19
  }
16
20
  }
17
21
 
18
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
22
+ ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
19
23
  `;
20
24
  const res = await (0, apiRequestV4_1.apiRequestV4)({
21
25
  githubApiBaseUrlV4,
@@ -18,11 +18,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
21
  Object.defineProperty(exports, "__esModule", { value: true });
25
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
22
+ const graphql_1 = require("graphql");
26
23
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
27
24
  const apiRequestV4Module = __importStar(require("../apiRequestV4"));
28
25
  const fetchCommitBySha_1 = require("./fetchCommitBySha");
@@ -42,16 +39,14 @@ describe('fetchCommitBySha', () => {
42
39
  accessToken: devAccessToken,
43
40
  sha: 'd421ddcf6157150596581c7885afa3690cec6339',
44
41
  sourceBranch: 'main',
45
- historicalBranchLabelMappings: [],
46
42
  });
47
43
  });
48
44
  it('makes the right queries', () => {
49
45
  const queries = spy.mock.calls.reduce((acc, call) => {
50
46
  const query = call[0].query;
51
- const ast = (0, graphql_tag_1.default)(query);
52
47
  //@ts-expect-error
53
- const name = ast.definitions[0].name.value;
54
- return { ...acc, [name]: query };
48
+ const name = query.definitions[0].name.value;
49
+ return { ...acc, [name]: (0, graphql_1.print)(query) };
55
50
  }, {});
56
51
  const queryNames = Object.keys(queries);
57
52
  expect(queryNames).toEqual(['CommitsBySha']);
@@ -98,7 +93,6 @@ describe('fetchCommitBySha', () => {
98
93
  accessToken: devAccessToken,
99
94
  sha: 'cb6fbc0',
100
95
  sourceBranch: 'master',
101
- historicalBranchLabelMappings: [],
102
96
  })).toEqual(expectedCommit);
103
97
  });
104
98
  it('throws if sha does not exist', async () => {
@@ -108,7 +102,6 @@ describe('fetchCommitBySha', () => {
108
102
  accessToken: devAccessToken,
109
103
  sha: 'fc22f59',
110
104
  sourceBranch: 'main',
111
- historicalBranchLabelMappings: [],
112
105
  })).rejects.toThrowError('No commit found on branch "main" with sha "fc22f59"');
113
106
  });
114
107
  it('throws if sha is invalid', async () => {
@@ -118,7 +111,6 @@ describe('fetchCommitBySha', () => {
118
111
  accessToken: devAccessToken,
119
112
  sha: 'myCommitSha',
120
113
  sourceBranch: 'main',
121
- historicalBranchLabelMappings: [],
122
114
  })).rejects.toThrowError('No commit found on branch "main" with sha "myCommitSha"');
123
115
  });
124
116
  });
@@ -6,7 +6,6 @@ export declare function fetchCommitsByAuthor(options: {
6
6
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
7
7
  commitPaths?: string[];
8
8
  githubApiBaseUrlV4?: string;
9
- historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
10
9
  maxNumber?: number;
11
10
  repoName: string;
12
11
  repoOwner: string;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchCommitsByAuthor = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const lodash_1 = require("lodash");
5
9
  const filterEmpty_1 = require("../../../../utils/filterEmpty");
6
10
  const HandledError_1 = require("../../../HandledError");
@@ -9,7 +13,7 @@ const apiRequestV4_1 = require("../apiRequestV4");
9
13
  const fetchAuthorId_1 = require("../fetchAuthorId");
10
14
  function fetchByCommitPath({ options, authorId, commitPath, }) {
11
15
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, dateSince, dateUntil, } = options;
12
- const query = /* GraphQL */ `
16
+ const query = (0, graphql_tag_1.default) `
13
17
  query CommitsByAuthor(
14
18
  $repoOwner: String!
15
19
  $repoName: String!
@@ -43,7 +47,7 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
43
47
  }
44
48
  }
45
49
 
46
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
50
+ ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
47
51
  `;
48
52
  const variables = {
49
53
  repoOwner,
@@ -18,11 +18,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
21
  Object.defineProperty(exports, "__esModule", { value: true });
25
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
22
+ const graphql_1 = require("graphql");
26
23
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
27
24
  const apiRequestV4Module = __importStar(require("../apiRequestV4"));
28
25
  const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
@@ -39,7 +36,6 @@ describe('fetchCommitsByAuthor', () => {
39
36
  commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
40
37
  accessToken: devAccessToken,
41
38
  author: 'sqren',
42
- historicalBranchLabelMappings: [],
43
39
  maxNumber: 10,
44
40
  repoName: 'kibana',
45
41
  repoOwner: 'elastic',
@@ -52,10 +48,9 @@ describe('fetchCommitsByAuthor', () => {
52
48
  it('makes the right queries', () => {
53
49
  const queries = spy.mock.calls.reduce((acc, call) => {
54
50
  const query = call[0].query;
55
- const ast = (0, graphql_tag_1.default)(query);
56
51
  //@ts-expect-error
57
- const name = ast.definitions[0].name.value;
58
- return { ...acc, [name]: query };
52
+ const name = query.definitions[0].name.value;
53
+ return { ...acc, [name]: (0, graphql_1.print)(query) };
59
54
  }, {});
60
55
  const queryNames = Object.keys(queries);
61
56
  expect(queryNames).toEqual(['AuthorId', 'CommitsByAuthor']);
@@ -71,7 +66,6 @@ describe('fetchCommitsByAuthor', () => {
71
66
  const getOptions = () => ({
72
67
  accessToken: devAccessToken,
73
68
  author: 'sqren',
74
- historicalBranchLabelMappings: [],
75
69
  maxNumber: 10,
76
70
  repoName: 'repo-with-different-commit-paths',
77
71
  repoOwner: 'backport-org',
@@ -146,7 +140,6 @@ describe('fetchCommitsByAuthor', () => {
146
140
  res = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
147
141
  accessToken: devAccessToken,
148
142
  commitPaths: [],
149
- historicalBranchLabelMappings: [],
150
143
  maxNumber: 10,
151
144
  repoName: 'backport-e2e',
152
145
  repoOwner: 'backport-org',
@@ -192,9 +185,11 @@ describe('fetchCommitsByAuthor', () => {
192
185
  },
193
186
  ]);
194
187
  });
195
- it('returns empty if there are no related PRs', async () => {
188
+ it('returns missing pull requests', async () => {
196
189
  const commitWithoutPRs = res.find((commit) => commit.sourcePullRequest?.number === 8);
197
- expect(commitWithoutPRs?.expectedTargetPullRequests).toEqual([]);
190
+ expect(commitWithoutPRs?.expectedTargetPullRequests).toEqual([
191
+ { branch: '7.x', state: 'MISSING' },
192
+ ]);
198
193
  });
199
194
  });
200
195
  });
@@ -11,7 +11,6 @@ const defaultOptions = {
11
11
  accessToken: 'myAccessToken',
12
12
  author: 'sqren',
13
13
  githubApiBaseUrlV4: 'http://localhost/graphql',
14
- historicalBranchLabelMappings: [],
15
14
  maxNumber: 10,
16
15
  repoName: 'kibana',
17
16
  repoOwner: 'elastic',
@@ -1,13 +1,17 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchPullRequestBySearchQuery = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const lodash_1 = require("lodash");
5
9
  const HandledError_1 = require("../../../HandledError");
6
10
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
7
11
  const apiRequestV4_1 = require("../apiRequestV4");
8
12
  async function fetchPullRequestBySearchQuery(options) {
9
13
  const { accessToken, githubApiBaseUrlV4, maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch, author, } = options;
10
- const query = /* GraphQL */ `
14
+ const query = (0, graphql_tag_1.default) `
11
15
  query PullRequestBySearchQuery($query: String!, $maxNumber: Int!) {
12
16
  search(query: $query, type: ISSUE, first: $maxNumber) {
13
17
  nodes {
@@ -20,7 +24,7 @@ async function fetchPullRequestBySearchQuery(options) {
20
24
  }
21
25
  }
22
26
 
23
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
27
+ ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
24
28
  `;
25
29
  const authorFilter = author ? ` author:${author}` : '';
26
30
  const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter} ${prFilter} base:${sourceBranch}`;
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchExistingPullRequest = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const apiRequestV4_1 = require("./apiRequestV4");
5
9
  async function fetchExistingPullRequest({ options, prPayload, }) {
6
10
  const { githubApiBaseUrlV4, accessToken } = options;
7
- const query = /* GraphQL */ `
11
+ const query = (0, graphql_tag_1.default) `
8
12
  query ExistingPullRequest(
9
13
  $repoOwner: String!
10
14
  $repoName: String!
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchPullRequestAutoMergeMethod = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const apiRequestV4_1 = require("./apiRequestV4");
5
9
  async function fetchPullRequestAutoMergeMethod(options, pullNumber) {
6
10
  const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
7
- const query = /* GraphQL */ `
11
+ const query = (0, graphql_tag_1.default) `
8
12
  query PullRequestAutoMergeMethod(
9
13
  $repoOwner: String!
10
14
  $repoName: String!
@@ -5,4 +5,4 @@ export declare function fetchRemoteProjectConfig(options: {
5
5
  repoName: string;
6
6
  repoOwner: string;
7
7
  sourceBranch: string;
8
- }): Promise<ConfigFileOptions>;
8
+ }): Promise<ConfigFileOptions | undefined>;
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchRemoteProjectConfig = void 0;
4
- const readConfigFile_1 = require("../../../options/config/readConfigFile");
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const remoteConfig_1 = require("../../remoteConfig");
5
9
  const apiRequestV4_1 = require("./apiRequestV4");
6
10
  async function fetchRemoteProjectConfig(options) {
7
11
  const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch } = options;
8
- const query = /* GraphQL */ `
12
+ const query = (0, graphql_tag_1.default) `
9
13
  query ProjectConfig(
10
14
  $repoOwner: String!
11
15
  $repoName: String!
@@ -14,27 +18,13 @@ async function fetchRemoteProjectConfig(options) {
14
18
  repository(owner: $repoOwner, name: $repoName) {
15
19
  ref(qualifiedName: $sourceBranch) {
16
20
  target {
17
- ... on Commit {
18
- history(first: 1, path: ".backportrc.json") {
19
- edges {
20
- remoteConfig: node {
21
- file(path: ".backportrc.json") {
22
- ... on TreeEntry {
23
- object {
24
- ... on Blob {
25
- text
26
- }
27
- }
28
- }
29
- }
30
- }
31
- }
32
- }
33
- }
21
+ ...RemoteConfigHistory
34
22
  }
35
23
  }
36
24
  }
37
25
  }
26
+
27
+ ${remoteConfig_1.RemoteConfigHistoryFragment}
38
28
  `;
39
29
  try {
40
30
  const res = await (0, apiRequestV4_1.apiRequestV4)({
@@ -47,7 +37,10 @@ async function fetchRemoteProjectConfig(options) {
47
37
  sourceBranch,
48
38
  },
49
39
  });
50
- return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(res.repository.ref.target.history.edges[0].remoteConfig.file.object.text));
40
+ const remoteConfig = res.repository.ref.target.remoteConfigHistory.edges?.[0].remoteConfig;
41
+ if (remoteConfig) {
42
+ return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
43
+ }
51
44
  }
52
45
  catch (e) {
53
46
  throw new Error('Project config does not exist');
@@ -8,10 +8,6 @@ export declare function getOptionsFromGithub(options: {
8
8
  skipRemoteConfig?: boolean;
9
9
  cwd?: string;
10
10
  }): Promise<{
11
- historicalBranchLabelMappings: {
12
- branchLabelMapping: Record<string, string>;
13
- committedDate: string;
14
- }[];
15
11
  accessToken?: string | undefined;
16
12
  assignees?: string[] | undefined;
17
13
  author?: string | null | undefined;
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getOptionsFromGithub = void 0;
4
- const readConfigFile_1 = require("../../../../options/config/readConfigFile");
5
- const filterEmpty_1 = require("../../../../utils/filterEmpty");
6
4
  const HandledError_1 = require("../../../HandledError");
7
5
  const git_1 = require("../../../git");
8
6
  const logger_1 = require("../../../logger");
7
+ const remoteConfig_1 = require("../../../remoteConfig");
9
8
  const apiRequestV4_1 = require("../apiRequestV4");
10
9
  const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
11
10
  const query_1 = require("./query");
@@ -32,30 +31,24 @@ async function getOptionsFromGithub(options) {
32
31
  if (res.repository.illegalBackportBranch) {
33
32
  throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
34
33
  }
35
- const historicalRemoteConfigs = res.repository.defaultBranchRef.target.history.edges;
36
- const latestRemoteConfig = historicalRemoteConfigs[0]?.remoteConfig;
37
- const skipRemoteConfig = await getSkipRemoteConfigFile(options.cwd, options.skipRemoteConfig, latestRemoteConfig);
38
- const remoteConfig = skipRemoteConfig
39
- ? {}
40
- : parseRemoteConfig(latestRemoteConfig);
34
+ const remoteConfig = await getRemoteConfigFileOptions(res, options.cwd, options.skipRemoteConfig);
41
35
  return {
42
36
  authenticatedUsername: options.username ?? res.viewer.login,
43
37
  sourceBranch: res.repository.defaultBranchRef.name,
44
38
  ...remoteConfig,
45
- historicalBranchLabelMappings: skipRemoteConfig
46
- ? []
47
- : getHistoricalBranchLabelMappings(historicalRemoteConfigs),
48
39
  };
49
40
  }
50
41
  exports.getOptionsFromGithub = getOptionsFromGithub;
51
- async function getSkipRemoteConfigFile(cwd, skipRemoteConfig, remoteConfig) {
42
+ async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
52
43
  if (skipRemoteConfig) {
53
44
  logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
54
- return true;
45
+ return;
55
46
  }
47
+ const remoteConfig = res.repository.defaultBranchRef.target.remoteConfigHistory.edges?.[0]
48
+ ?.remoteConfig;
56
49
  if (!remoteConfig) {
57
50
  logger_1.logger.info("Skipping remote config: remote config doesn't exist");
58
- return true;
51
+ return;
59
52
  }
60
53
  if (cwd) {
61
54
  const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
@@ -65,61 +58,27 @@ async function getSkipRemoteConfigFile(cwd, skipRemoteConfig, remoteConfig) {
65
58
  ]);
66
59
  if (isLocalConfigUntracked) {
67
60
  logger_1.logger.info('Skipping remote config: local config is new');
68
- return true;
61
+ return;
69
62
  }
70
63
  if (isLocalConfigModified) {
71
64
  logger_1.logger.info('Skipping remote config: local config is modified');
72
- return true;
65
+ return;
73
66
  }
74
67
  if (localCommitDate &&
75
68
  localCommitDate > Date.parse(remoteConfig.committedDate)) {
76
69
  logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
77
- return true;
78
- }
79
- }
80
- return false;
81
- }
82
- function parseRemoteConfig(remoteConfig) {
83
- if (!remoteConfig) {
84
- return;
85
- }
86
- try {
87
- logger_1.logger.info('Using remote config');
88
- return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(remoteConfig.file.object.text));
89
- }
90
- catch (e) {
91
- logger_1.logger.info('Parsing remote config failed', e);
92
- return;
93
- }
94
- }
95
- function getHistoricalBranchLabelMappings(historicalRemoteConfigs) {
96
- return historicalRemoteConfigs
97
- .map((edge) => {
98
- try {
99
- const remoteConfig = JSON.parse(edge.remoteConfig.file.object.text);
100
- if (!remoteConfig.branchLabelMapping) {
101
- return;
102
- }
103
- return {
104
- branchLabelMapping: remoteConfig.branchLabelMapping,
105
- committedDate: edge.remoteConfig.committedDate,
106
- };
107
- }
108
- catch (e) {
109
- logger_1.logger.info('Could not get historical remote config', e);
110
70
  return;
111
71
  }
112
- })
113
- .filter(filterEmpty_1.filterNil);
72
+ }
73
+ return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
114
74
  }
115
75
  function swallowErrorIfConfigFileIsMissing(error) {
116
76
  const { data, errors } = error.axiosResponse.data;
117
- const wasMissingConfigError = errors?.some((error) => {
118
- const isMatch = /^repository.defaultBranchRef.target.history.edges.\d+.remoteConfig.file$/.test(error.path.join('.'));
119
- return isMatch && error.type === 'NOT_FOUND';
77
+ const missingConfigError = errors?.some((error) => {
78
+ return error.path.includes('remoteConfig') && error.type === 'NOT_FOUND';
120
79
  });
121
80
  // swallow error if it's just the config file that's missing
122
- if (wasMissingConfigError && data != null) {
81
+ if (missingConfigError && data != null) {
123
82
  return data;
124
83
  }
125
84
  // Throw unexpected error
@@ -41,24 +41,6 @@ describe('getOptionsFromGithub', () => {
41
41
  '^v7.9.0$': '7.x',
42
42
  '^v8.0.0$': 'master',
43
43
  },
44
- historicalBranchLabelMappings: [
45
- {
46
- branchLabelMapping: {
47
- '^v(\\d+).(\\d+).\\d+$': '$1.$2',
48
- '^v7.9.0$': '7.x',
49
- '^v8.0.0$': 'master',
50
- },
51
- committedDate: '2020-08-15T10:33:06Z',
52
- },
53
- {
54
- branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
55
- committedDate: '2020-08-15T10:20:23Z',
56
- },
57
- {
58
- branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
59
- committedDate: '2020-08-15T10:17:57Z',
60
- },
61
- ],
62
44
  sourceBranch: 'master',
63
45
  targetBranchChoices: [
64
46
  { checked: true, name: 'master' },
@@ -129,7 +111,6 @@ describe('getOptionsFromGithub', () => {
129
111
  expect(options).toEqual({
130
112
  authenticatedUsername: 'sqren',
131
113
  sourceBranch: 'main',
132
- historicalBranchLabelMappings: [],
133
114
  });
134
115
  });
135
116
  });
@@ -1,11 +1,4 @@
1
- export declare type RemoteConfig = {
2
- committedDate: string;
3
- file: {
4
- object: {
5
- text: string;
6
- };
7
- };
8
- };
1
+ import { RemoteConfigHistory } from '../../../remoteConfig';
9
2
  export interface GithubConfigOptionsResponse {
10
3
  viewer: {
11
4
  login: string;
@@ -16,14 +9,8 @@ export interface GithubConfigOptionsResponse {
16
9
  } | null;
17
10
  defaultBranchRef: {
18
11
  name: string;
19
- target: {
20
- history: {
21
- edges: Array<{
22
- remoteConfig: RemoteConfig;
23
- }>;
24
- };
25
- };
12
+ target: RemoteConfigHistory;
26
13
  };
27
14
  };
28
15
  }
29
- export declare const query = "\n query GithubConfigOptions($repoOwner: String!, $repoName: String!) {\n viewer {\n login\n }\n repository(owner: $repoOwner, name: $repoName) {\n # check to see if a branch named \"backport\" exists\n illegalBackportBranch: ref(qualifiedName: \"refs/heads/backport\") {\n id\n }\n defaultBranchRef {\n name\n target {\n ... on Commit {\n history(first: 20, path: \".backportrc.json\") {\n edges {\n remoteConfig: node {\n committedDate\n file(path: \".backportrc.json\") {\n ... on TreeEntry {\n object {\n ... on Blob {\n text\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n";
16
+ export declare const query: import("graphql").DocumentNode;