backport 8.0.0 → 8.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 (205) hide show
  1. package/README.md +4 -4
  2. package/dist/backportRun.d.ts +5 -4
  3. package/dist/backportRun.js +41 -42
  4. package/dist/entrypoint.cli.js +3 -7
  5. package/dist/entrypoint.module.d.ts +7 -5
  6. package/dist/entrypoint.module.js +11 -9
  7. package/dist/entrypoint.module.private.test.js +4 -4
  8. package/dist/errors/BackportError.d.ts +19 -0
  9. package/dist/errors/BackportError.js +29 -0
  10. package/dist/lib/BackportError.d.ts +19 -0
  11. package/dist/lib/BackportError.js +29 -0
  12. package/dist/lib/cherrypickAndCreateTargetPullRequest.d.ts +13 -0
  13. package/dist/lib/cherrypickAndCreateTargetPullRequest.js +238 -0
  14. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.d.ts +1 -0
  15. package/dist/lib/cherrypickAndCreateTargetPullRequest.test.js +321 -0
  16. package/dist/lib/child-process-promisified.d.ts +25 -0
  17. package/dist/lib/child-process-promisified.js +58 -0
  18. package/dist/lib/env.d.ts +7 -0
  19. package/dist/lib/env.js +33 -0
  20. package/dist/lib/env.test.d.ts +1 -0
  21. package/dist/lib/env.test.js +26 -0
  22. package/dist/lib/getCommits.d.ts +2 -0
  23. package/dist/lib/getCommits.js +75 -0
  24. package/dist/lib/getCommitsWithoutBackports.d.ts +11 -0
  25. package/dist/lib/getCommitsWithoutBackports.js +68 -0
  26. package/dist/lib/getCommitsWithoutBackports.test.d.ts +1 -0
  27. package/dist/lib/getCommitsWithoutBackports.test.js +335 -0
  28. package/dist/lib/getGitConfigAuthor.d.ts +6 -0
  29. package/dist/lib/getGitConfigAuthor.js +15 -0
  30. package/dist/lib/getTargetBranches.d.ts +5 -0
  31. package/dist/lib/getTargetBranches.js +67 -0
  32. package/dist/lib/getTargetBranches.test.d.ts +1 -0
  33. package/dist/lib/getTargetBranches.test.js +206 -0
  34. package/dist/lib/git.d.ts +77 -0
  35. package/dist/lib/git.js +439 -0
  36. package/dist/lib/git.private.test.d.ts +1 -0
  37. package/dist/lib/git.private.test.js +618 -0
  38. package/dist/lib/git.test.d.ts +1 -0
  39. package/dist/lib/git.test.js +580 -0
  40. package/dist/lib/github/commitFormatters.d.ts +3 -0
  41. package/dist/lib/github/commitFormatters.js +17 -0
  42. package/dist/lib/github/commitFormatters.test.d.ts +1 -0
  43. package/dist/lib/github/commitFormatters.test.js +11 -0
  44. package/dist/lib/github/v3/addAssigneesToPullRequest.d.ts +2 -0
  45. package/dist/lib/github/v3/addAssigneesToPullRequest.js +32 -0
  46. package/dist/lib/github/v3/addAssigneesToPullRequest.test.d.ts +1 -0
  47. package/dist/lib/github/v3/addAssigneesToPullRequest.test.js +27 -0
  48. package/dist/lib/github/v3/addLabelsToPullRequest.d.ts +2 -0
  49. package/dist/lib/github/v3/addLabelsToPullRequest.js +30 -0
  50. package/dist/lib/github/v3/addReviewersToPullRequest.d.ts +2 -0
  51. package/dist/lib/github/v3/addReviewersToPullRequest.js +32 -0
  52. package/dist/lib/github/v3/createPullRequest.d.ts +29 -0
  53. package/dist/lib/github/v3/createPullRequest.js +91 -0
  54. package/dist/lib/github/v3/createPullRequest.test.d.ts +1 -0
  55. package/dist/lib/github/v3/createPullRequest.test.js +377 -0
  56. package/dist/lib/github/v3/createStatusComment.d.ts +11 -0
  57. package/dist/lib/github/v3/createStatusComment.js +136 -0
  58. package/dist/lib/github/v3/createStatusComment.test.d.ts +1 -0
  59. package/dist/lib/github/v3/createStatusComment.test.js +461 -0
  60. package/dist/lib/github/v3/getGithubV3ErrorMessage.d.ts +14 -0
  61. package/dist/lib/github/v3/getGithubV3ErrorMessage.js +16 -0
  62. package/dist/lib/github/v4/FetchPullRequestId.d.ts +2 -0
  63. package/dist/lib/github/v4/FetchPullRequestId.js +36 -0
  64. package/dist/lib/github/v4/apiRequestV4.d.ts +31 -0
  65. package/dist/lib/github/v4/apiRequestV4.js +71 -0
  66. package/dist/lib/github/v4/apiRequestV4.test.d.ts +1 -0
  67. package/dist/lib/github/v4/apiRequestV4.test.js +109 -0
  68. package/dist/lib/github/v4/disablePullRequestAutoMerge.d.ts +2 -0
  69. package/dist/lib/github/v4/disablePullRequestAutoMerge.js +32 -0
  70. package/dist/lib/github/v4/enablePullRequestAutoMerge.d.ts +2 -0
  71. package/dist/lib/github/v4/enablePullRequestAutoMerge.js +50 -0
  72. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.d.ts +1 -0
  73. package/dist/lib/github/v4/enablePullRequestAutoMerge.private.test.js +112 -0
  74. package/dist/lib/github/v4/fetchAuthorId.d.ts +10 -0
  75. package/dist/lib/github/v4/fetchAuthorId.js +28 -0
  76. package/dist/lib/github/v4/fetchAuthorId.private.test.d.ts +1 -0
  77. package/dist/lib/github/v4/fetchAuthorId.private.test.js +25 -0
  78. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  79. package/dist/lib/github/v4/fetchCommits/allFetchers.private.test.js +93 -0
  80. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +11 -0
  81. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.js +58 -0
  82. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +1 -0
  83. package/dist/lib/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +136 -0
  84. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.d.ts +11 -0
  85. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.js +48 -0
  86. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +1 -0
  87. package/dist/lib/github/v4/fetchCommits/fetchCommitBySha.private.test.js +118 -0
  88. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +29 -0
  89. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.js +110 -0
  90. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +1 -0
  91. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +196 -0
  92. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +1 -0
  93. package/dist/lib/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +157 -0
  94. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +1 -0
  95. package/dist/lib/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +107 -0
  96. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.d.ts +12 -0
  97. package/dist/lib/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +69 -0
  98. package/dist/lib/github/v4/fetchExistingPullRequest.d.ts +9 -0
  99. package/dist/lib/github/v4/fetchExistingPullRequest.js +64 -0
  100. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.d.ts +1 -0
  101. package/dist/lib/github/v4/fetchExistingPullRequest.private.test.js +44 -0
  102. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.d.ts +2 -0
  103. package/dist/lib/github/v4/fetchPullRequestAutoMergeMethod.js +39 -0
  104. package/dist/lib/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  105. package/dist/lib/github/v4/fetchRemoteProjectConfig.js +49 -0
  106. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  107. package/dist/lib/github/v4/fetchRemoteProjectConfig.private.test.js +49 -0
  108. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +72 -0
  109. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +78 -0
  110. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +1 -0
  111. package/dist/lib/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +116 -0
  112. package/dist/lib/github/v4/getOptionsFromGithub/query.d.ts +16 -0
  113. package/dist/lib/github/v4/getOptionsFromGithub/query.js +29 -0
  114. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.d.ts +29 -0
  115. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.js +61 -0
  116. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +1 -0
  117. package/dist/lib/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +72 -0
  118. package/dist/lib/github/v4/mocks/commitsByAuthorMock.d.ts +2 -0
  119. package/dist/lib/github/v4/mocks/commitsByAuthorMock.js +176 -0
  120. package/dist/lib/github/v4/throwOnInvalidAccessToken.d.ts +7 -0
  121. package/dist/lib/github/v4/throwOnInvalidAccessToken.js +45 -0
  122. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.d.ts +1 -0
  123. package/dist/lib/github/v4/throwOnInvalidAccessToken.test.js +87 -0
  124. package/dist/lib/logger.d.ts +9 -0
  125. package/dist/lib/logger.js +74 -0
  126. package/dist/lib/ora.d.ts +2 -0
  127. package/dist/lib/ora.js +21 -0
  128. package/dist/lib/prompt.test.d.ts +1 -0
  129. package/dist/lib/prompt.test.js +139 -0
  130. package/dist/lib/prompts.d.ts +17 -0
  131. package/dist/lib/prompts.js +132 -0
  132. package/dist/lib/remoteConfig.d.ts +20 -0
  133. package/dist/lib/remoteConfig.js +52 -0
  134. package/dist/lib/sequentially.d.ts +1 -0
  135. package/dist/lib/sequentially.js +10 -0
  136. package/dist/lib/setupRepo.d.ts +2 -0
  137. package/dist/lib/setupRepo.js +56 -0
  138. package/dist/lib/setupRepo.test.d.ts +1 -0
  139. package/dist/lib/setupRepo.test.js +278 -0
  140. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.d.ts +16 -0
  141. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.js +102 -0
  142. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.d.ts +1 -0
  143. package/dist/lib/sourceCommit/getExpectedTargetPullRequests.test.js +467 -0
  144. package/dist/lib/sourceCommit/getMockSourceCommit.d.ts +26 -0
  145. package/dist/lib/sourceCommit/getMockSourceCommit.js +103 -0
  146. package/dist/lib/sourceCommit/parseSourceCommit.d.ts +108 -0
  147. package/dist/lib/sourceCommit/parseSourceCommit.js +123 -0
  148. package/dist/lib/sourceCommit/parseSourceCommit.test.d.ts +1 -0
  149. package/dist/lib/sourceCommit/parseSourceCommit.test.js +226 -0
  150. package/dist/options/ConfigOptions.d.ts +4 -2
  151. package/dist/options/cliArgs.d.ts +15 -12
  152. package/dist/options/cliArgs.js +34 -19
  153. package/dist/options/cliArgs.test.js +125 -1
  154. package/dist/options/config/config.d.ts +5 -4
  155. package/dist/options/config/config.js +3 -5
  156. package/dist/options/config/config.test.js +0 -1
  157. package/dist/options/config/globalConfig.d.ts +3 -1
  158. package/dist/options/config/globalConfig.js +5 -5
  159. package/dist/options/config/readConfigFile.d.ts +9 -7
  160. package/dist/options/config/readConfigFile.js +2 -2
  161. package/dist/options/options.d.ts +43 -7
  162. package/dist/options/options.js +20 -24
  163. package/dist/options/options.test.js +112 -54
  164. package/dist/runSequentially.d.ts +10 -7
  165. package/dist/runSequentially.js +5 -5
  166. package/dist/scripts/postinstall.js +3 -3
  167. package/dist/scripts/postinstall.test.js +1 -1
  168. package/dist/services/BackportError.d.ts +19 -0
  169. package/dist/services/BackportError.js +29 -0
  170. package/dist/services/HandledBackportError.d.ts +19 -0
  171. package/dist/services/HandledBackportError.js +29 -0
  172. package/dist/services/HandledError.d.ts +1 -1
  173. package/dist/services/HandledError.js +5 -5
  174. package/dist/services/git.js +7 -7
  175. package/dist/services/github/v3/createPullRequest.js +2 -2
  176. package/dist/services/github/v3/createStatusComment.js +2 -2
  177. package/dist/services/github/v3/createStatusComment.test.js +5 -4
  178. package/dist/services/github/v4/apiRequestV4.js +2 -2
  179. package/dist/services/github/v4/apiRequestV4.test.js +2 -2
  180. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +3 -3
  181. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  182. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +3 -3
  183. package/dist/services/github/v4/fetchCommits/fetchPullRequestsBySearchQuery.js +2 -2
  184. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +2 -2
  185. package/dist/services/github/v4/throwOnInvalidAccessToken.js +5 -5
  186. package/dist/state.d.ts +0 -0
  187. package/dist/state.js +1 -0
  188. package/dist/test/e2e/cli/commit-author.private.test.js +4 -4
  189. package/dist/test/e2e/cli/different-merge-strategies.private.test.js +26 -24
  190. package/dist/test/e2e/cli/entrypoint.cli.private.test.js +189 -140
  191. package/dist/test/e2e/cli/repo-with-backportrc-removed.private.test.js +12 -14
  192. package/dist/test/e2e/cli/runBackportViaCli.d.ts +5 -2
  193. package/dist/test/e2e/cli/runBackportViaCli.js +42 -29
  194. package/dist/test/e2e/cli/test-that-repo-can-be-cloned.private.test.js +22 -14
  195. package/dist/test/e2e/module/entrypoint.module.mutation.test.js +2 -2
  196. package/dist/test/handleUnbackportedPullRequests.private.test.js +3 -2
  197. package/dist/test/setupFiles/automatic-mocks.js +1 -1
  198. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -3
  199. package/dist/ui/getCommits.js +2 -2
  200. package/dist/ui/getTargetBranches.js +3 -3
  201. package/dist/ui/setupRepo.js +2 -2
  202. package/dist/utils/packageVersion.d.ts +1 -1
  203. package/dist/utils/packageVersion.js +1 -1
  204. package/package.json +12 -12
  205. package/yarn.lock +112 -65
@@ -0,0 +1,72 @@
1
+ export declare type OptionsFromGithub = Awaited<ReturnType<typeof getOptionsFromGithub>>;
2
+ export declare function getOptionsFromGithub(options: {
3
+ accessToken: string;
4
+ cwd?: string;
5
+ githubApiBaseUrlV4?: string;
6
+ repoName: string;
7
+ repoOwner: string;
8
+ skipRemoteConfig?: boolean;
9
+ globalConfigFile?: string;
10
+ }): Promise<{
11
+ accessToken?: string | undefined;
12
+ assignees?: string[] | undefined;
13
+ author?: string | null | undefined;
14
+ autoAssign?: boolean | undefined;
15
+ autoFixConflicts?: (({ files, directory, logger, targetBranch, }: {
16
+ files: string[];
17
+ directory: string;
18
+ logger: import("winston").Logger;
19
+ targetBranch: string;
20
+ }) => boolean | Promise<boolean>) | undefined;
21
+ autoMerge?: boolean | undefined;
22
+ autoMergeMethod?: string | undefined;
23
+ backportBinary?: string | undefined;
24
+ cherrypickRef?: boolean | undefined;
25
+ commitPaths?: string[] | undefined;
26
+ details?: boolean | undefined;
27
+ dir?: string | undefined;
28
+ dryRun?: boolean | undefined;
29
+ editor?: string | undefined;
30
+ fork?: boolean | undefined;
31
+ gitAuthorEmail?: string | undefined;
32
+ gitAuthorName?: string | undefined;
33
+ gitHostname?: string | undefined;
34
+ githubApiBaseUrlV3?: string | undefined;
35
+ githubApiBaseUrlV4?: string | undefined;
36
+ interactive?: boolean | undefined;
37
+ logFilePath?: string | undefined;
38
+ ls?: boolean | undefined;
39
+ maxNumber?: number | undefined;
40
+ multiple?: boolean | undefined;
41
+ multipleBranches?: boolean | undefined;
42
+ multipleCommits?: boolean | undefined;
43
+ noVerify?: boolean | undefined;
44
+ prDescription?: string | undefined;
45
+ prFilter?: string | undefined;
46
+ projectConfigFile?: string | undefined;
47
+ prTitle?: string | undefined;
48
+ publishStatusCommentOnAbort?: boolean | undefined;
49
+ publishStatusCommentOnFailure?: boolean | undefined;
50
+ publishStatusCommentOnSuccess?: boolean | undefined;
51
+ pullNumber?: number | undefined;
52
+ repoForkOwner?: string | undefined;
53
+ repoName?: string | undefined;
54
+ repoOwner?: string | undefined;
55
+ resetAuthor?: boolean | undefined;
56
+ reviewers?: string[] | undefined;
57
+ sha?: string | string[] | undefined;
58
+ skipRemoteConfig?: boolean | undefined;
59
+ sourceBranch: string;
60
+ sourcePRLabels?: string[] | undefined;
61
+ targetBranchChoices?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
62
+ targetBranches?: string[] | undefined;
63
+ targetPRLabels?: string[] | undefined;
64
+ help?: boolean | undefined;
65
+ version?: boolean | undefined;
66
+ v?: boolean | undefined;
67
+ branchLabelMapping?: Record<string, string> | undefined;
68
+ upstream?: string | undefined;
69
+ branches?: import("../../../../options/ConfigOptions").TargetBranchChoiceOrString[] | undefined;
70
+ labels?: string[] | undefined;
71
+ authenticatedUsername: string;
72
+ }>;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOptionsFromGithub = void 0;
4
+ const BackportError_1 = require("../../../BackportError");
5
+ const git_1 = require("../../../git");
6
+ const logger_1 = require("../../../logger");
7
+ const remoteConfig_1 = require("../../../remoteConfig");
8
+ const apiRequestV4_1 = require("../apiRequestV4");
9
+ const throwOnInvalidAccessToken_1 = require("../throwOnInvalidAccessToken");
10
+ const query_1 = require("./query");
11
+ async function getOptionsFromGithub(options) {
12
+ const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, globalConfigFile, } = options;
13
+ let res;
14
+ try {
15
+ res = await (0, apiRequestV4_1.apiRequestV4)({
16
+ githubApiBaseUrlV4,
17
+ accessToken,
18
+ query: query_1.query,
19
+ variables: { repoOwner, repoName },
20
+ });
21
+ }
22
+ catch (e) {
23
+ if (!(e instanceof apiRequestV4_1.GithubV4Exception)) {
24
+ throw e;
25
+ }
26
+ (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
27
+ error: e,
28
+ repoName,
29
+ repoOwner,
30
+ globalConfigFile,
31
+ });
32
+ res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
33
+ }
34
+ // it is not possible to have a branch named "backport"
35
+ if (res.repository.illegalBackportBranch) {
36
+ throw new BackportError_1.BackportError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
37
+ }
38
+ const remoteConfig = await getRemoteConfigFileOptions(res, options.cwd, options.skipRemoteConfig);
39
+ return {
40
+ authenticatedUsername: res.viewer.login,
41
+ sourceBranch: res.repository.defaultBranchRef.name,
42
+ ...remoteConfig,
43
+ };
44
+ }
45
+ exports.getOptionsFromGithub = getOptionsFromGithub;
46
+ async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
47
+ if (skipRemoteConfig) {
48
+ logger_1.logger.info('Skipping remote config: `--skip-remote-config` specified via config file or cli');
49
+ return;
50
+ }
51
+ const remoteConfig = res.repository.defaultBranchRef.target.remoteConfigHistory.edges?.[0]
52
+ ?.remoteConfig;
53
+ if (!remoteConfig) {
54
+ logger_1.logger.info("Skipping remote config: remote config doesn't exist");
55
+ return;
56
+ }
57
+ if (cwd) {
58
+ const [isLocalConfigModified, isLocalConfigUntracked, localCommitDate] = await Promise.all([
59
+ (0, git_1.isLocalConfigFileModified)({ cwd }),
60
+ (0, git_1.isLocalConfigFileUntracked)({ cwd }),
61
+ (0, git_1.getLocalConfigFileCommitDate)({ cwd }),
62
+ ]);
63
+ if (isLocalConfigUntracked) {
64
+ logger_1.logger.info('Skipping remote config: local config is new');
65
+ return;
66
+ }
67
+ if (isLocalConfigModified) {
68
+ logger_1.logger.info('Skipping remote config: local config is modified');
69
+ return;
70
+ }
71
+ if (localCommitDate &&
72
+ localCommitDate > Date.parse(remoteConfig.committedDate)) {
73
+ logger_1.logger.info(`Skipping remote config: local config is newer: ${new Date(localCommitDate).toISOString()} > ${remoteConfig.committedDate}`);
74
+ return;
75
+ }
76
+ }
77
+ return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
78
+ }
@@ -0,0 +1,116 @@
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
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
10
+ describe('getOptionsFromGithub', () => {
11
+ beforeAll(async () => {
12
+ jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir');
13
+ });
14
+ describe('access token', () => {
15
+ describe('is invalid', () => {
16
+ it('throws an error', async () => {
17
+ const combinedOptions = {
18
+ author: 'sqren',
19
+ accessToken: 'foo',
20
+ repoOwner: 'backport-org',
21
+ repoName: 'backport-e2e',
22
+ cwd: process.cwd(),
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,
32
+ repoOwner: 'backport-org',
33
+ repoName: 'backport-e2e',
34
+ cwd: process.cwd(),
35
+ };
36
+ expect(await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions)).toEqual({
37
+ authenticatedUsername: 'sqren',
38
+ branchLabelMapping: {
39
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
40
+ '^v7.9.0$': '7.x',
41
+ '^v8.0.0$': 'master',
42
+ },
43
+ sourceBranch: 'master',
44
+ targetBranchChoices: [
45
+ { checked: true, name: 'master' },
46
+ { checked: true, name: '7.x' },
47
+ '7.8',
48
+ ],
49
+ targetPRLabels: ['backport'],
50
+ repoOwner: 'backport-org',
51
+ repoName: 'backport-e2e',
52
+ });
53
+ });
54
+ });
55
+ });
56
+ describe('when `repoOwner` is fork', () => {
57
+ it('returns original repoOwner', async () => {
58
+ const combinedOptions = {
59
+ author: 'sqren',
60
+ accessToken,
61
+ repoOwner: 'sqren',
62
+ repoName: 'backport-e2e',
63
+ cwd: process.cwd(),
64
+ };
65
+ const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
66
+ await expect(options.repoOwner).toEqual('backport-org');
67
+ });
68
+ });
69
+ describe('sourceBranch', () => {
70
+ describe('when no sourceBranch is specified', () => {
71
+ it('uses the default branch of the repo', async () => {
72
+ const combinedOptions = {
73
+ author: 'sqren',
74
+ accessToken,
75
+ repoOwner: 'backport-org',
76
+ repoName: 'repo-with-non-standard-main-branch',
77
+ cwd: process.cwd(),
78
+ };
79
+ const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
80
+ await expect(options.sourceBranch).toEqual('my-custom-default-branch');
81
+ });
82
+ });
83
+ });
84
+ describe('when a branch named "backport"', () => {
85
+ describe('exists', () => {
86
+ it('shows a warning', async () => {
87
+ const combinedOptions = {
88
+ author: 'sqren',
89
+ accessToken,
90
+ repoOwner: 'backport-org',
91
+ repoName: 'repo-with-branch-named-backport',
92
+ cwd: process.cwd(),
93
+ };
94
+ await expect(async () => {
95
+ await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
96
+ }).rejects.toThrowError('You must delete the branch "backport" to continue. See https://github.com/sqren/backport/issues/155 for details');
97
+ });
98
+ });
99
+ });
100
+ describe('when a backportrc.json config was deleted from repo', () => {
101
+ it('does not throw', async () => {
102
+ const combinedOptions = {
103
+ author: 'sqren',
104
+ accessToken,
105
+ repoOwner: 'backport-org',
106
+ repoName: 'repo-with-backportrc-removed',
107
+ cwd: process.cwd(),
108
+ };
109
+ const options = await (0, getOptionsFromGithub_1.getOptionsFromGithub)(combinedOptions);
110
+ expect(options).toEqual({
111
+ authenticatedUsername: 'sqren',
112
+ sourceBranch: 'main',
113
+ });
114
+ });
115
+ });
116
+ });
@@ -0,0 +1,16 @@
1
+ import { RemoteConfigHistory } from '../../../remoteConfig';
2
+ export interface GithubConfigOptionsResponse {
3
+ viewer: {
4
+ login: string;
5
+ };
6
+ repository: {
7
+ illegalBackportBranch: {
8
+ id: string;
9
+ } | null;
10
+ defaultBranchRef: {
11
+ name: string;
12
+ target: RemoteConfigHistory;
13
+ };
14
+ };
15
+ }
16
+ export declare const query: import("graphql").DocumentNode;
@@ -0,0 +1,29 @@
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.query = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const remoteConfig_1 = require("../../../remoteConfig");
9
+ exports.query = (0, graphql_tag_1.default) `
10
+ query GithubConfigOptions($repoOwner: String!, $repoName: String!) {
11
+ viewer {
12
+ login
13
+ }
14
+ repository(owner: $repoOwner, name: $repoName) {
15
+ # check to see if a branch named "backport" exists
16
+ illegalBackportBranch: ref(qualifiedName: "refs/heads/backport") {
17
+ id
18
+ }
19
+ defaultBranchRef {
20
+ name
21
+ target {
22
+ ...RemoteConfigHistoryFragment
23
+ }
24
+ }
25
+ }
26
+ }
27
+
28
+ ${remoteConfig_1.RemoteConfigHistoryFragment}
29
+ `;
@@ -0,0 +1,29 @@
1
+ export declare function getRepoOwnerAndNameFromGitRemotes({ accessToken, githubApiBaseUrlV4, cwd, }: {
2
+ accessToken: string;
3
+ githubApiBaseUrlV4?: string;
4
+ cwd: string;
5
+ }): Promise<{
6
+ repoOwner?: string;
7
+ repoName?: string;
8
+ }>;
9
+ export interface RepoOwnerAndNameResponse {
10
+ repository: {
11
+ isFork: true;
12
+ name: string;
13
+ owner: {
14
+ login: string;
15
+ };
16
+ parent: {
17
+ owner: {
18
+ login: string;
19
+ };
20
+ };
21
+ } | {
22
+ isFork: false;
23
+ name: string;
24
+ owner: {
25
+ login: string;
26
+ };
27
+ parent: null;
28
+ };
29
+ }
@@ -0,0 +1,61 @@
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.getRepoOwnerAndNameFromGitRemotes = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const maybe_1 = require("../../../utils/maybe");
9
+ const git_1 = require("../../git");
10
+ const logger_1 = require("../../logger");
11
+ const apiRequestV4_1 = require("./apiRequestV4");
12
+ // This method should be used to get the origin owner (instead of a fork owner)
13
+ async function getRepoOwnerAndNameFromGitRemotes({ accessToken, githubApiBaseUrlV4, cwd, }) {
14
+ const remotes = await (0, git_1.getRepoInfoFromGitRemotes)({ cwd });
15
+ const firstRemote = (0, maybe_1.maybe)(remotes[0]);
16
+ if (!firstRemote) {
17
+ return {};
18
+ }
19
+ try {
20
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
21
+ githubApiBaseUrlV4,
22
+ accessToken,
23
+ query,
24
+ variables: {
25
+ repoOwner: firstRemote.repoOwner,
26
+ repoName: firstRemote.repoName,
27
+ },
28
+ });
29
+ return {
30
+ repoName: res.repository.name,
31
+ // get the original owner (not the fork owner)
32
+ repoOwner: res.repository.isFork
33
+ ? res.repository.parent.owner.login
34
+ : res.repository.owner.login,
35
+ };
36
+ }
37
+ catch (e) {
38
+ if (e instanceof apiRequestV4_1.GithubV4Exception) {
39
+ logger_1.logger.error(e.message);
40
+ return {};
41
+ }
42
+ throw e;
43
+ }
44
+ }
45
+ exports.getRepoOwnerAndNameFromGitRemotes = getRepoOwnerAndNameFromGitRemotes;
46
+ const query = (0, graphql_tag_1.default) `
47
+ query RepoOwnerAndName($repoOwner: String!, $repoName: String!) {
48
+ repository(owner: $repoOwner, name: $repoName) {
49
+ isFork
50
+ name
51
+ owner {
52
+ login
53
+ }
54
+ parent {
55
+ owner {
56
+ login
57
+ }
58
+ }
59
+ }
60
+ }
61
+ `;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
27
+ const sandbox_1 = require("../../../test/sandbox");
28
+ const childProcess = __importStar(require("../../child-process-promisified"));
29
+ const getRepoOwnerAndNameFromGitRemotes_1 = require("./getRepoOwnerAndNameFromGitRemotes");
30
+ const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename });
31
+ const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
32
+ describe('fetchRemoteProjectConfig', () => {
33
+ describe('when the remote is a fork', () => {
34
+ it('retrives the original owner from github', async () => {
35
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
36
+ const execOpts = { cwd: sandboxPath };
37
+ await childProcess.exec(`git init`, execOpts);
38
+ await childProcess.exec(`git remote add sqren git@github.com:sqren/kibana.git`, execOpts);
39
+ expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
40
+ accessToken,
41
+ cwd: sandboxPath,
42
+ })).toEqual({
43
+ repoName: 'kibana',
44
+ repoOwner: 'elastic',
45
+ });
46
+ });
47
+ });
48
+ describe('when none of the git remotes are found', () => {
49
+ it('swallows the error and returns empty', async () => {
50
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
51
+ const execOpts = { cwd: sandboxPath };
52
+ await childProcess.exec(`git init`, execOpts);
53
+ await childProcess.exec(`git remote add foo git@github.com:foo/kibana.git`, execOpts);
54
+ await childProcess.exec(`git remote add bar git@github.com:bar/kibana.git`, execOpts);
55
+ expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
56
+ accessToken,
57
+ cwd: sandboxPath,
58
+ })).toEqual({});
59
+ });
60
+ });
61
+ describe('when there are no git remotes', () => {
62
+ it('returns empty', async () => {
63
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
64
+ const execOpts = { cwd: sandboxPath };
65
+ await childProcess.exec(`git init`, execOpts);
66
+ expect(await (0, getRepoOwnerAndNameFromGitRemotes_1.getRepoOwnerAndNameFromGitRemotes)({
67
+ accessToken,
68
+ cwd: sandboxPath,
69
+ })).toEqual({});
70
+ });
71
+ });
72
+ });
@@ -0,0 +1,2 @@
1
+ import { CommitByAuthorResponse } from '../fetchCommits/fetchCommitsByAuthor';
2
+ export declare const commitsByAuthorMock: CommitByAuthorResponse;
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.commitsByAuthorMock = void 0;
4
+ exports.commitsByAuthorMock = {
5
+ repository: {
6
+ ref: {
7
+ target: {
8
+ history: {
9
+ edges: [
10
+ {
11
+ node: {
12
+ author: {
13
+ email: 'soren.louv@elastic.co',
14
+ name: 'Søren Louv-Jansen',
15
+ },
16
+ repository: {
17
+ name: 'kibana',
18
+ owner: { login: 'elastic' },
19
+ },
20
+ committedDate: '2021-12-24T00:00:00Z',
21
+ sha: '2e63475c483f7844b0f2833bc57fdee32095bacb',
22
+ message: 'Add 👻',
23
+ associatedPullRequests: {
24
+ edges: [],
25
+ },
26
+ },
27
+ },
28
+ {
29
+ node: {
30
+ author: {
31
+ email: 'soren.louv@elastic.co',
32
+ name: 'Søren Louv-Jansen',
33
+ },
34
+ repository: {
35
+ name: 'kibana',
36
+ owner: { login: 'elastic' },
37
+ },
38
+ committedDate: '2021-12-23T00:00:00Z',
39
+ sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
40
+ message: 'Add witch (#85)',
41
+ associatedPullRequests: {
42
+ edges: [
43
+ {
44
+ node: {
45
+ url: 'https://github.com/elastic/kibana/pull/85',
46
+ baseRefName: 'master',
47
+ labels: {
48
+ nodes: [{ name: 'my-label-b' }],
49
+ },
50
+ number: 85,
51
+ mergeCommit: {
52
+ remoteConfigHistory: { edges: [] },
53
+ sha: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
54
+ message: 'Add witch (#85)',
55
+ },
56
+ timelineItems: {
57
+ edges: [],
58
+ },
59
+ },
60
+ },
61
+ ],
62
+ },
63
+ },
64
+ },
65
+ {
66
+ node: {
67
+ author: {
68
+ email: 'soren.louv@elastic.co',
69
+ name: 'Søren Louv-Jansen',
70
+ },
71
+ repository: {
72
+ name: 'kibana',
73
+ owner: { login: 'elastic' },
74
+ },
75
+ committedDate: '2021-12-22T00:00:00Z',
76
+ sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
77
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
78
+ associatedPullRequests: {
79
+ edges: [
80
+ {
81
+ node: {
82
+ url: 'https://github.com/elastic/kibana/pull/80',
83
+ labels: {
84
+ nodes: [{ name: 'v6.3.0' }],
85
+ },
86
+ baseRefName: 'master',
87
+ number: 80,
88
+ mergeCommit: {
89
+ remoteConfigHistory: { edges: [] },
90
+ sha: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
91
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
92
+ },
93
+ timelineItems: {
94
+ edges: [
95
+ {
96
+ node: {
97
+ targetPullRequest: {
98
+ __typename: 'PullRequest',
99
+ targetMergeCommit: {
100
+ sha: 'target-merge-commit-sha',
101
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
102
+ },
103
+ repository: {
104
+ name: 'kibana',
105
+ owner: { login: 'elastic' },
106
+ },
107
+ url: 'https://github.com/elastic/kibana/pull/99',
108
+ title: 'some title',
109
+ state: 'MERGED',
110
+ number: 99,
111
+ baseRefName: '6.3',
112
+ commits: {
113
+ edges: [
114
+ {
115
+ node: {
116
+ targetCommit: {
117
+ sha: 'abc',
118
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
119
+ },
120
+ },
121
+ },
122
+ ],
123
+ },
124
+ },
125
+ },
126
+ },
127
+ ],
128
+ },
129
+ },
130
+ },
131
+ ],
132
+ },
133
+ },
134
+ },
135
+ {
136
+ node: {
137
+ author: {
138
+ email: 'soren.louv@elastic.co',
139
+ name: 'Søren Louv-Jansen',
140
+ },
141
+ repository: {
142
+ name: 'kibana',
143
+ owner: { login: 'elastic' },
144
+ },
145
+ committedDate: '2021-12-21T00:00:00Z',
146
+ sha: '3827bbbaf39914eda4f02f6940189844375fd097',
147
+ message: 'Add backport config',
148
+ associatedPullRequests: {
149
+ edges: [],
150
+ },
151
+ },
152
+ },
153
+ {
154
+ node: {
155
+ author: {
156
+ email: 'soren.louv@elastic.co',
157
+ name: 'Søren Louv-Jansen',
158
+ },
159
+ repository: {
160
+ name: 'kibana',
161
+ owner: { login: 'elastic' },
162
+ },
163
+ committedDate: '2021-12-20T00:00:00Z',
164
+ sha: '5ea0da550ac191029459289d67f99ad7d310812b',
165
+ message: 'Initial commit',
166
+ associatedPullRequests: {
167
+ edges: [],
168
+ },
169
+ },
170
+ },
171
+ ],
172
+ },
173
+ },
174
+ },
175
+ },
176
+ };