backport 5.6.6 → 6.1.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 (234) hide show
  1. package/README.md +186 -50
  2. package/dist/entrypoint.cli.js +3 -1
  3. package/dist/entrypoint.module.d.ts +18 -5
  4. package/dist/entrypoint.module.js +42 -12
  5. package/dist/entrypoint.module.private.test.d.ts +1 -0
  6. package/dist/entrypoint.module.private.test.js +34 -0
  7. package/dist/ink.d.ts +1 -0
  8. package/dist/ink.js +49 -0
  9. package/dist/main.d.ts +11 -6
  10. package/dist/main.js +40 -25
  11. package/dist/options/ConfigOptions.d.ts +28 -13
  12. package/dist/options/cliArgs.d.ts +36 -35
  13. package/dist/options/cliArgs.js +91 -52
  14. package/dist/options/cliArgs.test.js +35 -43
  15. package/dist/options/config/config.d.ts +35 -57
  16. package/dist/options/config/config.js +5 -39
  17. package/dist/options/config/config.test.js +11 -27
  18. package/dist/options/config/getOptionsFromGit.d.ts +3 -2
  19. package/dist/options/config/getOptionsFromGit.js +1 -3
  20. package/dist/options/config/globalConfig.d.ts +2 -51
  21. package/dist/options/config/globalConfig.js +9 -12
  22. package/dist/options/config/globalConfig.test.js +7 -5
  23. package/dist/options/config/projectConfig.d.ts +2 -51
  24. package/dist/options/config/projectConfig.js +2 -2
  25. package/dist/options/config/projectConfig.test.js +53 -16
  26. package/dist/options/config/readConfigFile.d.ts +44 -41
  27. package/dist/options/config/readConfigFile.js +30 -4
  28. package/dist/options/options.d.ts +59 -31
  29. package/dist/options/options.js +103 -10
  30. package/dist/options/options.test.js +266 -79
  31. package/dist/options/parseRequiredOptions.d.ts +19 -14
  32. package/dist/options/parseRequiredOptions.js +9 -15
  33. package/dist/options/parseRequiredOptions.test.js +30 -26
  34. package/dist/runSequentially.d.ts +20 -0
  35. package/dist/runSequentially.js +41 -0
  36. package/dist/runSequentially.test.d.ts +1 -0
  37. package/dist/runSequentially.test.js +196 -0
  38. package/dist/runWithOptions.js +7 -14
  39. package/dist/runWithOptions.test.js +138 -17
  40. package/dist/scripts/generate-gql.d.ts +1 -0
  41. package/dist/scripts/generate-gql.js +15 -0
  42. package/dist/scripts/postinstall.js +4 -4
  43. package/dist/scripts/postinstall.test.js +9 -2
  44. package/dist/scripts/runPostinstall.js +1 -1
  45. package/dist/services/HandledError.d.ts +11 -1
  46. package/dist/services/HandledError.js +2 -1
  47. package/dist/services/child-process-promisified.d.ts +1 -1
  48. package/dist/services/child-process-promisified.js +1 -1
  49. package/dist/services/env.js +5 -5
  50. package/dist/services/env.test.js +11 -4
  51. package/dist/services/fs-promisified.js +4 -4
  52. package/dist/services/getExpectedTarget.d.ts +9 -0
  53. package/dist/services/getExpectedTarget.js +77 -0
  54. package/dist/services/getExpectedTargetPullRequests.d.ts +9 -0
  55. package/dist/services/getExpectedTargetPullRequests.js +77 -0
  56. package/dist/services/git.d.ts +20 -6
  57. package/dist/services/git.integration.test.d.ts +1 -0
  58. package/dist/services/git.integration.test.js +168 -0
  59. package/dist/services/git.js +93 -67
  60. package/dist/services/git.test.js +68 -68
  61. package/dist/services/github/commitFormatters.d.ts +3 -7
  62. package/dist/services/github/commitFormatters.js +10 -19
  63. package/dist/services/github/commitFormatters.test.js +2 -24
  64. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  65. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -8
  66. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +6 -8
  67. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  68. package/dist/services/github/v3/addLabelsToPullRequest.js +2 -6
  69. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +2 -0
  70. package/dist/services/github/v3/addReviewersToPullRequest.js +34 -0
  71. package/dist/services/github/v3/createPullRequest.d.ts +3 -2
  72. package/dist/services/github/v3/createPullRequest.js +31 -25
  73. package/dist/services/github/v3/createPullRequest.test.d.ts +1 -0
  74. package/dist/services/github/v3/createPullRequest.test.js +110 -0
  75. package/dist/services/github/v3/createStatusComment.d.ts +11 -0
  76. package/dist/services/github/v3/createStatusComment.js +95 -0
  77. package/dist/services/github/v3/createStatusComment.test.d.ts +1 -0
  78. package/dist/services/github/v3/createStatusComment.test.js +209 -0
  79. package/dist/services/github/v4/FetchPullRequestId.js +1 -1
  80. package/dist/services/github/v4/apiRequestV4.d.ts +2 -2
  81. package/dist/services/github/v4/apiRequestV4.js +6 -8
  82. package/dist/services/github/v4/apiRequestV4.test.js +7 -7
  83. package/dist/services/github/v4/disablePullRequestAutoMerge.js +3 -4
  84. package/dist/services/github/v4/enablePullRequestAutoMerge.js +9 -8
  85. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +93 -33
  86. package/dist/services/github/v4/fetchAuthorId.d.ts +5 -2
  87. package/dist/services/github/v4/fetchAuthorId.js +6 -7
  88. package/dist/services/github/v4/fetchAuthorId.private.test.js +6 -9
  89. package/dist/services/github/v4/fetchCommitByPullNumber.js +11 -9
  90. package/dist/services/github/v4/fetchCommitByPullNumber.private.test.js +4 -4
  91. package/dist/services/github/v4/fetchCommitBySha.js +14 -12
  92. package/dist/services/github/v4/fetchCommitBySha.private.test.js +4 -4
  93. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +12 -0
  94. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +46 -0
  95. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  96. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +70 -0
  97. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +12 -0
  98. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +36 -0
  99. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  100. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +55 -0
  101. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +27 -0
  102. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +88 -0
  103. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  104. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +128 -0
  105. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  106. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +125 -0
  107. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.d.ts +28 -0
  108. package/dist/services/github/v4/fetchCommits/fetchCommitsInDateRange.js +52 -0
  109. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.d.ts +3 -0
  110. package/dist/services/github/v4/fetchCommits/fetchProjectConfig.js +55 -0
  111. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.d.ts +10 -0
  112. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +49 -0
  113. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  114. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +77 -0
  115. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.d.ts +1 -0
  116. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.test.js +252 -0
  117. package/dist/services/github/v4/fetchCommitsByAuthor.d.ts +2 -1
  118. package/dist/services/github/v4/fetchCommitsByAuthor.js +81 -70
  119. package/dist/services/github/v4/fetchCommitsByAuthor.private.test.js +78 -5
  120. package/dist/services/github/v4/fetchCommitsByAuthor.test.js +29 -21
  121. package/dist/services/github/v4/fetchDefaultBranch.js +1 -1
  122. package/dist/services/github/v4/fetchExistingPullRequest.js +2 -3
  123. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +3 -5
  124. package/dist/services/github/v4/fetchMergedPullRequests.d.ts +18 -19
  125. package/dist/services/github/v4/fetchMergedPullRequests.js +22 -69
  126. package/dist/services/github/v4/fetchMergedPullRequests.private.test.js +8 -9
  127. package/dist/services/github/v4/fetchProjectConfig.d.ts +8 -0
  128. package/dist/services/github/v4/fetchProjectConfig.js +56 -0
  129. package/dist/services/github/v4/fetchProjectConfig.private.test.d.ts +1 -0
  130. package/dist/services/github/v4/fetchProjectConfig.private.test.js +52 -0
  131. package/dist/services/github/v4/fetchProjectConfig.test.d.ts +1 -0
  132. package/dist/services/github/v4/fetchProjectConfig.test.js +37 -0
  133. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +2 -3
  134. package/dist/services/github/v4/fetchPullRequestBySearchQuery.js +12 -10
  135. package/dist/services/github/v4/fetchPullRequestBySearchQuery.private.test.js +3 -3
  136. package/dist/services/github/v4/fetchPullRequestBySearchQuery.test.js +2 -2
  137. package/dist/services/github/v4/getExistingTargetPullRequests.d.ts +4 -58
  138. package/dist/services/github/v4/getExistingTargetPullRequests.js +3 -58
  139. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +67 -0
  140. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +130 -0
  141. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  142. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +130 -0
  143. package/dist/services/github/v4/getOptionsFromGithub/index.d.ts +19 -11
  144. package/dist/services/github/v4/getOptionsFromGithub/index.js +52 -22
  145. package/dist/services/github/v4/getOptionsFromGithub/index.private.test.js +46 -7
  146. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +16 -16
  147. package/dist/services/github/v4/getOptionsFromGithub/query.js +16 -15
  148. package/dist/services/github/v4/getTargetBranchesFromLabels.d.ts +0 -7
  149. package/dist/services/github/v4/getTargetBranchesFromLabels.js +1 -26
  150. package/dist/services/github/v4/getTargetBranchesFromLabels.test.js +69 -32
  151. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +2 -2
  152. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +39 -25
  153. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.d.ts +1 -1
  154. package/dist/services/github/v4/mocks/fetchPullRequestBySearchQueryMock.js +10 -0
  155. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.d.ts +1 -1
  156. package/dist/services/github/v4/mocks/getCommitsByAuthorMock.js +2 -0
  157. package/dist/services/github/v4/mocks/getPullRequestNodeMock.d.ts +1 -1
  158. package/dist/services/github/v4/mocks/getPullRequestNodeMock.js +1 -0
  159. package/dist/services/github/v4/throwOnInvalidAccessToken.js +10 -15
  160. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +7 -7
  161. package/dist/services/logger.d.ts +3 -3
  162. package/dist/services/logger.js +16 -15
  163. package/dist/services/prompt.test.d.ts +1 -0
  164. package/dist/services/prompt.test.js +87 -0
  165. package/dist/services/prompts.d.ts +10 -4
  166. package/dist/services/prompts.js +85 -22
  167. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +9 -0
  168. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +92 -0
  169. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  170. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +413 -0
  171. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +21 -0
  172. package/dist/services/sourceCommit/getMockSourceCommit.js +67 -0
  173. package/dist/services/sourceCommit/getTargetBranchesFromLabels.d.ts +5 -0
  174. package/dist/services/sourceCommit/getTargetBranchesFromLabels.js +20 -0
  175. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.d.ts +1 -0
  176. package/dist/services/sourceCommit/getTargetBranchesFromLabels.test.js +201 -0
  177. package/dist/services/sourceCommit/parseSourceCommit.d.ts +82 -0
  178. package/dist/services/sourceCommit/parseSourceCommit.js +96 -0
  179. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  180. package/dist/services/sourceCommit/parseSourceCommit.test.js +229 -0
  181. package/dist/services/sourceCommit/sourceCommit.d.ts +78 -0
  182. package/dist/services/sourceCommit/sourceCommit.js +86 -0
  183. package/dist/services/sourceCommit/sourceCommit.test.d.ts +1 -0
  184. package/dist/services/sourceCommit/sourceCommit.test.js +287 -0
  185. package/dist/services/sourceCommit.d.ts +78 -0
  186. package/dist/services/sourceCommit.js +86 -0
  187. package/dist/services/sourceCommit.test.d.ts +1 -0
  188. package/dist/services/sourceCommit.test.js +280 -0
  189. package/dist/test/inquirer.private.test.js +55 -51
  190. package/dist/test/integration/createSpies.js +6 -6
  191. package/dist/test/integration/envConstants.js +5 -6
  192. package/dist/test/integration/helpers.js +1 -1
  193. package/dist/test/integration/integration.private.test.d.ts +1 -0
  194. package/dist/test/integration/integration.private.test.js +327 -0
  195. package/dist/test/integration/integration.test.js +28 -29
  196. package/dist/test/mockConfigFiles.d.ts +5 -0
  197. package/dist/test/mockConfigFiles.js +37 -0
  198. package/dist/test/nockHelpers.d.ts +1 -1
  199. package/dist/test/nockHelpers.js +7 -11
  200. package/dist/test/private/getDevAccessToken.js +1 -1
  201. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  202. package/dist/test/setupFiles/automatic-mocks.js +1 -51
  203. package/dist/types/Commit.d.ts +85 -0
  204. package/dist/types/Commit.js +139 -0
  205. package/dist/types/commitNode.d.ts +89 -0
  206. package/dist/types/commitNode.js +139 -0
  207. package/dist/types/commitNode.test.d.ts +1 -0
  208. package/dist/types/commitNode.test.js +255 -0
  209. package/dist/types/commitWithAssociatedPullRequests.d.ts +86 -0
  210. package/dist/types/commitWithAssociatedPullRequests.js +145 -0
  211. package/dist/ui/cherrypickAndCreatePullRequest.test.js +346 -76
  212. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +2 -1
  213. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +95 -67
  214. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  215. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +468 -0
  216. package/dist/ui/getCommits.d.ts +1 -1
  217. package/dist/ui/getCommits.js +55 -25
  218. package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
  219. package/dist/ui/getCommitsWithoutBackports.js +53 -0
  220. package/dist/ui/getTargetBranches.d.ts +3 -2
  221. package/dist/ui/getTargetBranches.js +33 -18
  222. package/dist/ui/getTargetBranches.test.js +75 -99
  223. package/dist/ui/getTargetBranchesFromLabels.d.ts +6 -0
  224. package/dist/ui/getTargetBranchesFromLabels.js +40 -0
  225. package/dist/ui/getTargetBranchesFromLabels.test.d.ts +1 -0
  226. package/dist/ui/getTargetBranchesFromLabels.test.js +288 -0
  227. package/dist/ui/maybeSetupRepo.js +11 -10
  228. package/dist/ui/maybeSetupRepo.test.js +54 -4
  229. package/dist/utils/excludeUndefined.d.ts +6 -0
  230. package/dist/utils/excludeUndefined.js +7 -0
  231. package/dist/utils/excludeUndefined.test.d.ts +1 -0
  232. package/dist/utils/excludeUndefined.test.js +24 -0
  233. package/package.json +37 -51
  234. package/yarn.lock +2414 -2993
@@ -0,0 +1,67 @@
1
+ export declare type OptionsFromGithub = Awaited<ReturnType<typeof getOptionsFromGithub>>;
2
+ export declare function getOptionsFromGithub(options: {
3
+ accessToken: string;
4
+ githubApiBaseUrlV4?: string;
5
+ repoName: string;
6
+ repoOwner: string;
7
+ skipRemoteConfig?: boolean;
8
+ }): Promise<{
9
+ historicalBranchLabelMappings: {
10
+ branchLabelMapping: Record<string, string>;
11
+ committedDate: string;
12
+ }[];
13
+ accessToken?: string | undefined;
14
+ assignees?: string[] | undefined;
15
+ author?: string | null | undefined;
16
+ autoAssign?: boolean | undefined;
17
+ autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
18
+ files: string[];
19
+ directory: string;
20
+ logger: {
21
+ error: (message: string, meta?: unknown) => void;
22
+ warn: (message: string, meta?: unknown) => void;
23
+ info: (message: string, meta?: unknown) => void;
24
+ verbose: (message: string, meta?: unknown) => void;
25
+ debug: (message: string, meta?: unknown) => void;
26
+ };
27
+ targetBranch: string;
28
+ }) => boolean | Promise<boolean>) | undefined;
29
+ autoMerge?: boolean | undefined;
30
+ autoMergeMethod?: string | undefined;
31
+ backportBinary?: string | undefined;
32
+ cherrypickRef?: boolean | undefined;
33
+ ci?: boolean | undefined;
34
+ commitPaths?: string[] | undefined;
35
+ details?: boolean | undefined;
36
+ editor?: string | undefined;
37
+ fork?: boolean | undefined;
38
+ gitHostname?: string | undefined;
39
+ githubApiBaseUrlV3?: string | undefined;
40
+ githubApiBaseUrlV4?: string | undefined;
41
+ maxNumber?: number | undefined;
42
+ multiple?: boolean | undefined;
43
+ multipleBranches?: boolean | undefined;
44
+ multipleCommits?: boolean | undefined;
45
+ noVerify?: boolean | undefined;
46
+ prDescription?: string | undefined;
47
+ prFilter?: string | undefined;
48
+ prTitle?: string | undefined;
49
+ pullNumber?: number | undefined;
50
+ repoName?: string | undefined;
51
+ repoOwner?: string | undefined;
52
+ resetAuthor?: boolean | undefined;
53
+ reviewers?: string[] | undefined;
54
+ sha?: string | undefined;
55
+ skipRemoteConfig?: boolean | undefined;
56
+ sourceBranch: string;
57
+ sourcePRLabels?: string[] | undefined;
58
+ targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
59
+ targetBranches?: string[] | undefined;
60
+ targetPRLabels?: string[] | undefined;
61
+ verbose?: boolean | undefined;
62
+ branchLabelMapping?: Record<string, string> | undefined;
63
+ upstream?: string | undefined;
64
+ branches?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
65
+ labels?: string[] | undefined;
66
+ authenticatedUsername: string;
67
+ }>;
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getOptionsFromGithub = void 0;
7
+ const ora_1 = __importDefault(require("ora"));
8
+ const readConfigFile_1 = require("../../../../options/config/readConfigFile");
9
+ const filterEmpty_1 = require("../../../../utils/filterEmpty");
10
+ const HandledError_1 = require("../../../HandledError");
11
+ const git_1 = require("../../../git");
12
+ const logger_1 = require("../../../logger");
13
+ const apiRequestV4_1 = require("../apiRequestV4");
14
+ const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
15
+ const query_1 = require("./query");
16
+ async function getOptionsFromGithub(options) {
17
+ const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
18
+ let res;
19
+ const spinner = (0, ora_1.default)().start('Initializing...');
20
+ try {
21
+ res = await (0, apiRequestV4_1.apiRequestV4)({
22
+ githubApiBaseUrlV4,
23
+ accessToken,
24
+ query: query_1.query,
25
+ variables: { repoOwner, repoName },
26
+ handleError: false,
27
+ });
28
+ spinner.stop();
29
+ }
30
+ catch (e) {
31
+ spinner.stop();
32
+ const error = e;
33
+ (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
34
+ error,
35
+ repoName,
36
+ repoOwner,
37
+ });
38
+ res = handleMissingConfigFile(error);
39
+ }
40
+ // get the original repo (not the fork)
41
+ const repo = res.repository.isFork ? res.repository.parent : res.repository;
42
+ // it is not possible to have a branch named "backport"
43
+ if (repo.ref?.name === 'backport') {
44
+ throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
45
+ }
46
+ const historicalRemoteConfigs = repo.defaultBranchRef.target.history.edges;
47
+ const latestRemoteConfig = historicalRemoteConfigs[0]?.remoteConfig;
48
+ const skipRemoteConfig = await getSkipRemoteConfigFile(options.skipRemoteConfig, latestRemoteConfig);
49
+ return {
50
+ authenticatedUsername: res.viewer.login,
51
+ sourceBranch: repo.defaultBranchRef.name,
52
+ ...(skipRemoteConfig ? {} : parseRemoteConfig(latestRemoteConfig)),
53
+ historicalBranchLabelMappings: skipRemoteConfig
54
+ ? []
55
+ : getHistoricalBranchLabelMappings(historicalRemoteConfigs),
56
+ };
57
+ }
58
+ exports.getOptionsFromGithub = getOptionsFromGithub;
59
+ async function getSkipRemoteConfigFile(skipRemoteConfig, remoteConfig) {
60
+ if (skipRemoteConfig) {
61
+ logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
62
+ return true;
63
+ }
64
+ if (!remoteConfig) {
65
+ logger_1.logger.info("Skipping remote config: remote config doesn't exist");
66
+ return true;
67
+ }
68
+ const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
69
+ (0, git_1.isLocalConfigFileModified)(),
70
+ (0, git_1.isLocalConfigFileUntracked)(),
71
+ (0, git_1.getLocalConfigFileCommitDate)(),
72
+ ]);
73
+ if (isLocalConfigUntracked) {
74
+ logger_1.logger.info('Skipping remote config: local config is new');
75
+ return true;
76
+ }
77
+ if (isLocalConfigModified) {
78
+ logger_1.logger.info('Skipping remote config: local config is modified');
79
+ return true;
80
+ }
81
+ if (localCommitDate &&
82
+ localCommitDate > Date.parse(remoteConfig.committedDate)) {
83
+ logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
84
+ return true;
85
+ }
86
+ return false;
87
+ }
88
+ function parseRemoteConfig(remoteConfig) {
89
+ if (!remoteConfig) {
90
+ return;
91
+ }
92
+ try {
93
+ logger_1.logger.info('Using remote config');
94
+ return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(remoteConfig.file.object.text));
95
+ }
96
+ catch (e) {
97
+ logger_1.logger.info('Parsing remote config failed', e);
98
+ return;
99
+ }
100
+ }
101
+ function getHistoricalBranchLabelMappings(historicalRemoteConfigs) {
102
+ return historicalRemoteConfigs
103
+ .map((edge) => {
104
+ try {
105
+ const remoteConfig = JSON.parse(edge.remoteConfig.file.object.text);
106
+ if (!remoteConfig.branchLabelMapping) {
107
+ return;
108
+ }
109
+ return {
110
+ branchLabelMapping: remoteConfig.branchLabelMapping,
111
+ committedDate: edge.remoteConfig.committedDate,
112
+ };
113
+ }
114
+ catch (e) {
115
+ logger_1.logger.info('Could not get historical remote config', e);
116
+ return;
117
+ }
118
+ })
119
+ .filter(filterEmpty_1.filterNil);
120
+ }
121
+ function handleMissingConfigFile(error) {
122
+ const wasMissingConfigError = error.response?.data.errors?.some((error) => error.type === 'NOT_FOUND' &&
123
+ error.path.join('.') ===
124
+ 'repository.defaultBranchRef.target.history.edges.0.remoteConfig.file');
125
+ // Throw unexpected error
126
+ if (!wasMissingConfigError || !error.response?.data.data) {
127
+ throw (0, apiRequestV4_1.handleGithubV4Error)(error);
128
+ }
129
+ return error.response.data.data;
130
+ }
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const os_1 = __importDefault(require("os"));
7
+ const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
8
+ const getOptionsFromGithub_1 = require("./getOptionsFromGithub");
9
+ describe('getOptionsFromGithub', () => {
10
+ let devAccessToken;
11
+ beforeAll(async () => {
12
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
13
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
14
+ });
15
+ describe('access token', () => {
16
+ describe('is invalid', () => {
17
+ it('throws an error', async () => {
18
+ const combinedOptions = {
19
+ author: 'sqren',
20
+ accessToken: 'foo',
21
+ repoOwner: 'backport-org',
22
+ repoName: 'backport-e2e',
23
+ };
24
+ await expect((0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).rejects.toThrowError('Please check your access token and make sure it is valid.\nConfig: /myHomeDir/.backport/config.json');
25
+ });
26
+ });
27
+ describe('is valid', () => {
28
+ it('returns the options', async () => {
29
+ const combinedOptions = {
30
+ author: 'sqren',
31
+ accessToken: devAccessToken,
32
+ repoOwner: 'backport-org',
33
+ repoName: 'backport-e2e',
34
+ };
35
+ expect(await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).toEqual({
36
+ authenticatedUsername: 'sqren',
37
+ branchLabelMapping: {
38
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
39
+ '^v7.9.0$': '7.x',
40
+ '^v8.0.0$': 'master',
41
+ },
42
+ historicalBranchLabelMappings: [
43
+ {
44
+ branchLabelMapping: {
45
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
46
+ '^v7.9.0$': '7.x',
47
+ '^v8.0.0$': 'master',
48
+ },
49
+ committedDate: '2020-08-15T10:33:06Z',
50
+ },
51
+ {
52
+ branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
53
+ committedDate: '2020-08-15T10:20:23Z',
54
+ },
55
+ {
56
+ branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
57
+ committedDate: '2020-08-15T10:17:57Z',
58
+ },
59
+ ],
60
+ sourceBranch: 'master',
61
+ targetBranchChoices: [
62
+ { checked: true, name: 'master' },
63
+ { checked: true, name: '7.x' },
64
+ '7.8',
65
+ ],
66
+ targetPRLabels: ['backport'],
67
+ repoOwner: 'backport-org',
68
+ repoName: 'backport-e2e',
69
+ });
70
+ });
71
+ });
72
+ });
73
+ describe('when `repoOwner` is fork', () => {
74
+ it('returns original repoOwner', async () => {
75
+ const combinedOptions = {
76
+ author: 'sqren',
77
+ accessToken: devAccessToken,
78
+ repoOwner: 'sqren',
79
+ repoName: 'backport-e2e',
80
+ };
81
+ const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
82
+ await expect(options.repoOwner).toEqual('backport-org');
83
+ });
84
+ });
85
+ describe('sourceBranch', () => {
86
+ describe('when no sourceBranch is specified', () => {
87
+ it('uses the default branch of the repo', async () => {
88
+ const combinedOptions = {
89
+ author: 'sqren',
90
+ accessToken: devAccessToken,
91
+ repoOwner: 'backport-org',
92
+ repoName: 'repo-with-non-standard-main-branch',
93
+ };
94
+ const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
95
+ await expect(options.sourceBranch).toEqual('my-custom-default-branch');
96
+ });
97
+ });
98
+ });
99
+ describe('when a branch named "backport"', () => {
100
+ describe('exists', () => {
101
+ it('shows a warning', async () => {
102
+ const combinedOptions = {
103
+ author: 'sqren',
104
+ accessToken: devAccessToken,
105
+ repoOwner: 'backport-org',
106
+ repoName: 'repo-with-branch-named-backport',
107
+ };
108
+ await expect(async () => {
109
+ await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
110
+ }).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
111
+ });
112
+ });
113
+ });
114
+ describe('when a backportrc.json config was deleted from repo', () => {
115
+ it('does not throw', async () => {
116
+ const combinedOptions = {
117
+ author: 'sqren',
118
+ accessToken: devAccessToken,
119
+ repoOwner: 'backport-org',
120
+ repoName: 'repo-with-backportrc-removed',
121
+ };
122
+ const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
123
+ expect(options).toEqual({
124
+ authenticatedUsername: 'sqren',
125
+ sourceBranch: 'main',
126
+ historicalBranchLabelMappings: [],
127
+ });
128
+ });
129
+ });
130
+ });
@@ -1,15 +1,16 @@
1
+ import { ConfigFileOptions } from '../../../../options/ConfigOptions';
1
2
  import { OptionsFromCliArgs } from '../../../../options/cliArgs';
2
- import { OptionsFromConfigFiles } from '../../../../options/config/config';
3
- import { PromiseReturnType } from '../../../../types/PromiseReturnType';
4
- export declare type OptionsFromGithub = PromiseReturnType<typeof getOptionsFromGithub>;
5
- export declare function getOptionsFromGithub(optionsFromConfigFiles: OptionsFromConfigFiles, optionsFromCliArgs: OptionsFromCliArgs): Promise<{
3
+ export declare type OptionsFromGithub = Awaited<ReturnType<typeof getOptionsFromGithub>>;
4
+ export declare function getOptionsFromGithub(optionsFromConfigFiles: ConfigFileOptions, optionsFromCliArgs: OptionsFromCliArgs): Promise<{
5
+ historicalBranchLabelMappings: {
6
+ branchLabelMapping: Record<string, string>;
7
+ committedDate: string;
8
+ }[];
6
9
  accessToken?: string | undefined;
7
10
  all?: boolean | undefined;
8
11
  assignees?: string[] | undefined;
9
12
  author?: string | undefined;
10
13
  autoAssign?: boolean | undefined;
11
- autoMerge?: boolean | undefined;
12
- autoMergeMethod?: string | undefined;
13
14
  autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
14
15
  files: string[];
15
16
  directory: string;
@@ -22,8 +23,12 @@ export declare function getOptionsFromGithub(optionsFromConfigFiles: OptionsFrom
22
23
  };
23
24
  targetBranch: string;
24
25
  }) => boolean | Promise<boolean>) | undefined;
25
- branchLabelMapping?: Record<string, string> | undefined;
26
+ autoMerge?: boolean | undefined;
27
+ autoMergeMethod?: string | undefined;
26
28
  ci?: boolean | undefined;
29
+ cherrypickRef?: boolean | undefined;
30
+ commitPaths?: string[] | undefined;
31
+ details?: boolean | undefined;
27
32
  editor?: string | undefined;
28
33
  forceLocalConfig?: boolean | undefined;
29
34
  fork?: boolean | undefined;
@@ -35,21 +40,24 @@ export declare function getOptionsFromGithub(optionsFromConfigFiles: OptionsFrom
35
40
  multipleBranches?: boolean | undefined;
36
41
  multipleCommits?: boolean | undefined;
37
42
  noVerify?: boolean | undefined;
38
- path?: string | undefined;
39
43
  prDescription?: string | undefined;
40
44
  prFilter?: string | undefined;
41
45
  prTitle?: string | undefined;
42
46
  pullNumber?: number | undefined;
47
+ repoOwner?: string | undefined;
48
+ repoName?: string | undefined;
43
49
  resetAuthor?: boolean | undefined;
50
+ reviewers?: string[] | undefined;
44
51
  sha?: string | undefined;
45
52
  sourceBranch: string;
46
53
  sourcePRLabels?: string[] | undefined;
47
- targetBranchChoices?: import("../../../../options/ConfigOptions").BranchChoiceRaw[] | undefined;
54
+ targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
48
55
  targetBranches?: string[] | undefined;
49
56
  targetPRLabels?: string[] | undefined;
50
- upstream?: string | undefined;
51
57
  username?: string | undefined;
52
58
  verbose?: boolean | undefined;
53
- branches?: import("../../../../options/ConfigOptions").BranchChoiceRaw[] | undefined;
59
+ branchLabelMapping?: Record<string, string> | undefined;
60
+ upstream?: string | undefined;
61
+ branches?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
54
62
  labels?: string[] | undefined;
55
63
  }>;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getOptionsFromGithub = void 0;
7
7
  const ora_1 = __importDefault(require("ora"));
8
8
  const parseRequiredOptions_1 = require("../../../../options/parseRequiredOptions");
9
+ const filterEmpty_1 = require("../../../../utils/filterEmpty");
9
10
  const HandledError_1 = require("../../../HandledError");
10
11
  const git_1 = require("../../../git");
11
12
  const logger_1 = require("../../../logger");
@@ -13,17 +14,16 @@ const apiRequestV4_1 = require("../apiRequestV4");
13
14
  const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
14
15
  const query_1 = require("./query");
15
16
  async function getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs) {
16
- var _a, _b, _c, _d, _e;
17
17
  const options = {
18
18
  ...optionsFromConfigFiles,
19
19
  ...optionsFromCliArgs,
20
20
  };
21
21
  const { githubApiBaseUrlV4 } = options;
22
- const { accessToken, repoName, repoOwner } = parseRequiredOptions_1.getRequiredOptions(options);
22
+ const { accessToken, repoName, repoOwner } = (0, parseRequiredOptions_1.getRequiredOptions)(options);
23
23
  let res;
24
- const spinner = ora_1.default().start('Initializing...');
24
+ const spinner = (0, ora_1.default)().start('Initializing...');
25
25
  try {
26
- res = await apiRequestV4_1.apiRequestV4({
26
+ res = await (0, apiRequestV4_1.apiRequestV4)({
27
27
  githubApiBaseUrlV4,
28
28
  accessToken,
29
29
  query: query_1.query,
@@ -35,31 +35,32 @@ async function getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs)
35
35
  catch (e) {
36
36
  spinner.stop();
37
37
  const error = e;
38
- throwOnInvalidAccessToken_1.throwOnInvalidAccessToken({
38
+ (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
39
39
  error,
40
40
  repoName,
41
41
  repoOwner,
42
42
  });
43
- const configFileNotFound = (_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data.errors) === null || _b === void 0 ? void 0 : _b.some((error) => error.type === 'NOT_FOUND' &&
43
+ const configFileNotFound = error.response?.data.errors?.some((error) => error.type === 'NOT_FOUND' &&
44
44
  error.path.join('.') ===
45
- 'repository.defaultBranchRef.target.jsonConfigFile.edges.0.config.file');
46
- if (configFileNotFound && ((_c = error.response) === null || _c === void 0 ? void 0 : _c.data.data)) {
45
+ 'repository.defaultBranchRef.target.history.edges.0.remoteConfig.file');
46
+ if (configFileNotFound && error.response?.data.data) {
47
47
  // swallow error if caused by missing config file on Github
48
48
  res = error.response.data.data;
49
49
  }
50
50
  else {
51
51
  // throw generic Github error
52
- throw apiRequestV4_1.handleGithubV4Error(error);
52
+ throw (0, apiRequestV4_1.handleGithubV4Error)(error);
53
53
  }
54
54
  }
55
55
  // get the original repo (not the fork)
56
56
  const repo = res.repository.isFork ? res.repository.parent : res.repository;
57
57
  // it is not possible to have a branch named "backport"
58
- if (((_d = repo.ref) === null || _d === void 0 ? void 0 : _d.name) === 'backport') {
58
+ if (repo.ref?.name === 'backport') {
59
59
  throw new HandledError_1.HandledError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
60
60
  }
61
- const remoteConfig = (_e = repo.defaultBranchRef.target.jsonConfigFile.edges[0]) === null || _e === void 0 ? void 0 : _e.config;
62
- const remoteConfigFile = await getRemoteConfigFile(options, remoteConfig);
61
+ const historicalRemoteConfigs = repo.defaultBranchRef.target.history.edges;
62
+ const latestRemoteConfig = historicalRemoteConfigs[0]?.remoteConfig;
63
+ const skipRemoteConfig = await getSkipRemoteConfigFile(options, latestRemoteConfig);
63
64
  const defaultBranch = repo.defaultBranchRef.name;
64
65
  // if no sourceBranch is given, use the `defaultBranch` (normally "master")
65
66
  const sourceBranch = options.sourceBranch
@@ -67,35 +68,44 @@ async function getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs)
67
68
  : defaultBranch;
68
69
  return {
69
70
  sourceBranch,
70
- ...remoteConfigFile,
71
+ ...(skipRemoteConfig ? {} : parseRemoteConfig(latestRemoteConfig)),
72
+ historicalBranchLabelMappings: skipRemoteConfig
73
+ ? []
74
+ : getHistoricalBranchLabelMappings(historicalRemoteConfigs),
71
75
  };
72
76
  }
73
77
  exports.getOptionsFromGithub = getOptionsFromGithub;
74
- async function getRemoteConfigFile(options, remoteConfig) {
78
+ async function getSkipRemoteConfigFile(options, remoteConfig) {
75
79
  if (options.forceLocalConfig) {
76
80
  logger_1.logger.info('Skipping remote config: `--force-local-config` specified via config file or cli');
77
- return;
81
+ return true;
78
82
  }
79
83
  if (!remoteConfig) {
80
84
  logger_1.logger.info("Skipping remote config: remote config doesn't exist");
81
- return;
85
+ return true;
82
86
  }
83
- const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate,] = await Promise.all([
84
- git_1.isLocalConfigFileModified(),
85
- git_1.isLocalConfigFileUntracked(),
86
- git_1.getLocalConfigFileCommitDate(),
87
+ const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
88
+ (0, git_1.isLocalConfigFileModified)(),
89
+ (0, git_1.isLocalConfigFileUntracked)(),
90
+ (0, git_1.getLocalConfigFileCommitDate)(),
87
91
  ]);
88
92
  if (isLocalConfigUntracked) {
89
93
  logger_1.logger.info('Skipping remote config: local config is new');
90
- return;
94
+ return true;
91
95
  }
92
96
  if (isLocalConfigModified) {
93
97
  logger_1.logger.info('Skipping remote config: local config is modified');
94
- return;
98
+ return true;
95
99
  }
96
100
  if (localCommitDate &&
97
101
  localCommitDate > Date.parse(remoteConfig.committedDate)) {
98
102
  logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
103
+ return true;
104
+ }
105
+ return false;
106
+ }
107
+ function parseRemoteConfig(remoteConfig) {
108
+ if (!remoteConfig) {
99
109
  return;
100
110
  }
101
111
  try {
@@ -107,3 +117,23 @@ async function getRemoteConfigFile(options, remoteConfig) {
107
117
  return;
108
118
  }
109
119
  }
120
+ function getHistoricalBranchLabelMappings(historicalRemoteConfigs) {
121
+ return historicalRemoteConfigs
122
+ .map((edge) => {
123
+ try {
124
+ const remoteConfig = JSON.parse(edge.remoteConfig.file.object.text);
125
+ if (!remoteConfig.branchLabelMapping) {
126
+ return;
127
+ }
128
+ return {
129
+ branchLabelMapping: remoteConfig.branchLabelMapping,
130
+ committedDate: edge.remoteConfig.committedDate,
131
+ };
132
+ }
133
+ catch (e) {
134
+ logger_1.logger.info('Could not get historical remote config', e);
135
+ return;
136
+ }
137
+ })
138
+ .filter(filterEmpty_1.filterNil);
139
+ }
@@ -1,11 +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 });
6
+ const os_1 = __importDefault(require("os"));
3
7
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
8
  const _1 = require(".");
5
9
  describe('getOptionsFromGithub', () => {
6
10
  let devAccessToken;
7
11
  beforeAll(async () => {
8
- devAccessToken = await getDevAccessToken_1.getDevAccessToken();
12
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
13
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
9
14
  });
10
15
  describe('access token', () => {
11
16
  describe('is invalid', () => {
@@ -17,7 +22,7 @@ describe('getOptionsFromGithub', () => {
17
22
  upstream: 'backport-org/backport-e2e',
18
23
  };
19
24
  const optionsFromCliArgs = {};
20
- await expect(_1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs)).rejects.toThrowError('Please check your access token and make sure it is valid.\nConfig: /myHomeDir/.backport/config.json');
25
+ await expect((0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs)).rejects.toThrowError('Please check your access token and make sure it is valid.\nConfig: /myHomeDir/.backport/config.json');
21
26
  });
22
27
  });
23
28
  describe('is valid', () => {
@@ -29,12 +34,30 @@ describe('getOptionsFromGithub', () => {
29
34
  upstream: 'backport-org/backport-e2e',
30
35
  };
31
36
  const optionsFromCliArgs = {};
32
- expect(await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs)).toEqual({
37
+ expect(await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs)).toEqual({
33
38
  branchLabelMapping: {
34
39
  '^v(\\d+).(\\d+).\\d+$': '$1.$2',
35
40
  '^v7.9.0$': '7.x',
36
41
  '^v8.0.0$': 'master',
37
42
  },
43
+ historicalBranchLabelMappings: [
44
+ {
45
+ branchLabelMapping: {
46
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
47
+ '^v7.9.0$': '7.x',
48
+ '^v8.0.0$': 'master',
49
+ },
50
+ committedDate: '2020-08-15T10:33:06Z',
51
+ },
52
+ {
53
+ branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
54
+ committedDate: '2020-08-15T10:20:23Z',
55
+ },
56
+ {
57
+ branchLabelMapping: { '6.1': '6.1', '6.3': '6.3' },
58
+ committedDate: '2020-08-15T10:17:57Z',
59
+ },
60
+ ],
38
61
  sourceBranch: 'master',
39
62
  targetBranchChoices: [
40
63
  { checked: true, name: 'master' },
@@ -56,7 +79,7 @@ describe('getOptionsFromGithub', () => {
56
79
  upstream: 'sqren/backport-e2e',
57
80
  };
58
81
  const optionsFromCliArgs = {};
59
- const options = await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs);
82
+ const options = await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
60
83
  await expect(options.upstream).toEqual('backport-org/backport-e2e');
61
84
  });
62
85
  });
@@ -70,7 +93,7 @@ describe('getOptionsFromGithub', () => {
70
93
  upstream: 'backport-org/repo-with-non-standard-main-branch',
71
94
  };
72
95
  const optionsFromCliArgs = {};
73
- const options = await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs);
96
+ const options = await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
74
97
  await expect(options.sourceBranch).toEqual('my-custom-default-branch');
75
98
  });
76
99
  });
@@ -84,7 +107,7 @@ describe('getOptionsFromGithub', () => {
84
107
  upstream: 'backport-org/repo-with-non-standard-main-branch',
85
108
  };
86
109
  const optionsFromCliArgs = {};
87
- const options = await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs);
110
+ const options = await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
88
111
  await expect(options.sourceBranch).toEqual('my-specific-source-branch');
89
112
  });
90
113
  });
@@ -100,9 +123,25 @@ describe('getOptionsFromGithub', () => {
100
123
  };
101
124
  const optionsFromCliArgs = {};
102
125
  await expect(async () => {
103
- await _1.getOptionsFromGithub(optionsFromConfigFiles, optionsFromCliArgs);
126
+ await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
104
127
  }).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
105
128
  });
106
129
  });
107
130
  });
131
+ describe('when a backportrc.json config was deleted from repo', () => {
132
+ it('does not throw', async () => {
133
+ const optionsFromConfigFiles = {
134
+ username: 'sqren',
135
+ accessToken: devAccessToken,
136
+ githubApiBaseUrlV4: 'https://api.github.com/graphql',
137
+ upstream: 'backport-org/repo-with-backportrc-removed',
138
+ };
139
+ const optionsFromCliArgs = {};
140
+ const options = await (0, _1.getOptionsFromGithub)(optionsFromConfigFiles, optionsFromCliArgs);
141
+ expect(options).toEqual({
142
+ sourceBranch: 'main',
143
+ historicalBranchLabelMappings: [],
144
+ });
145
+ });
146
+ });
108
147
  });