backport 7.0.1-beta.2 → 7.2.0-beta.2

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 (163) 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/entrypoint.module.d.ts +4 -3
  5. package/dist/entrypoint.module.js +2 -7
  6. package/dist/options/ConfigOptions.d.ts +1 -1
  7. package/dist/options/cliArgs.d.ts +2 -1
  8. package/dist/options/cliArgs.js +4 -0
  9. package/dist/options/config/config.d.ts +1 -1
  10. package/dist/options/config/readConfigFile.d.ts +2 -2
  11. package/dist/options/options.d.ts +3 -6
  12. package/dist/runSequentially.js +1 -0
  13. package/dist/services/HandledError.js +3 -1
  14. package/dist/services/git.d.ts +2 -0
  15. package/dist/services/git.js +47 -10
  16. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  17. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
  18. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  19. package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
  20. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
  21. package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
  22. package/dist/services/github/v3/createPullRequest.js +2 -5
  23. package/dist/services/github/v3/createStatusComment.js +1 -1
  24. package/dist/services/github/v4/FetchPullRequestId.js +5 -1
  25. package/dist/services/github/v4/apiRequestV4.d.ts +7 -4
  26. package/dist/services/github/v4/apiRequestV4.js +22 -21
  27. package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
  28. package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
  29. package/dist/services/github/v4/fetchAuthorId.js +5 -1
  30. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
  31. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +24 -13
  32. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
  33. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +24 -13
  34. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
  35. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +20 -10
  36. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +20 -9
  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 +1 -5
  42. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -66
  43. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
  44. package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
  45. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
  46. package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
  47. package/dist/services/logger.d.ts +5 -5
  48. package/dist/services/logger.js +24 -23
  49. package/dist/services/remoteConfig.d.ts +20 -0
  50. package/dist/services/remoteConfig.js +52 -0
  51. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
  52. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
  53. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
  54. package/dist/services/sourceCommit/getMockSourceCommit.js +21 -6
  55. package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
  56. package/dist/services/sourceCommit/parseSourceCommit.js +73 -77
  57. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +16 -22
  58. package/dist/ui/getCommits.js +8 -6
  59. package/dist/ui/maybeSetupRepo.js +7 -14
  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 +10 -10
  65. package/yarn.lock +121 -114
  66. package/dist/entrypoint.cli.e2e.private.test.d.ts +0 -1
  67. package/dist/entrypoint.cli.e2e.private.test.js +0 -319
  68. package/dist/entrypoint.cli.private.test.d.ts +0 -1
  69. package/dist/entrypoint.cli.private.test.js +0 -46
  70. package/dist/options/cliArgs.test.d.ts +0 -1
  71. package/dist/options/cliArgs.test.js +0 -182
  72. package/dist/options/config/config.test.d.ts +0 -1
  73. package/dist/options/config/config.test.js +0 -32
  74. package/dist/options/config/globalConfig.test.d.ts +0 -1
  75. package/dist/options/config/globalConfig.test.js +0 -61
  76. package/dist/options/config/projectConfig.test.d.ts +0 -1
  77. package/dist/options/config/projectConfig.test.js +0 -109
  78. package/dist/options/options.test.d.ts +0 -1
  79. package/dist/options/options.test.js +0 -386
  80. package/dist/runSequentially.test.d.ts +0 -1
  81. package/dist/runSequentially.test.js +0 -218
  82. package/dist/scripts/postinstall.test.d.ts +0 -1
  83. package/dist/scripts/postinstall.test.js +0 -53
  84. package/dist/services/env.test.d.ts +0 -1
  85. package/dist/services/env.test.js +0 -21
  86. package/dist/services/git.integration.test.d.ts +0 -1
  87. package/dist/services/git.integration.test.js +0 -267
  88. package/dist/services/git.test.d.ts +0 -1
  89. package/dist/services/git.test.js +0 -518
  90. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  91. package/dist/services/github/commitFormatters.test.js +0 -11
  92. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  93. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  94. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  95. package/dist/services/github/v3/createPullRequest.test.js +0 -325
  96. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  97. package/dist/services/github/v3/createStatusComment.test.js +0 -386
  98. package/dist/services/github/v3/index.d.ts +0 -1
  99. package/dist/services/github/v3/index.js +0 -61
  100. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  101. package/dist/services/github/v4/apiRequestV4.test.js +0 -82
  102. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  103. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  104. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  105. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -28
  106. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  107. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -96
  108. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  109. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -143
  110. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  111. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -124
  112. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  113. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -200
  114. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  115. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -153
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  117. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -102
  118. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  119. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -47
  120. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  121. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -52
  122. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  123. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -136
  124. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  125. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -71
  126. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  127. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -154
  128. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  129. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  130. package/dist/services/prompt.test.d.ts +0 -1
  131. package/dist/services/prompt.test.js +0 -134
  132. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  133. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -433
  134. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  135. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -235
  136. package/dist/test/ExecError.d.ts +0 -16
  137. package/dist/test/ExecError.js +0 -15
  138. package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
  139. package/dist/test/backport-e2e.mutation.test.js +0 -347
  140. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +0 -1
  141. package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -57
  142. package/dist/test/mockConfigFiles.d.ts +0 -5
  143. package/dist/test/mockConfigFiles.js +0 -21
  144. package/dist/test/mocks.d.ts +0 -10
  145. package/dist/test/mocks.js +0 -23
  146. package/dist/test/nockHelpers.d.ts +0 -16
  147. package/dist/test/nockHelpers.js +0 -32
  148. package/dist/test/private/getDevAccessToken.d.ts +0 -2
  149. package/dist/test/private/getDevAccessToken.js +0 -12
  150. package/dist/test/sandbox.d.ts +0 -5
  151. package/dist/test/sandbox.js +0 -43
  152. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  153. package/dist/test/setupFiles/automatic-mocks.js +0 -63
  154. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  155. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -455
  156. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  157. package/dist/ui/getCommitsWithoutBackports.test.js +0 -311
  158. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  159. package/dist/ui/getTargetBranches.test.js +0 -198
  160. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  161. package/dist/ui/maybeSetupRepo.test.js +0 -204
  162. package/dist/utils/excludeUndefined.test.d.ts +0 -1
  163. package/dist/utils/excludeUndefined.test.js +0 -24
@@ -4,7 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.enablePullRequestAutoMerge = void 0;
7
- const ora_1 = __importDefault(require("ora"));
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const ora_1 = require("../../../ui/ora");
8
9
  const logger_1 = require("../../logger");
9
10
  const FetchPullRequestId_1 = require("./FetchPullRequestId");
10
11
  const apiRequestV4_1 = require("./apiRequestV4");
@@ -12,9 +13,9 @@ async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
12
13
  const { accessToken, githubApiBaseUrlV4, autoMergeMethod = 'merge', } = options;
13
14
  const text = `Enabling auto merging via ${options.autoMergeMethod}`;
14
15
  logger_1.logger.info(text);
15
- const spinner = (0, ora_1.default)(text).start();
16
+ const spinner = (0, ora_1.ora)(options.ci, text).start();
16
17
  const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, targetPullRequestNumber);
17
- const query = /* GraphQL */ `
18
+ const query = (0, graphql_tag_1.default) `
18
19
  mutation EnablePullRequestAutoMerge(
19
20
  $pullRequestId: ID!
20
21
  $mergeMethod: PullRequestMergeMethod!
@@ -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.fetchAuthorId = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const apiRequestV4_1 = require("./apiRequestV4");
5
9
  async function fetchAuthorId({ accessToken, author, githubApiBaseUrlV4 = 'https://api.github.com/graphql', }) {
6
10
  if (author === null) {
7
11
  return null;
8
12
  }
9
- const query = /* GraphQL */ `
13
+ const query = (0, graphql_tag_1.default) `
10
14
  query AuthorId($author: String!) {
11
15
  user(login: $author) {
12
16
  id
@@ -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,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.fetchCommitByPullNumber = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const HandledError_1 = require("../../../HandledError");
9
+ const remoteConfig_1 = require("../../../remoteConfig");
5
10
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
6
11
  const apiRequestV4_1 = require("../apiRequestV4");
7
12
  async function fetchCommitByPullNumber(options) {
8
13
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', pullNumber, repoName, repoOwner, } = options;
9
- const query = /* GraphQL */ `
14
+ const query = (0, graphql_tag_1.default) `
10
15
  query CommitByPullNumber(
11
16
  $repoOwner: String!
12
17
  $repoName: String!
@@ -15,24 +20,30 @@ async function fetchCommitByPullNumber(options) {
15
20
  repository(owner: $repoOwner, name: $repoName) {
16
21
  pullRequest(number: $pullNumber) {
17
22
  mergeCommit {
18
- ...SourceCommitWithTargetPullRequest
23
+ ...SourceCommitWithTargetPullRequestFragment
19
24
  }
20
25
  }
21
26
  }
22
27
  }
23
28
 
24
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
29
+ ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
25
30
  `;
26
- const res = await (0, apiRequestV4_1.apiRequestV4)({
27
- githubApiBaseUrlV4,
28
- accessToken,
29
- query,
30
- variables: {
31
- repoOwner,
32
- repoName,
33
- pullNumber,
34
- },
35
- });
31
+ let res;
32
+ try {
33
+ res = await (0, apiRequestV4_1.apiRequestV4)({
34
+ githubApiBaseUrlV4,
35
+ accessToken,
36
+ query,
37
+ variables: {
38
+ repoOwner,
39
+ repoName,
40
+ pullNumber,
41
+ },
42
+ });
43
+ }
44
+ catch (e) {
45
+ res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
46
+ }
36
47
  const pullRequestNode = res.repository.pullRequest;
37
48
  if (!pullRequestNode) {
38
49
  throw new HandledError_1.HandledError(`The PR #${pullNumber} does not exist`);
@@ -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,32 +1,43 @@
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");
9
+ const remoteConfig_1 = require("../../../remoteConfig");
5
10
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
6
11
  const apiRequestV4_1 = require("../apiRequestV4");
7
12
  async function fetchCommitBySha(options) {
8
13
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
9
- const query = /* GraphQL */ `
14
+ const query = (0, graphql_tag_1.default) `
10
15
  query CommitsBySha($repoOwner: String!, $repoName: String!, $sha: String!) {
11
16
  repository(owner: $repoOwner, name: $repoName) {
12
17
  object(expression: $sha) {
13
- ...SourceCommitWithTargetPullRequest
18
+ ...SourceCommitWithTargetPullRequestFragment
14
19
  }
15
20
  }
16
21
  }
17
22
 
18
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
23
+ ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
19
24
  `;
20
- const res = await (0, apiRequestV4_1.apiRequestV4)({
21
- githubApiBaseUrlV4,
22
- accessToken,
23
- query,
24
- variables: {
25
- repoOwner,
26
- repoName,
27
- sha,
28
- },
29
- });
25
+ let res;
26
+ try {
27
+ res = await (0, apiRequestV4_1.apiRequestV4)({
28
+ githubApiBaseUrlV4,
29
+ accessToken,
30
+ query,
31
+ variables: {
32
+ repoOwner,
33
+ repoName,
34
+ sha,
35
+ },
36
+ });
37
+ }
38
+ catch (e) {
39
+ res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
40
+ }
30
41
  const sourceCommit = res.repository.object;
31
42
  if (!sourceCommit) {
32
43
  throw new HandledError_1.HandledError(`No commit found on branch "${sourceBranch}" with sha "${sha}"`);
@@ -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,15 +1,20 @@
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");
11
+ const remoteConfig_1 = require("../../../remoteConfig");
7
12
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
8
13
  const apiRequestV4_1 = require("../apiRequestV4");
9
14
  const fetchAuthorId_1 = require("../fetchAuthorId");
10
- function fetchByCommitPath({ options, authorId, commitPath, }) {
15
+ async function fetchByCommitPath({ options, authorId, commitPath, }) {
11
16
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, dateSince, dateUntil, } = options;
12
- const query = /* GraphQL */ `
17
+ const query = (0, graphql_tag_1.default) `
13
18
  query CommitsByAuthor(
14
19
  $repoOwner: String!
15
20
  $repoName: String!
@@ -33,7 +38,7 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
33
38
  ) {
34
39
  edges {
35
40
  node {
36
- ...SourceCommitWithTargetPullRequest
41
+ ...SourceCommitWithTargetPullRequestFragment
37
42
  }
38
43
  }
39
44
  }
@@ -43,7 +48,7 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
43
48
  }
44
49
  }
45
50
 
46
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
51
+ ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
47
52
  `;
48
53
  const variables = {
49
54
  repoOwner,
@@ -55,12 +60,17 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
55
60
  dateSince,
56
61
  dateUntil,
57
62
  };
58
- return (0, apiRequestV4_1.apiRequestV4)({
59
- githubApiBaseUrlV4,
60
- accessToken,
61
- query,
62
- variables,
63
- });
63
+ try {
64
+ return await (0, apiRequestV4_1.apiRequestV4)({
65
+ githubApiBaseUrlV4,
66
+ accessToken,
67
+ query,
68
+ variables,
69
+ });
70
+ }
71
+ catch (e) {
72
+ return (0, remoteConfig_1.swallowMissingConfigFileException)(e);
73
+ }
64
74
  }
65
75
  async function fetchCommitsByAuthor(options) {
66
76
  const { sourceBranch, commitPaths = [] } = options;
@@ -1,26 +1,31 @@
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");
10
+ const remoteConfig_1 = require("../../../remoteConfig");
6
11
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
7
12
  const apiRequestV4_1 = require("../apiRequestV4");
8
13
  async function fetchPullRequestBySearchQuery(options) {
9
14
  const { accessToken, githubApiBaseUrlV4, maxNumber = 10, prFilter, repoName, repoOwner, sourceBranch, author, } = options;
10
- const query = /* GraphQL */ `
15
+ const query = (0, graphql_tag_1.default) `
11
16
  query PullRequestBySearchQuery($query: String!, $maxNumber: Int!) {
12
17
  search(query: $query, type: ISSUE, first: $maxNumber) {
13
18
  nodes {
14
19
  ... on PullRequest {
15
20
  mergeCommit {
16
- ...SourceCommitWithTargetPullRequest
21
+ ...SourceCommitWithTargetPullRequestFragment
17
22
  }
18
23
  }
19
24
  }
20
25
  }
21
26
  }
22
27
 
23
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
28
+ ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
24
29
  `;
25
30
  const authorFilter = author ? ` author:${author}` : '';
26
31
  const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter} ${prFilter} base:${sourceBranch}`;
@@ -28,12 +33,18 @@ async function fetchPullRequestBySearchQuery(options) {
28
33
  query: searchQuery,
29
34
  maxNumber: maxNumber,
30
35
  };
31
- const res = await (0, apiRequestV4_1.apiRequestV4)({
32
- githubApiBaseUrlV4,
33
- accessToken,
34
- query,
35
- variables,
36
- });
36
+ let res;
37
+ try {
38
+ res = await (0, apiRequestV4_1.apiRequestV4)({
39
+ githubApiBaseUrlV4,
40
+ accessToken,
41
+ query,
42
+ variables,
43
+ });
44
+ }
45
+ catch (e) {
46
+ res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
47
+ }
37
48
  const commits = res.search.nodes.map((pullRequestNode) => {
38
49
  const sourceCommit = pullRequestNode.mergeCommit;
39
50
  return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
@@ -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
+ ...RemoteConfigHistoryFragment
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;
@@ -51,7 +47,7 @@ export declare function getOptionsFromGithub(options: {
51
47
  repoOwner?: string | undefined;
52
48
  resetAuthor?: boolean | undefined;
53
49
  reviewers?: string[] | undefined;
54
- sha?: string | undefined;
50
+ sha?: string | string[] | undefined;
55
51
  skipRemoteConfig?: boolean | undefined;
56
52
  sourceBranch: string;
57
53
  sourcePRLabels?: string[] | 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");
@@ -24,38 +23,31 @@ async function getOptionsFromGithub(options) {
24
23
  if (!(e instanceof apiRequestV4_1.GithubV4Exception)) {
25
24
  throw e;
26
25
  }
27
- const error = e;
28
- (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({ error, repoName, repoOwner });
29
- res = swallowErrorIfConfigFileIsMissing(error);
26
+ (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({ error: e, repoName, repoOwner });
27
+ res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
30
28
  }
31
29
  // it is not possible to have a branch named "backport"
32
30
  if (res.repository.illegalBackportBranch) {
33
31
  throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
34
32
  }
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);
33
+ const remoteConfig = await getRemoteConfigFileOptions(res, options.cwd, options.skipRemoteConfig);
41
34
  return {
42
35
  authenticatedUsername: options.username ?? res.viewer.login,
43
36
  sourceBranch: res.repository.defaultBranchRef.name,
44
37
  ...remoteConfig,
45
- historicalBranchLabelMappings: skipRemoteConfig
46
- ? []
47
- : getHistoricalBranchLabelMappings(historicalRemoteConfigs),
48
38
  };
49
39
  }
50
40
  exports.getOptionsFromGithub = getOptionsFromGithub;
51
- async function getSkipRemoteConfigFile(cwd, skipRemoteConfig, remoteConfig) {
41
+ async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
52
42
  if (skipRemoteConfig) {
53
43
  logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
54
- return true;
44
+ return;
55
45
  }
46
+ const remoteConfig = res.repository.defaultBranchRef.target.remoteConfigHistory.edges?.[0]
47
+ ?.remoteConfig;
56
48
  if (!remoteConfig) {
57
49
  logger_1.logger.info("Skipping remote config: remote config doesn't exist");
58
- return true;
50
+ return;
59
51
  }
60
52
  if (cwd) {
61
53
  const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
@@ -65,63 +57,17 @@ async function getSkipRemoteConfigFile(cwd, skipRemoteConfig, remoteConfig) {
65
57
  ]);
66
58
  if (isLocalConfigUntracked) {
67
59
  logger_1.logger.info('Skipping remote config: local config is new');
68
- return true;
60
+ return;
69
61
  }
70
62
  if (isLocalConfigModified) {
71
63
  logger_1.logger.info('Skipping remote config: local config is modified');
72
- return true;
64
+ return;
73
65
  }
74
66
  if (localCommitDate &&
75
67
  localCommitDate > Date.parse(remoteConfig.committedDate)) {
76
68
  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
69
  return;
111
70
  }
112
- })
113
- .filter(filterEmpty_1.filterNil);
114
- }
115
- function swallowErrorIfConfigFileIsMissing(error) {
116
- 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';
120
- });
121
- // swallow error if it's just the config file that's missing
122
- if (wasMissingConfigError && data != null) {
123
- return data;
124
71
  }
125
- // Throw unexpected error
126
- throw error;
72
+ return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
127
73
  }
@@ -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;
@@ -1,7 +1,12 @@
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.query = void 0;
4
- exports.query = `
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const remoteConfig_1 = require("../../../remoteConfig");
9
+ exports.query = (0, graphql_tag_1.default) `
5
10
  query GithubConfigOptions($repoOwner: String!, $repoName: String!) {
6
11
  viewer {
7
12
  login
@@ -14,26 +19,11 @@ exports.query = `
14
19
  defaultBranchRef {
15
20
  name
16
21
  target {
17
- ... on Commit {
18
- history(first: 20, path: ".backportrc.json") {
19
- edges {
20
- remoteConfig: node {
21
- committedDate
22
- file(path: ".backportrc.json") {
23
- ... on TreeEntry {
24
- object {
25
- ... on Blob {
26
- text
27
- }
28
- }
29
- }
30
- }
31
- }
32
- }
33
- }
34
- }
22
+ ...RemoteConfigHistoryFragment
35
23
  }
36
24
  }
37
25
  }
38
26
  }
27
+
28
+ ${remoteConfig_1.RemoteConfigHistoryFragment}
39
29
  `;
@@ -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.getRepoOwnerAndNameFromGitRemotes = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const maybe_1 = require("../../../utils/maybe");
5
9
  const git_1 = require("../../git");
6
10
  const logger_1 = require("../../logger");
@@ -38,7 +42,7 @@ async function getRepoOwnerAndNameFromGitRemotes({ accessToken, githubApiBaseUrl
38
42
  }
39
43
  }
40
44
  exports.getRepoOwnerAndNameFromGitRemotes = getRepoOwnerAndNameFromGitRemotes;
41
- const query = /* GraphQL */ `
45
+ const query = (0, graphql_tag_1.default) `
42
46
  query RepoOwnerAndName($repoOwner: String!, $repoName: String!) {
43
47
  repository(owner: $repoOwner, name: $repoName) {
44
48
  isFork