backport 7.2.0-beta.1 → 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 (129) hide show
  1. package/dist/entrypoint.cli.js +0 -0
  2. package/dist/entrypoint.module.d.ts +4 -3
  3. package/dist/entrypoint.module.js +2 -7
  4. package/dist/options/ConfigOptions.d.ts +1 -1
  5. package/dist/options/cliArgs.d.ts +1 -0
  6. package/dist/options/cliArgs.js +4 -0
  7. package/dist/options/config/config.d.ts +1 -1
  8. package/dist/options/config/readConfigFile.d.ts +1 -1
  9. package/dist/options/options.d.ts +2 -1
  10. package/dist/services/github/v3/createStatusComment.js +1 -1
  11. package/dist/services/github/v4/apiRequestV4.d.ts +2 -3
  12. package/dist/services/github/v4/apiRequestV4.js +15 -14
  13. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +2 -2
  14. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +2 -2
  15. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +2 -2
  16. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +2 -2
  17. package/dist/services/github/v4/fetchRemoteProjectConfig.js +1 -1
  18. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +1 -1
  19. package/dist/services/github/v4/getOptionsFromGithub/query.js +1 -1
  20. package/dist/services/github/v4/throwOnInvalidAccessToken.js +6 -6
  21. package/dist/services/remoteConfig.js +2 -2
  22. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -1
  23. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +5 -1
  24. package/dist/services/sourceCommit/getMockSourceCommit.js +19 -18
  25. package/dist/services/sourceCommit/parseSourceCommit.d.ts +2 -2
  26. package/dist/services/sourceCommit/parseSourceCommit.js +9 -15
  27. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +12 -18
  28. package/dist/ui/getCommits.js +6 -4
  29. package/dist/ui/maybeSetupRepo.js +7 -14
  30. package/dist/utils/packageVersion.d.ts +1 -1
  31. package/dist/utils/packageVersion.js +1 -1
  32. package/package.json +9 -9
  33. package/yarn.lock +121 -114
  34. package/dist/entrypoint.cli.e2e.private.test.d.ts +0 -1
  35. package/dist/entrypoint.cli.e2e.private.test.js +0 -386
  36. package/dist/entrypoint.cli.private.test.d.ts +0 -1
  37. package/dist/entrypoint.cli.private.test.js +0 -46
  38. package/dist/options/cliArgs.test.d.ts +0 -1
  39. package/dist/options/cliArgs.test.js +0 -182
  40. package/dist/options/config/config.test.d.ts +0 -1
  41. package/dist/options/config/config.test.js +0 -32
  42. package/dist/options/config/globalConfig.test.d.ts +0 -1
  43. package/dist/options/config/globalConfig.test.js +0 -61
  44. package/dist/options/config/projectConfig.test.d.ts +0 -1
  45. package/dist/options/config/projectConfig.test.js +0 -109
  46. package/dist/options/options.test.d.ts +0 -1
  47. package/dist/options/options.test.js +0 -384
  48. package/dist/runSequentially.test.d.ts +0 -1
  49. package/dist/runSequentially.test.js +0 -219
  50. package/dist/scripts/postinstall.test.d.ts +0 -1
  51. package/dist/scripts/postinstall.test.js +0 -53
  52. package/dist/services/env.test.d.ts +0 -1
  53. package/dist/services/env.test.js +0 -21
  54. package/dist/services/git.integration.test.d.ts +0 -1
  55. package/dist/services/git.integration.test.js +0 -320
  56. package/dist/services/git.test.d.ts +0 -1
  57. package/dist/services/git.test.js +0 -532
  58. package/dist/services/github/commitFormatters.test.d.ts +0 -1
  59. package/dist/services/github/commitFormatters.test.js +0 -11
  60. package/dist/services/github/v3/addAssigneesToPullRequest.test.d.ts +0 -1
  61. package/dist/services/github/v3/addAssigneesToPullRequest.test.js +0 -27
  62. package/dist/services/github/v3/createPullRequest.test.d.ts +0 -1
  63. package/dist/services/github/v3/createPullRequest.test.js +0 -325
  64. package/dist/services/github/v3/createStatusComment.test.d.ts +0 -1
  65. package/dist/services/github/v3/createStatusComment.test.js +0 -386
  66. package/dist/services/github/v4/apiRequestV4.test.d.ts +0 -1
  67. package/dist/services/github/v4/apiRequestV4.test.js +0 -109
  68. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.d.ts +0 -1
  69. package/dist/services/github/v4/enablePullRequestAutoMerge.private.test.js +0 -112
  70. package/dist/services/github/v4/fetchAuthorId.private.test.d.ts +0 -1
  71. package/dist/services/github/v4/fetchAuthorId.private.test.js +0 -28
  72. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +0 -1
  73. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -93
  74. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.d.ts +0 -1
  75. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +0 -134
  76. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.d.ts +0 -1
  77. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +0 -116
  78. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.d.ts +0 -1
  79. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +0 -195
  80. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.d.ts +0 -1
  81. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -152
  82. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.d.ts +0 -1
  83. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +0 -102
  84. package/dist/services/github/v4/fetchExistingPullRequest.private.test.d.ts +0 -1
  85. package/dist/services/github/v4/fetchExistingPullRequest.private.test.js +0 -47
  86. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +0 -1
  87. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +0 -52
  88. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.d.ts +0 -1
  89. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -117
  90. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.d.ts +0 -1
  91. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.private.test.js +0 -71
  92. package/dist/services/github/v4/mocks/commitsByAuthorMock.d.ts +0 -2
  93. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +0 -159
  94. package/dist/services/github/v4/throwOnInvalidAccessToken.test.d.ts +0 -1
  95. package/dist/services/github/v4/throwOnInvalidAccessToken.test.js +0 -87
  96. package/dist/services/prompt.test.d.ts +0 -1
  97. package/dist/services/prompt.test.js +0 -134
  98. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.d.ts +0 -1
  99. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +0 -433
  100. package/dist/services/sourceCommit/parseSourceCommit.test.d.ts +0 -1
  101. package/dist/services/sourceCommit/parseSourceCommit.test.js +0 -225
  102. package/dist/test/ExecError.d.ts +0 -16
  103. package/dist/test/ExecError.js +0 -15
  104. package/dist/test/backport-e2e.mutation.test.d.ts +0 -1
  105. package/dist/test/backport-e2e.mutation.test.js +0 -347
  106. package/dist/test/handleUnbackportedPullRequests.private.test.d.ts +0 -1
  107. package/dist/test/handleUnbackportedPullRequests.private.test.js +0 -57
  108. package/dist/test/mockConfigFiles.d.ts +0 -5
  109. package/dist/test/mockConfigFiles.js +0 -21
  110. package/dist/test/mocks.d.ts +0 -10
  111. package/dist/test/mocks.js +0 -23
  112. package/dist/test/nockHelpers.d.ts +0 -16
  113. package/dist/test/nockHelpers.js +0 -36
  114. package/dist/test/private/getDevAccessToken.d.ts +0 -2
  115. package/dist/test/private/getDevAccessToken.js +0 -12
  116. package/dist/test/sandbox.d.ts +0 -5
  117. package/dist/test/sandbox.js +0 -43
  118. package/dist/test/setupFiles/automatic-mocks.d.ts +0 -1
  119. package/dist/test/setupFiles/automatic-mocks.js +0 -63
  120. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.d.ts +0 -1
  121. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +0 -459
  122. package/dist/ui/getCommitsWithoutBackports.test.d.ts +0 -1
  123. package/dist/ui/getCommitsWithoutBackports.test.js +0 -311
  124. package/dist/ui/getTargetBranches.test.d.ts +0 -1
  125. package/dist/ui/getTargetBranches.test.js +0 -198
  126. package/dist/ui/maybeSetupRepo.test.d.ts +0 -1
  127. package/dist/ui/maybeSetupRepo.test.js +0 -204
  128. package/dist/utils/excludeUndefined.test.d.ts +0 -1
  129. package/dist/utils/excludeUndefined.test.js +0 -24
File without changes
@@ -1,8 +1,9 @@
1
1
  import { ConfigFileOptions } from './options/ConfigOptions';
2
2
  import { ValidConfigOptions } from './options/options';
3
+ import { Commit } from './services/sourceCommit/parseSourceCommit';
3
4
  export { BackportResponse } from './backportRun';
4
5
  export { ConfigFileOptions } from './options/ConfigOptions';
5
- export { Commit } from './services/sourceCommit/parseSourceCommit';
6
+ export { Commit };
6
7
  export { fetchRemoteProjectConfig as getRemoteProjectConfig } from './services/github/v4/fetchRemoteProjectConfig';
7
8
  export { getGlobalConfig as getLocalGlobalConfig } from './options/config/globalConfig';
8
9
  export declare function backportRun(options: ConfigFileOptions, processArgs?: string[]): Promise<import("./backportRun").BackportResponse>;
@@ -14,9 +15,9 @@ export declare function getCommits(options: {
14
15
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
15
16
  githubApiBaseUrlV4?: string;
16
17
  pullNumber?: number;
17
- sha?: string;
18
+ sha?: string | string[];
18
19
  skipRemoteConfig?: boolean;
19
20
  sourceBranch?: string;
20
21
  dateUntil?: string;
21
22
  dateSince?: string;
22
- }): Promise<import("./services/sourceCommit/parseSourceCommit").Commit[]>;
23
+ }): Promise<Commit[]>;
@@ -37,13 +37,8 @@ async function getCommits(options) {
37
37
  ];
38
38
  }
39
39
  if (options.sha) {
40
- return [
41
- await (0, fetchCommitBySha_1.fetchCommitBySha)({
42
- ...optionsFromGithub,
43
- ...options,
44
- sha: options.sha,
45
- }),
46
- ];
40
+ const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
41
+ return Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...optionsFromGithub, ...options, sha })));
47
42
  }
48
43
  return (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
49
44
  ...optionsFromGithub,
@@ -45,7 +45,7 @@ declare type Options = Partial<{
45
45
  repoOwner: string;
46
46
  resetAuthor: boolean;
47
47
  reviewers: string[];
48
- sha: string;
48
+ sha: string | string[];
49
49
  skipRemoteConfig: boolean;
50
50
  sourceBranch: string;
51
51
  sourcePRLabels: string[];
@@ -16,6 +16,7 @@ export declare function getOptionsFromCliArgs(processArgs: readonly string[], {
16
16
  cherrypickRef?: boolean | undefined;
17
17
  configFile?: string | undefined;
18
18
  details?: boolean | undefined;
19
+ dryRun?: boolean | undefined;
19
20
  editor?: string | undefined;
20
21
  skipRemoteConfig?: boolean | undefined;
21
22
  gitHostname?: string | undefined;
@@ -83,6 +83,10 @@ function getOptionsFromCliArgs(processArgs, { exitOnError = true } = {}) {
83
83
  .option('details', {
84
84
  description: 'Show details about each commit',
85
85
  type: 'boolean',
86
+ })
87
+ .option('dryRun', {
88
+ description: 'Run backport locally without pushing to Github',
89
+ type: 'boolean',
86
90
  })
87
91
  .option('editor', {
88
92
  description: 'Editor to be opened during conflict resolution',
@@ -45,7 +45,7 @@ export declare function getOptionsFromConfigFiles({ optionsFromCliArgs, optionsF
45
45
  repoOwner?: string | undefined;
46
46
  resetAuthor?: boolean | undefined;
47
47
  reviewers?: string[] | undefined;
48
- sha?: string | undefined;
48
+ sha?: string | string[] | undefined;
49
49
  skipRemoteConfig?: boolean | undefined;
50
50
  sourceBranch?: string | undefined;
51
51
  sourcePRLabels?: string[] | undefined;
@@ -30,7 +30,7 @@ export declare function withConfigMigrations({ upstream, labels, branches, ...co
30
30
  prTitle?: string | undefined;
31
31
  prFilter?: string | undefined;
32
32
  pullNumber?: number | undefined;
33
- sha?: string | undefined;
33
+ sha?: string | string[] | undefined;
34
34
  resetAuthor?: boolean | undefined;
35
35
  repoOwner?: string | undefined;
36
36
  repoName?: string | undefined;
@@ -17,6 +17,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
17
17
  cherrypickRef: boolean;
18
18
  configFile?: string | undefined;
19
19
  details: boolean;
20
+ dryRun?: boolean | undefined;
20
21
  editor?: string | undefined;
21
22
  skipRemoteConfig?: boolean | undefined;
22
23
  gitHostname: string;
@@ -31,7 +32,7 @@ export declare function getOptions(processArgs: string[], optionsFromModule: Con
31
32
  prTitle?: string | undefined;
32
33
  prFilter?: string | undefined;
33
34
  pullNumber?: number | undefined;
34
- sha?: string | undefined;
35
+ sha?: string | string[] | undefined;
35
36
  resetAuthor: boolean;
36
37
  sourceBranch: string;
37
38
  username?: string | undefined;
@@ -9,7 +9,7 @@ const logger_1 = require("../../logger");
9
9
  const commitFormatters_1 = require("../commitFormatters");
10
10
  async function createStatusComment({ options, backportResponse, }) {
11
11
  const { githubApiBaseUrlV3, repoName, repoOwner, accessToken, publishStatusComment, } = options;
12
- if (!publishStatusComment) {
12
+ if (!publishStatusComment || options.dryRun) {
13
13
  return;
14
14
  }
15
15
  try {
@@ -22,11 +22,10 @@ export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessT
22
22
  }): Promise<DataResponse>;
23
23
  declare type AxiosGithubResponse<DataResponse> = AxiosResponse<GithubV4Response<DataResponse | null>, any>;
24
24
  export declare class GithubV4Exception<DataResponse> extends Error {
25
- message: string;
26
- axiosResponse: AxiosGithubResponse<DataResponse> & {
25
+ githubResponse: AxiosGithubResponse<DataResponse> & {
27
26
  request: undefined;
28
27
  };
29
- constructor(message: string, axiosResponse: AxiosGithubResponse<DataResponse>);
28
+ constructor(githubResponse: AxiosGithubResponse<DataResponse>, errorMessage?: string);
30
29
  }
31
30
  export declare function getQueryName(query: DocumentNode): string;
32
31
  export {};
@@ -17,16 +17,13 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
17
17
  },
18
18
  });
19
19
  if (response.data.errors) {
20
- const message = `${response.data.errors
21
- .map((error) => error.message)
22
- .join(',')} (Github API v4)`;
23
- throw new GithubV4Exception(message, response);
20
+ throw new GithubV4Exception(response);
24
21
  }
25
22
  addDebugLogs({
26
23
  githubApiBaseUrlV4,
27
24
  query,
28
25
  variables,
29
- axiosResponse: response,
26
+ githubResponse: response,
30
27
  didSucceed: false,
31
28
  });
32
29
  return response.data.data;
@@ -37,32 +34,36 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
37
34
  githubApiBaseUrlV4,
38
35
  query,
39
36
  variables,
40
- axiosResponse: e.response,
37
+ githubResponse: e.response,
41
38
  didSucceed: false,
42
39
  });
43
- throw new GithubV4Exception(`${e.message} (Unhandled Github API v4)`, e.response);
40
+ throw new GithubV4Exception(e.response, e.message);
44
41
  }
45
42
  throw e;
46
43
  }
47
44
  }
48
45
  exports.apiRequestV4 = apiRequestV4;
49
- function addDebugLogs({ githubApiBaseUrlV4, query, variables, axiosResponse, didSucceed, }) {
46
+ function addDebugLogs({ githubApiBaseUrlV4, query, variables, githubResponse, didSucceed, }) {
50
47
  const gqlQueryName = getQueryName(query);
51
- logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${axiosResponse.status})`);
48
+ logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${githubResponse.status})`);
52
49
  const logMethod = didSucceed ? logger_1.logger.verbose : logger_1.logger.info;
53
50
  logMethod(`Query name ${gqlQueryName}`);
54
51
  logMethod(`Query: ${query}`);
55
52
  logMethod('Variables:', variables);
56
- logMethod('Response headers:', axiosResponse.headers);
57
- logMethod('Response data:', axiosResponse.data);
53
+ logMethod('Response headers:', githubResponse.headers);
54
+ logMethod('Response data:', githubResponse.data);
58
55
  }
59
56
  class GithubV4Exception extends Error {
60
- constructor(message, axiosResponse) {
57
+ constructor(githubResponse, errorMessage) {
58
+ const githubMessage = githubResponse.data.errors
59
+ ?.map((error) => error.message)
60
+ .join(',');
61
+ const message = `${errorMessage ?? githubMessage ?? 'Unknown error'} (Github API v4)`;
61
62
  super(message);
62
- this.message = message;
63
63
  Error.captureStackTrace(this, HandledError_1.HandledError);
64
64
  this.name = 'GithubV4Exception';
65
- this.axiosResponse = { ...axiosResponse, request: undefined };
65
+ this.message = message;
66
+ this.githubResponse = { ...githubResponse, request: undefined };
66
67
  }
67
68
  }
68
69
  exports.GithubV4Exception = GithubV4Exception;
@@ -20,13 +20,13 @@ async function fetchCommitByPullNumber(options) {
20
20
  repository(owner: $repoOwner, name: $repoName) {
21
21
  pullRequest(number: $pullNumber) {
22
22
  mergeCommit {
23
- ...SourceCommitWithTargetPullRequest
23
+ ...SourceCommitWithTargetPullRequestFragment
24
24
  }
25
25
  }
26
26
  }
27
27
  }
28
28
 
29
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
29
+ ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
30
30
  `;
31
31
  let res;
32
32
  try {
@@ -15,12 +15,12 @@ async function fetchCommitBySha(options) {
15
15
  query CommitsBySha($repoOwner: String!, $repoName: String!, $sha: String!) {
16
16
  repository(owner: $repoOwner, name: $repoName) {
17
17
  object(expression: $sha) {
18
- ...SourceCommitWithTargetPullRequest
18
+ ...SourceCommitWithTargetPullRequestFragment
19
19
  }
20
20
  }
21
21
  }
22
22
 
23
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
23
+ ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
24
24
  `;
25
25
  let res;
26
26
  try {
@@ -38,7 +38,7 @@ async function fetchByCommitPath({ options, authorId, commitPath, }) {
38
38
  ) {
39
39
  edges {
40
40
  node {
41
- ...SourceCommitWithTargetPullRequest
41
+ ...SourceCommitWithTargetPullRequestFragment
42
42
  }
43
43
  }
44
44
  }
@@ -48,7 +48,7 @@ async function fetchByCommitPath({ options, authorId, commitPath, }) {
48
48
  }
49
49
  }
50
50
 
51
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
51
+ ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
52
52
  `;
53
53
  const variables = {
54
54
  repoOwner,
@@ -18,14 +18,14 @@ async function fetchPullRequestBySearchQuery(options) {
18
18
  nodes {
19
19
  ... on PullRequest {
20
20
  mergeCommit {
21
- ...SourceCommitWithTargetPullRequest
21
+ ...SourceCommitWithTargetPullRequestFragment
22
22
  }
23
23
  }
24
24
  }
25
25
  }
26
26
  }
27
27
 
28
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
28
+ ${parseSourceCommit_1.SourceCommitWithTargetPullRequestFragment}
29
29
  `;
30
30
  const authorFilter = author ? ` author:${author}` : '';
31
31
  const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter} ${prFilter} base:${sourceBranch}`;
@@ -18,7 +18,7 @@ async function fetchRemoteProjectConfig(options) {
18
18
  repository(owner: $repoOwner, name: $repoName) {
19
19
  ref(qualifiedName: $sourceBranch) {
20
20
  target {
21
- ...RemoteConfigHistory
21
+ ...RemoteConfigHistoryFragment
22
22
  }
23
23
  }
24
24
  }
@@ -47,7 +47,7 @@ export declare function getOptionsFromGithub(options: {
47
47
  repoOwner?: string | undefined;
48
48
  resetAuthor?: boolean | undefined;
49
49
  reviewers?: string[] | undefined;
50
- sha?: string | undefined;
50
+ sha?: string | string[] | undefined;
51
51
  skipRemoteConfig?: boolean | undefined;
52
52
  sourceBranch: string;
53
53
  sourcePRLabels?: string[] | undefined;
@@ -19,7 +19,7 @@ exports.query = (0, graphql_tag_1.default) `
19
19
  defaultBranchRef {
20
20
  name
21
21
  target {
22
- ...RemoteConfigHistory
22
+ ...RemoteConfigHistoryFragment
23
23
  }
24
24
  }
25
25
  }
@@ -12,13 +12,13 @@ function throwOnInvalidAccessToken({ error, repoOwner, repoName, }) {
12
12
  return matches[1];
13
13
  }
14
14
  }
15
- const statusCode = error.axiosResponse.status;
15
+ const statusCode = error.githubResponse.status;
16
16
  switch (statusCode) {
17
17
  case 200: {
18
- const repoNotFound = error.axiosResponse.data.errors?.some((error) => error.type === 'NOT_FOUND' && error.path.join('.') === 'repository');
19
- const grantedScopes = error.axiosResponse.headers['x-oauth-scopes'] || '';
20
- const requiredScopes = error.axiosResponse.headers['x-accepted-oauth-scopes'] || '';
21
- const ssoHeader = (0, maybe_1.maybe)(error.axiosResponse.headers['x-github-sso']);
18
+ const repoNotFound = error.githubResponse.data.errors?.some((error) => error.type === 'NOT_FOUND' && error.path.join('.') === 'repository');
19
+ const grantedScopes = error.githubResponse.headers['x-oauth-scopes'] || '';
20
+ const requiredScopes = error.githubResponse.headers['x-accepted-oauth-scopes'] || '';
21
+ const ssoHeader = (0, maybe_1.maybe)(error.githubResponse.headers['x-github-sso']);
22
22
  if (repoNotFound) {
23
23
  const hasRequiredScopes = (0, lodash_1.isEmpty)((0, lodash_1.difference)(requiredScopes.split(','), grantedScopes.split(',')));
24
24
  // user does not have permission to the repo
@@ -28,7 +28,7 @@ function throwOnInvalidAccessToken({ error, repoOwner, repoName, }) {
28
28
  // repo does not exist
29
29
  throw new HandledError_1.HandledError(`The repository "${repoOwner}/${repoName}" doesn't exist`);
30
30
  }
31
- const repoAccessForbidden = error.axiosResponse.data.errors?.some((error) => error.type === 'FORBIDDEN');
31
+ const repoAccessForbidden = error.githubResponse.data.errors?.some((error) => error.type === 'FORBIDDEN');
32
32
  const ssoAuthUrl = getSSOAuthUrl(ssoHeader);
33
33
  // user does not have permissions
34
34
  if (repoAccessForbidden && ssoAuthUrl) {
@@ -8,7 +8,7 @@ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const readConfigFile_1 = require("../options/config/readConfigFile");
9
9
  const logger_1 = require("./logger");
10
10
  exports.RemoteConfigHistoryFragment = (0, graphql_tag_1.default) `
11
- fragment RemoteConfigHistory on Commit {
11
+ fragment RemoteConfigHistoryFragment on Commit {
12
12
  remoteConfigHistory: history(first: 1, path: ".backportrc.json") {
13
13
  edges {
14
14
  remoteConfig: node {
@@ -38,7 +38,7 @@ function parseRemoteConfig(remoteConfig) {
38
38
  }
39
39
  exports.parseRemoteConfig = parseRemoteConfig;
40
40
  function swallowMissingConfigFileException(error) {
41
- const { data, errors } = error.axiosResponse.data;
41
+ const { data, errors } = error.githubResponse.data;
42
42
  const missingConfigError = errors?.some((error) => {
43
43
  return error.path.includes('remoteConfig') && error.type === 'NOT_FOUND';
44
44
  });
@@ -10,4 +10,7 @@ export declare type ExpectedTargetPullRequest = {
10
10
  message: string;
11
11
  };
12
12
  };
13
- export declare function getExpectedTargetPullRequests(sourceCommit: SourceCommitWithTargetPullRequest, branchLabelMapping: ValidConfigOptions['branchLabelMapping']): ExpectedTargetPullRequest[];
13
+ export declare function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }: {
14
+ sourceCommit: SourceCommitWithTargetPullRequest;
15
+ latestBranchLabelMapping: ValidConfigOptions['branchLabelMapping'];
16
+ }): ExpectedTargetPullRequest[];
@@ -4,8 +4,12 @@ exports.getExpectedTargetPullRequests = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const filterEmpty_1 = require("../../utils/filterEmpty");
6
6
  const commitFormatters_1 = require("../github/commitFormatters");
7
- function getExpectedTargetPullRequests(sourceCommit, branchLabelMapping) {
7
+ const remoteConfig_1 = require("../remoteConfig");
8
+ function getExpectedTargetPullRequests({ sourceCommit, latestBranchLabelMapping, }) {
8
9
  const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
10
+ const remoteConfig = sourcePullRequest?.mergeCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
11
+ const branchLabelMapping = (remoteConfig && (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping) ??
12
+ latestBranchLabelMapping;
9
13
  // if there is no source pull request the commit was pushed directly to the source branch
10
14
  // in that case there will be no labels, and thus not possible to deduce the expected target branches
11
15
  if (!sourcePullRequest) {
@@ -5,24 +5,6 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
5
5
  const defaultTargetPullRequestTitle = 'DO NOT USE: Default Pull Request Title';
6
6
  const defaultSourceCommitSha = 'DO NOT USE: default-source-commit-sha';
7
7
  const baseMockCommit = {
8
- remoteConfigHistory: sourceCommit.remoteConfig
9
- ? {
10
- edges: [
11
- {
12
- remoteConfig: {
13
- committedDate: sourceCommit.remoteConfig.committedDate,
14
- file: {
15
- object: {
16
- text: JSON.stringify({
17
- branchLabelMapping: sourceCommit.remoteConfig.branchLabelMapping,
18
- }),
19
- },
20
- },
21
- },
22
- },
23
- ],
24
- }
25
- : { edges: [] },
26
8
  repository: {
27
9
  name: 'kibana',
28
10
  owner: { login: 'elastic' },
@@ -35,6 +17,24 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
35
17
  if (!sourcePullRequest) {
36
18
  return baseMockCommit;
37
19
  }
20
+ const remoteConfigHistory = sourceCommit.remoteConfig
21
+ ? {
22
+ edges: [
23
+ {
24
+ remoteConfig: {
25
+ committedDate: sourceCommit.remoteConfig.committedDate,
26
+ file: {
27
+ object: {
28
+ text: JSON.stringify({
29
+ branchLabelMapping: sourceCommit.remoteConfig.branchLabelMapping,
30
+ }),
31
+ },
32
+ },
33
+ },
34
+ },
35
+ ],
36
+ }
37
+ : { edges: [] };
38
38
  return {
39
39
  ...baseMockCommit,
40
40
  associatedPullRequests: {
@@ -42,6 +42,7 @@ function getMockSourceCommit({ sourceCommit, sourcePullRequest, timelineItems =
42
42
  {
43
43
  node: {
44
44
  mergeCommit: {
45
+ remoteConfigHistory,
45
46
  sha: sourceCommit.sha ?? defaultSourceCommitSha,
46
47
  message: sourceCommit.message,
47
48
  },
@@ -28,6 +28,7 @@ export interface SourcePullRequestNode {
28
28
  }[];
29
29
  };
30
30
  mergeCommit: {
31
+ remoteConfigHistory: RemoteConfigHistory['remoteConfigHistory'];
31
32
  sha: string;
32
33
  message: string;
33
34
  };
@@ -76,7 +77,6 @@ interface TimelineIssueEdge {
76
77
  };
77
78
  }
78
79
  export declare type SourceCommitWithTargetPullRequest = {
79
- remoteConfigHistory: RemoteConfigHistory['remoteConfigHistory'];
80
80
  repository: {
81
81
  name: string;
82
82
  owner: {
@@ -99,5 +99,5 @@ export declare function parseSourceCommit({ sourceCommit, options, }: {
99
99
  sourceBranch: string;
100
100
  };
101
101
  }): Commit;
102
- export declare const sourceCommitWithTargetPullRequestFragment: import("graphql").DocumentNode;
102
+ export declare const SourceCommitWithTargetPullRequestFragment: import("graphql").DocumentNode;
103
103
  export {};
@@ -3,20 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.sourceCommitWithTargetPullRequestFragment = exports.parseSourceCommit = void 0;
6
+ exports.SourceCommitWithTargetPullRequestFragment = exports.parseSourceCommit = void 0;
7
7
  const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const remoteConfig_1 = require("../remoteConfig");
9
9
  const getExpectedTargetPullRequests_1 = require("./getExpectedTargetPullRequests");
10
10
  function parseSourceCommit({ sourceCommit, options, }) {
11
11
  const sourcePullRequest = sourceCommit.associatedPullRequests.edges?.[0]?.node;
12
- // use info from associated pull request if available. Fall back to commit info
13
- const sourceBranch = sourcePullRequest?.baseRefName ?? options.sourceBranch;
14
- const remoteConfig = sourceCommit.remoteConfigHistory.edges?.[0]?.remoteConfig;
15
- const branchLabelMapping = remoteConfig
16
- ? (0, remoteConfig_1.parseRemoteConfig)(remoteConfig)?.branchLabelMapping ??
17
- options.branchLabelMapping
18
- : options.branchLabelMapping;
19
- const expectedTargetPullRequests = (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)(sourceCommit, branchLabelMapping);
20
12
  return {
21
13
  sourceCommit: {
22
14
  committedDate: sourceCommit.committedDate,
@@ -33,15 +25,16 @@ function parseSourceCommit({ sourceCommit, options, }) {
33
25
  },
34
26
  }
35
27
  : undefined,
36
- sourceBranch,
37
- expectedTargetPullRequests,
28
+ sourceBranch: sourcePullRequest?.baseRefName ?? options.sourceBranch,
29
+ expectedTargetPullRequests: (0, getExpectedTargetPullRequests_1.getExpectedTargetPullRequests)({
30
+ sourceCommit,
31
+ latestBranchLabelMapping: options.branchLabelMapping,
32
+ }),
38
33
  };
39
34
  }
40
35
  exports.parseSourceCommit = parseSourceCommit;
41
- exports.sourceCommitWithTargetPullRequestFragment = (0, graphql_tag_1.default) `
42
- fragment SourceCommitWithTargetPullRequest on Commit {
43
- ...RemoteConfigHistory
44
-
36
+ exports.SourceCommitWithTargetPullRequestFragment = (0, graphql_tag_1.default) `
37
+ fragment SourceCommitWithTargetPullRequestFragment on Commit {
45
38
  # Source Commit
46
39
  repository {
47
40
  name
@@ -68,6 +61,7 @@ exports.sourceCommitWithTargetPullRequestFragment = (0, graphql_tag_1.default) `
68
61
 
69
62
  # source merge commit (the commit that actually went into the source branch)
70
63
  mergeCommit {
64
+ ...RemoteConfigHistoryFragment
71
65
  sha: oid
72
66
  message
73
67
  }
@@ -25,6 +25,17 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
25
25
  const backportBranch = getBackportBranchName(targetBranch, commits);
26
26
  const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
27
27
  (0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
28
+ await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
29
+ await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
30
+ if (options.resetAuthor) {
31
+ await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
32
+ }
33
+ if (options.dryRun) {
34
+ (0, ora_1.ora)(options.ci).succeed('Dry run');
35
+ return { url: 'https://localhost/dry-run', didUpdate: false, number: 1337 };
36
+ }
37
+ await (0, git_1.pushBackportBranch)({ options, backportBranch });
38
+ await (0, git_1.deleteBackportBranch)({ options, backportBranch });
28
39
  const prPayload = {
29
40
  owner: options.repoOwner,
30
41
  repo: options.repoName,
@@ -33,13 +44,7 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
33
44
  head: `${repoForkOwner}:${backportBranch}`,
34
45
  base: targetBranch, // eg. 7.x
35
46
  };
36
- const targetPullRequest = await backportViaFilesystem({
37
- options,
38
- prPayload,
39
- targetBranch,
40
- backportBranch,
41
- commits,
42
- });
47
+ const targetPullRequest = await (0, createPullRequest_1.createPullRequest)({ options, prPayload });
43
48
  // add assignees to target pull request
44
49
  const assignees = options.autoAssign
45
50
  ? [options.authenticatedUsername]
@@ -72,17 +77,6 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
72
77
  return targetPullRequest;
73
78
  }
74
79
  exports.cherrypickAndCreateTargetPullRequest = cherrypickAndCreateTargetPullRequest;
75
- async function backportViaFilesystem({ options, prPayload, commits, targetBranch, backportBranch, }) {
76
- logger_1.logger.info('Backporting via filesystem');
77
- await (0, git_1.createBackportBranch)({ options, targetBranch, backportBranch });
78
- await (0, sequentially_1.sequentially)(commits, (commit) => waitForCherrypick(options, commit, targetBranch));
79
- if (options.resetAuthor) {
80
- await (0, git_1.setCommitAuthor)(options, options.authenticatedUsername);
81
- }
82
- await (0, git_1.pushBackportBranch)({ options, backportBranch });
83
- await (0, git_1.deleteBackportBranch)({ options, backportBranch });
84
- return (0, createPullRequest_1.createPullRequest)({ options, prPayload });
85
- }
86
80
  /*
87
81
  * Returns the name of the backport branch without remote name
88
82
  *
@@ -23,10 +23,12 @@ async function getCommits(options) {
23
23
  const spinner = (0, ora_1.ora)(options.ci).start();
24
24
  try {
25
25
  if (options.sha) {
26
- spinner.text = `Loading commit "${(0, commitFormatters_1.getShortSha)(options.sha)}"`;
27
- const commit = await (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha: options.sha });
28
- spinner.stopAndPersist(getOraPersistsOption('Select commit', commit.sourceCommit.message));
29
- return [commit];
26
+ const shas = Array.isArray(options.sha) ? options.sha : [options.sha];
27
+ // TODO: use Intl.ListFormat to format the sha's
28
+ spinner.text = `Loading commit "${shas.map(commitFormatters_1.getShortSha)}"`;
29
+ const commits = await Promise.all(shas.map((sha) => (0, fetchCommitBySha_1.fetchCommitBySha)({ ...options, sha })));
30
+ spinner.stopAndPersist(getOraPersistsOption('Select commit', commits.map((commit) => commit.sourceCommit.message).join(', ')));
31
+ return commits;
30
32
  }
31
33
  if (options.pullNumber) {
32
34
  spinner.text = `Loading pull request #${options.pullNumber}`;
@@ -1,14 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.maybeSetupRepo = void 0;
4
- const promises_1 = require("fs/promises");
5
4
  const del = require("del");
6
5
  const ora = require("ora");
7
6
  const env_1 = require("../services/env");
8
7
  const git_1 = require("../services/git");
9
8
  async function maybeSetupRepo(options) {
10
9
  const repoPath = (0, env_1.getRepoPath)(options);
11
- const isAlreadyCloned = await getIsRepoCloned(repoPath);
10
+ const isAlreadyCloned = await getIsRepoCloned(options);
12
11
  // clone repo if folder does not already exists
13
12
  if (!isAlreadyCloned) {
14
13
  const spinner = ora().start();
@@ -19,6 +18,7 @@ async function maybeSetupRepo(options) {
19
18
  : sourcePath;
20
19
  const spinnerCloneText = `Cloning repository from ${sourcePathHumanReadable} (one-time operation)`;
21
20
  spinner.text = `0% ${spinnerCloneText}`;
21
+ await del(repoPath, { force: true });
22
22
  await (0, git_1.cloneRepo)({ sourcePath, targetPath: repoPath }, (progress) => {
23
23
  spinner.text = `${progress}% ${spinnerCloneText}`;
24
24
  });
@@ -26,7 +26,7 @@ async function maybeSetupRepo(options) {
26
26
  }
27
27
  catch (e) {
28
28
  spinner.fail();
29
- await del(repoPath);
29
+ await del(repoPath, { force: true });
30
30
  throw e;
31
31
  }
32
32
  }
@@ -42,15 +42,8 @@ async function maybeSetupRepo(options) {
42
42
  }
43
43
  }
44
44
  exports.maybeSetupRepo = maybeSetupRepo;
45
- async function getIsRepoCloned(path) {
46
- try {
47
- const stats = await (0, promises_1.stat)(path);
48
- return stats.isDirectory();
49
- }
50
- catch (e) {
51
- if (e.code === 'ENOENT') {
52
- return false;
53
- }
54
- throw e;
55
- }
45
+ async function getIsRepoCloned(options) {
46
+ const repoPath = (0, env_1.getRepoPath)(options);
47
+ const projectRoot = await (0, git_1.getGitProjectRoot)(options);
48
+ return repoPath === projectRoot;
56
49
  }
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "7.2.0-beta.1";
1
+ export declare const PACKAGE_VERSION = "7.2.0-beta.2";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PACKAGE_VERSION = void 0;
4
- exports.PACKAGE_VERSION = '7.2.0-beta.1';
4
+ exports.PACKAGE_VERSION = '7.2.0-beta.2';