backport 7.0.1-beta.1 → 7.2.0-beta.1

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 (72) hide show
  1. package/dist/backportRun.d.ts +1 -0
  2. package/dist/backportRun.js +3 -2
  3. package/dist/entrypoint.cli.e2e.private.test.js +74 -7
  4. package/dist/entrypoint.cli.js +12 -1
  5. package/dist/options/cliArgs.d.ts +1 -1
  6. package/dist/options/config/readConfigFile.d.ts +1 -1
  7. package/dist/options/options.d.ts +1 -5
  8. package/dist/options/options.test.js +26 -28
  9. package/dist/runSequentially.js +1 -0
  10. package/dist/runSequentially.test.js +3 -2
  11. package/dist/services/HandledError.js +3 -1
  12. package/dist/services/git.d.ts +2 -0
  13. package/dist/services/git.integration.test.js +66 -13
  14. package/dist/services/git.js +47 -10
  15. package/dist/services/git.test.js +15 -1
  16. package/dist/services/github/v3/addAssigneesToPullRequest.d.ts +1 -1
  17. package/dist/services/github/v3/addAssigneesToPullRequest.js +3 -6
  18. package/dist/services/github/v3/addLabelsToPullRequest.d.ts +1 -1
  19. package/dist/services/github/v3/addLabelsToPullRequest.js +3 -6
  20. package/dist/services/github/v3/addReviewersToPullRequest.d.ts +1 -1
  21. package/dist/services/github/v3/addReviewersToPullRequest.js +3 -6
  22. package/dist/services/github/v3/createPullRequest.js +2 -5
  23. package/dist/services/github/v4/FetchPullRequestId.js +5 -1
  24. package/dist/services/github/v4/apiRequestV4.d.ts +6 -2
  25. package/dist/services/github/v4/apiRequestV4.js +8 -8
  26. package/dist/services/github/v4/apiRequestV4.test.js +38 -11
  27. package/dist/services/github/v4/disablePullRequestAutoMerge.js +5 -1
  28. package/dist/services/github/v4/enablePullRequestAutoMerge.js +4 -3
  29. package/dist/services/github/v4/fetchAuthorId.js +5 -1
  30. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +0 -3
  31. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.d.ts +0 -1
  32. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +23 -12
  33. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +3 -12
  34. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.d.ts +0 -1
  35. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +23 -12
  36. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +3 -11
  37. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +0 -1
  38. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +19 -9
  39. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +7 -12
  40. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +0 -1
  41. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +19 -8
  42. package/dist/services/github/v4/fetchExistingPullRequest.js +5 -1
  43. package/dist/services/github/v4/fetchPullRequestAutoMergeMethod.js +5 -1
  44. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +1 -1
  45. package/dist/services/github/v4/fetchRemoteProjectConfig.js +13 -20
  46. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +0 -4
  47. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +12 -66
  48. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.private.test.js +0 -19
  49. package/dist/services/github/v4/getOptionsFromGithub/query.d.ts +3 -16
  50. package/dist/services/github/v4/getOptionsFromGithub/query.js +9 -19
  51. package/dist/services/github/v4/getRepoOwnerAndNameFromGitRemotes.js +5 -1
  52. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +5 -0
  53. package/dist/services/logger.d.ts +5 -5
  54. package/dist/services/logger.js +24 -23
  55. package/dist/services/remoteConfig.d.ts +20 -0
  56. package/dist/services/remoteConfig.js +52 -0
  57. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +4 -0
  58. package/dist/services/sourceCommit/getMockSourceCommit.js +20 -6
  59. package/dist/services/sourceCommit/parseSourceCommit.d.ts +3 -4
  60. package/dist/services/sourceCommit/parseSourceCommit.js +73 -71
  61. package/dist/services/sourceCommit/parseSourceCommit.test.js +7 -17
  62. package/dist/test/nockHelpers.js +6 -2
  63. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +4 -4
  64. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +4 -0
  65. package/dist/ui/getCommits.js +2 -2
  66. package/dist/ui/ora.d.ts +9 -0
  67. package/dist/ui/ora.js +21 -0
  68. package/dist/utils/packageVersion.d.ts +1 -1
  69. package/dist/utils/packageVersion.js +1 -1
  70. package/package.json +3 -3
  71. package/dist/services/github/v3/index.d.ts +0 -1
  72. package/dist/services/github/v3/index.js +0 -61
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.addAssigneesToPullRequest = void 0;
7
4
  const rest_1 = require("@octokit/rest");
8
- const ora_1 = __importDefault(require("ora"));
5
+ const ora_1 = require("../../../ui/ora");
9
6
  const logger_1 = require("../../logger");
10
- async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, }, pullNumber, assignees) {
7
+ async function addAssigneesToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, autoAssign, ci, }, pullNumber, assignees) {
11
8
  const text = autoAssign
12
9
  ? `Self-assigning to #${pullNumber}`
13
10
  : `Adding assignees to #${pullNumber}: ${assignees.join(', ')}`;
14
11
  logger_1.logger.info(text);
15
- const spinner = (0, ora_1.default)(text).start();
12
+ const spinner = (0, ora_1.ora)(ci, text).start();
16
13
  try {
17
14
  const octokit = new rest_1.Octokit({
18
15
  auth: accessToken,
@@ -1,2 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
2
+ export declare function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }: ValidConfigOptions, pullNumber: number, labels: string[]): Promise<void>;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.addLabelsToPullRequest = void 0;
7
4
  const rest_1 = require("@octokit/rest");
8
- const ora_1 = __importDefault(require("ora"));
5
+ const ora_1 = require("../../../ui/ora");
9
6
  const logger_1 = require("../../logger");
10
- async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, labels) {
7
+ async function addLabelsToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }, pullNumber, labels) {
11
8
  const text = `Adding labels: ${labels.join(', ')}`;
12
9
  logger_1.logger.info(text);
13
- const spinner = (0, ora_1.default)(text).start();
10
+ const spinner = (0, ora_1.ora)(ci, text).start();
14
11
  try {
15
12
  const octokit = new rest_1.Octokit({
16
13
  auth: accessToken,
@@ -1,2 +1,2 @@
1
1
  import { ValidConfigOptions } from '../../../options/options';
2
- export declare function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }: ValidConfigOptions, pullNumber: number, reviewers: string[]): Promise<void>;
2
+ export declare function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }: ValidConfigOptions, pullNumber: number, reviewers: string[]): Promise<void>;
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.addReviewersToPullRequest = void 0;
7
4
  const rest_1 = require("@octokit/rest");
8
- const ora_1 = __importDefault(require("ora"));
5
+ const ora_1 = require("../../../ui/ora");
9
6
  const logger_1 = require("../../logger");
10
- async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken }, pullNumber, reviewers) {
7
+ async function addReviewersToPullRequest({ githubApiBaseUrlV3, repoName, repoOwner, accessToken, ci, }, pullNumber, reviewers) {
11
8
  const text = `Adding reviewers: ${reviewers}`;
12
9
  logger_1.logger.info(text);
13
- const spinner = (0, ora_1.default)(text).start();
10
+ const spinner = (0, ora_1.ora)(ci, text).start();
14
11
  try {
15
12
  const octokit = new rest_1.Octokit({
16
13
  auth: accessToken,
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getTitle = exports.getPullRequestBody = exports.createPullRequest = void 0;
7
4
  const rest_1 = require("@octokit/rest");
8
- const ora_1 = __importDefault(require("ora"));
5
+ const ora_1 = require("../../../ui/ora");
9
6
  const packageVersion_1 = require("../../../utils/packageVersion");
10
7
  const HandledError_1 = require("../../HandledError");
11
8
  const logger_1 = require("../../logger");
@@ -15,7 +12,7 @@ const getGithubV3ErrorMessage_1 = require("./getGithubV3ErrorMessage");
15
12
  async function createPullRequest({ options, prPayload, }) {
16
13
  logger_1.logger.info(`Creating PR with title: "${prPayload.title}". ${prPayload.head} -> ${prPayload.base}`);
17
14
  const { accessToken, githubApiBaseUrlV3 } = options;
18
- const spinner = (0, ora_1.default)(`Creating pull request`).start();
15
+ const spinner = (0, ora_1.ora)(options.ci, `Creating pull request`).start();
19
16
  try {
20
17
  const octokit = new rest_1.Octokit({
21
18
  auth: accessToken,
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchPullRequestId = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const apiRequestV4_1 = require("./apiRequestV4");
5
9
  async function fetchPullRequestId(options, pullNumber) {
6
10
  const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
7
- const prQuery = /* GraphQL */ `
11
+ const prQuery = (0, graphql_tag_1.default) `
8
12
  query PullRequestId(
9
13
  $repoOwner: String!
10
14
  $repoName: String!
@@ -1,4 +1,5 @@
1
1
  import { AxiosResponse } from 'axios';
2
+ import { DocumentNode } from 'graphql';
2
3
  interface GithubError {
3
4
  type: string;
4
5
  path: string[];
@@ -16,13 +17,16 @@ declare type Variables = Record<string, string | number | null>;
16
17
  export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessToken, query, variables, }: {
17
18
  githubApiBaseUrlV4?: string;
18
19
  accessToken: string;
19
- query: string;
20
+ query: DocumentNode;
20
21
  variables?: Variables;
21
22
  }): Promise<DataResponse>;
22
23
  declare type AxiosGithubResponse<DataResponse> = AxiosResponse<GithubV4Response<DataResponse | null>, any>;
23
24
  export declare class GithubV4Exception<DataResponse> extends Error {
24
25
  message: string;
25
- axiosResponse: AxiosGithubResponse<DataResponse>;
26
+ axiosResponse: AxiosGithubResponse<DataResponse> & {
27
+ request: undefined;
28
+ };
26
29
  constructor(message: string, axiosResponse: AxiosGithubResponse<DataResponse>);
27
30
  }
31
+ export declare function getQueryName(query: DocumentNode): string;
28
32
  export {};
@@ -3,14 +3,14 @@ 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.GithubV4Exception = exports.apiRequestV4 = void 0;
6
+ exports.getQueryName = exports.GithubV4Exception = exports.apiRequestV4 = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const printer_1 = require("graphql/language/printer");
9
9
  const HandledError_1 = require("../../HandledError");
10
10
  const logger_1 = require("../../logger");
11
11
  async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graphql', accessToken, query, variables, }) {
12
12
  try {
13
- const response = await axios_1.default.post(githubApiBaseUrlV4, { query, variables }, {
13
+ const response = await axios_1.default.post(githubApiBaseUrlV4, { query: (0, printer_1.print)(query), variables }, {
14
14
  headers: {
15
15
  'Content-Type': 'application/json',
16
16
  Authorization: `bearer ${accessToken}`,
@@ -47,7 +47,7 @@ async function apiRequestV4({ githubApiBaseUrlV4 = 'https://api.github.com/graph
47
47
  }
48
48
  exports.apiRequestV4 = apiRequestV4;
49
49
  function addDebugLogs({ githubApiBaseUrlV4, query, variables, axiosResponse, didSucceed, }) {
50
- const gqlQueryName = getGqlQueryName(query);
50
+ const gqlQueryName = getQueryName(query);
51
51
  logger_1.logger.info(`POST ${githubApiBaseUrlV4} (name:${gqlQueryName}, status: ${axiosResponse.status})`);
52
52
  const logMethod = didSucceed ? logger_1.logger.verbose : logger_1.logger.info;
53
53
  logMethod(`Query name ${gqlQueryName}`);
@@ -60,14 +60,14 @@ class GithubV4Exception extends Error {
60
60
  constructor(message, axiosResponse) {
61
61
  super(message);
62
62
  this.message = message;
63
- this.axiosResponse = axiosResponse;
64
63
  Error.captureStackTrace(this, HandledError_1.HandledError);
65
64
  this.name = 'GithubV4Exception';
65
+ this.axiosResponse = { ...axiosResponse, request: undefined };
66
66
  }
67
67
  }
68
68
  exports.GithubV4Exception = GithubV4Exception;
69
- function getGqlQueryName(query) {
70
- const ast = (0, graphql_tag_1.default)(query);
69
+ function getQueryName(query) {
71
70
  //@ts-expect-error
72
- return ast.definitions[0].name.value;
71
+ return query.definitions[0].name?.value;
73
72
  }
73
+ exports.getQueryName = getQueryName;
@@ -3,6 +3,7 @@ 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
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
6
7
  const nock_1 = __importDefault(require("nock"));
7
8
  const nockHelpers_1 = require("../../../test/nockHelpers");
8
9
  const HandledError_1 = require("../../HandledError");
@@ -18,25 +19,39 @@ describe('apiRequestV4', () => {
18
19
  commitsByAuthorCalls = (0, nockHelpers_1.mockGqlRequest)({
19
20
  name: 'MyQuery',
20
21
  statusCode: 200,
21
- body: { data: { hello: 'world' } },
22
+ body: { data: { viewer: { login: 'sqren' } } },
22
23
  });
23
24
  res = await (0, apiRequestV4_1.apiRequestV4)({
24
25
  accessToken: 'myAccessToken',
25
26
  githubApiBaseUrlV4: 'http://localhost/graphql',
26
- query: 'query MyQuery{ foo }',
27
+ query: (0, graphql_tag_1.default) `
28
+ query MyQuery {
29
+ viewer {
30
+ login
31
+ }
32
+ }
33
+ `,
27
34
  variables: { foo: 'bar' },
28
35
  });
29
36
  });
30
37
  it('should return correct response', async () => {
31
- expect(res).toEqual({ hello: 'world' });
38
+ expect(res).toEqual({ viewer: { login: 'sqren' } });
32
39
  });
33
40
  it('should call with correct args', async () => {
34
- expect(commitsByAuthorCalls).toEqual([
35
- {
36
- query: 'query MyQuery{ foo }',
37
- variables: { foo: 'bar' },
38
- },
39
- ]);
41
+ expect(commitsByAuthorCalls).toMatchInlineSnapshot(`
42
+ Array [
43
+ Object {
44
+ "query": "query MyQuery {
45
+ viewer {
46
+ login
47
+ }
48
+ }",
49
+ "variables": Object {
50
+ "foo": "bar",
51
+ },
52
+ },
53
+ ]
54
+ `);
40
55
  });
41
56
  });
42
57
  describe('when request fails with error messages', () => {
@@ -53,7 +68,13 @@ describe('apiRequestV4', () => {
53
68
  return expect((0, apiRequestV4_1.apiRequestV4)({
54
69
  accessToken: 'myAccessToken',
55
70
  githubApiBaseUrlV4: 'http://localhost/graphql',
56
- query: 'query MyQuery{ foo }',
71
+ query: (0, graphql_tag_1.default) `
72
+ query MyQuery {
73
+ viewer {
74
+ login
75
+ }
76
+ }
77
+ `,
57
78
  variables: {
58
79
  foo: 'bar',
59
80
  },
@@ -72,7 +93,13 @@ describe('apiRequestV4', () => {
72
93
  return expect((0, apiRequestV4_1.apiRequestV4)({
73
94
  accessToken: 'myAccessToken',
74
95
  githubApiBaseUrlV4: 'http://localhost/graphql',
75
- query: 'query MyQuery{ foo }',
96
+ query: (0, graphql_tag_1.default) `
97
+ query MyQuery {
98
+ viewer {
99
+ login
100
+ }
101
+ }
102
+ `,
76
103
  variables: {
77
104
  foo: 'bar',
78
105
  },
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.disablePullRequestAutoMerge = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const FetchPullRequestId_1 = require("./FetchPullRequestId");
5
9
  const apiRequestV4_1 = require("./apiRequestV4");
6
10
  async function disablePullRequestAutoMerge(options, pullNumber) {
7
11
  const { accessToken, githubApiBaseUrlV4 } = options;
8
12
  const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, pullNumber);
9
- const query = /* GraphQL */ `
13
+ const query = (0, graphql_tag_1.default) `
10
14
  mutation DisablePullRequestAutoMerge($pullRequestId: ID!) {
11
15
  disablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId }) {
12
16
  pullRequest {
@@ -4,7 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.enablePullRequestAutoMerge = void 0;
7
- const ora_1 = __importDefault(require("ora"));
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
+ const ora_1 = require("../../../ui/ora");
8
9
  const logger_1 = require("../../logger");
9
10
  const FetchPullRequestId_1 = require("./FetchPullRequestId");
10
11
  const apiRequestV4_1 = require("./apiRequestV4");
@@ -12,9 +13,9 @@ async function enablePullRequestAutoMerge(options, targetPullRequestNumber) {
12
13
  const { accessToken, githubApiBaseUrlV4, autoMergeMethod = 'merge', } = options;
13
14
  const text = `Enabling auto merging via ${options.autoMergeMethod}`;
14
15
  logger_1.logger.info(text);
15
- const spinner = (0, ora_1.default)(text).start();
16
+ const spinner = (0, ora_1.ora)(options.ci, text).start();
16
17
  const pullRequestId = await (0, FetchPullRequestId_1.fetchPullRequestId)(options, targetPullRequestNumber);
17
- const query = /* GraphQL */ `
18
+ const query = (0, graphql_tag_1.default) `
18
19
  mutation EnablePullRequestAutoMerge(
19
20
  $pullRequestId: ID!
20
21
  $mergeMethod: PullRequestMergeMethod!
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchAuthorId = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const apiRequestV4_1 = require("./apiRequestV4");
5
9
  async function fetchAuthorId({ accessToken, author, githubApiBaseUrlV4 = 'https://api.github.com/graphql', }) {
6
10
  if (author === null) {
7
11
  return null;
8
12
  }
9
- const query = /* GraphQL */ `
13
+ const query = (0, graphql_tag_1.default) `
10
14
  query AuthorId($author: String!) {
11
15
  user(login: $author) {
12
16
  id
@@ -13,7 +13,6 @@ describe('allFetchers', () => {
13
13
  const commitsByAuthor = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
14
14
  accessToken: devAccessToken,
15
15
  author: 'sqren',
16
- historicalBranchLabelMappings: [],
17
16
  maxNumber: 1,
18
17
  repoName: 'kibana',
19
18
  repoOwner: 'elastic',
@@ -34,7 +33,6 @@ describe('allFetchers', () => {
34
33
  accessToken: devAccessToken,
35
34
  pullNumber: commitByAuthor.sourcePullRequest.number,
36
35
  sourceBranch: 'master',
37
- historicalBranchLabelMappings: [],
38
36
  });
39
37
  expect(commitByAuthor).toEqual(commitByPullNumber);
40
38
  });
@@ -45,7 +43,6 @@ describe('allFetchers', () => {
45
43
  accessToken: devAccessToken,
46
44
  sha: commitByAuthor.sourceCommit.sha,
47
45
  sourceBranch: 'main',
48
- historicalBranchLabelMappings: [],
49
46
  });
50
47
  expect(commitByAuthor).toEqual(commitBySha);
51
48
  });
@@ -4,7 +4,6 @@ export declare function fetchCommitByPullNumber(options: {
4
4
  accessToken: string;
5
5
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
6
6
  githubApiBaseUrlV4?: string;
7
- historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
8
7
  pullNumber: number;
9
8
  repoName: string;
10
9
  repoOwner: string;
@@ -1,12 +1,17 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchCommitByPullNumber = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const HandledError_1 = require("../../../HandledError");
9
+ const remoteConfig_1 = require("../../../remoteConfig");
5
10
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
6
11
  const apiRequestV4_1 = require("../apiRequestV4");
7
12
  async function fetchCommitByPullNumber(options) {
8
13
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', pullNumber, repoName, repoOwner, } = options;
9
- const query = /* GraphQL */ `
14
+ const query = (0, graphql_tag_1.default) `
10
15
  query CommitByPullNumber(
11
16
  $repoOwner: String!
12
17
  $repoName: String!
@@ -21,18 +26,24 @@ async function fetchCommitByPullNumber(options) {
21
26
  }
22
27
  }
23
28
 
24
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
29
+ ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
25
30
  `;
26
- const res = await (0, apiRequestV4_1.apiRequestV4)({
27
- githubApiBaseUrlV4,
28
- accessToken,
29
- query,
30
- variables: {
31
- repoOwner,
32
- repoName,
33
- pullNumber,
34
- },
35
- });
31
+ let res;
32
+ try {
33
+ res = await (0, apiRequestV4_1.apiRequestV4)({
34
+ githubApiBaseUrlV4,
35
+ accessToken,
36
+ query,
37
+ variables: {
38
+ repoOwner,
39
+ repoName,
40
+ pullNumber,
41
+ },
42
+ });
43
+ }
44
+ catch (e) {
45
+ res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
46
+ }
36
47
  const pullRequestNode = res.repository.pullRequest;
37
48
  if (!pullRequestNode) {
38
49
  throw new HandledError_1.HandledError(`The PR #${pullNumber} does not exist`);
@@ -18,11 +18,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
21
  Object.defineProperty(exports, "__esModule", { value: true });
25
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
22
+ const graphql_1 = require("graphql");
26
23
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
27
24
  const apiRequestV4Module = __importStar(require("../apiRequestV4"));
28
25
  const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
@@ -42,16 +39,13 @@ describe('fetchCommitByPullNumber', () => {
42
39
  accessToken: devAccessToken,
43
40
  pullNumber: 121633,
44
41
  sourceBranch: 'master',
45
- historicalBranchLabelMappings: [],
46
42
  });
47
43
  });
48
44
  it('makes the right queries', () => {
49
45
  const queries = spy.mock.calls.reduce((acc, call) => {
50
46
  const query = call[0].query;
51
- const ast = (0, graphql_tag_1.default)(query);
52
- //@ts-expect-error
53
- const name = ast.definitions[0].name.value;
54
- return { ...acc, [name]: query };
47
+ const name = apiRequestV4Module.getQueryName(query);
48
+ return { ...acc, [name]: (0, graphql_1.print)(query) };
55
49
  }, {});
56
50
  const queryNames = Object.keys(queries);
57
51
  expect(queryNames).toEqual(['CommitByPullNumber']);
@@ -71,7 +65,6 @@ describe('fetchCommitByPullNumber', () => {
71
65
  repoName: 'backport-e2e',
72
66
  repoOwner: 'backport-org',
73
67
  sourceBranch: 'main',
74
- historicalBranchLabelMappings: [],
75
68
  };
76
69
  const expectedCommit = {
77
70
  sourceCommit: {
@@ -122,7 +115,6 @@ describe('fetchCommitByPullNumber', () => {
122
115
  repoName: 'backport-e2e',
123
116
  repoOwner: 'backport-org',
124
117
  sourceBranch: 'main',
125
- historicalBranchLabelMappings: [],
126
118
  };
127
119
  await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`The PR #11 is not merged`);
128
120
  });
@@ -135,7 +127,6 @@ describe('fetchCommitByPullNumber', () => {
135
127
  repoName: 'backport-e2e',
136
128
  repoOwner: 'backport-org',
137
129
  sourceBranch: 'main',
138
- historicalBranchLabelMappings: [],
139
130
  };
140
131
  await expect((0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)(options)).rejects.toThrowError(`Could not resolve to a PullRequest with the number of 9999999999999. (Github API v4)`);
141
132
  });
@@ -4,7 +4,6 @@ export declare function fetchCommitBySha(options: {
4
4
  accessToken: string;
5
5
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
6
6
  githubApiBaseUrlV4?: string;
7
- historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
8
7
  repoName: string;
9
8
  repoOwner: string;
10
9
  sha: string;
@@ -1,12 +1,17 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.fetchCommitBySha = void 0;
7
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
4
8
  const HandledError_1 = require("../../../HandledError");
9
+ const remoteConfig_1 = require("../../../remoteConfig");
5
10
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
6
11
  const apiRequestV4_1 = require("../apiRequestV4");
7
12
  async function fetchCommitBySha(options) {
8
13
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
9
- const query = /* GraphQL */ `
14
+ const query = (0, graphql_tag_1.default) `
10
15
  query CommitsBySha($repoOwner: String!, $repoName: String!, $sha: String!) {
11
16
  repository(owner: $repoOwner, name: $repoName) {
12
17
  object(expression: $sha) {
@@ -15,18 +20,24 @@ async function fetchCommitBySha(options) {
15
20
  }
16
21
  }
17
22
 
18
- ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
23
+ ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
19
24
  `;
20
- const res = await (0, apiRequestV4_1.apiRequestV4)({
21
- githubApiBaseUrlV4,
22
- accessToken,
23
- query,
24
- variables: {
25
- repoOwner,
26
- repoName,
27
- sha,
28
- },
29
- });
25
+ let res;
26
+ try {
27
+ res = await (0, apiRequestV4_1.apiRequestV4)({
28
+ githubApiBaseUrlV4,
29
+ accessToken,
30
+ query,
31
+ variables: {
32
+ repoOwner,
33
+ repoName,
34
+ sha,
35
+ },
36
+ });
37
+ }
38
+ catch (e) {
39
+ res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
40
+ }
30
41
  const sourceCommit = res.repository.object;
31
42
  if (!sourceCommit) {
32
43
  throw new HandledError_1.HandledError(`No commit found on branch "${sourceBranch}" with sha "${sha}"`);
@@ -18,11 +18,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
21
  Object.defineProperty(exports, "__esModule", { value: true });
25
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
22
+ const graphql_1 = require("graphql");
26
23
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
27
24
  const apiRequestV4Module = __importStar(require("../apiRequestV4"));
28
25
  const fetchCommitBySha_1 = require("./fetchCommitBySha");
@@ -42,16 +39,14 @@ describe('fetchCommitBySha', () => {
42
39
  accessToken: devAccessToken,
43
40
  sha: 'd421ddcf6157150596581c7885afa3690cec6339',
44
41
  sourceBranch: 'main',
45
- historicalBranchLabelMappings: [],
46
42
  });
47
43
  });
48
44
  it('makes the right queries', () => {
49
45
  const queries = spy.mock.calls.reduce((acc, call) => {
50
46
  const query = call[0].query;
51
- const ast = (0, graphql_tag_1.default)(query);
52
47
  //@ts-expect-error
53
- const name = ast.definitions[0].name.value;
54
- return { ...acc, [name]: query };
48
+ const name = query.definitions[0].name.value;
49
+ return { ...acc, [name]: (0, graphql_1.print)(query) };
55
50
  }, {});
56
51
  const queryNames = Object.keys(queries);
57
52
  expect(queryNames).toEqual(['CommitsBySha']);
@@ -98,7 +93,6 @@ describe('fetchCommitBySha', () => {
98
93
  accessToken: devAccessToken,
99
94
  sha: 'cb6fbc0',
100
95
  sourceBranch: 'master',
101
- historicalBranchLabelMappings: [],
102
96
  })).toEqual(expectedCommit);
103
97
  });
104
98
  it('throws if sha does not exist', async () => {
@@ -108,7 +102,6 @@ describe('fetchCommitBySha', () => {
108
102
  accessToken: devAccessToken,
109
103
  sha: 'fc22f59',
110
104
  sourceBranch: 'main',
111
- historicalBranchLabelMappings: [],
112
105
  })).rejects.toThrowError('No commit found on branch "main" with sha "fc22f59"');
113
106
  });
114
107
  it('throws if sha is invalid', async () => {
@@ -118,7 +111,6 @@ describe('fetchCommitBySha', () => {
118
111
  accessToken: devAccessToken,
119
112
  sha: 'myCommitSha',
120
113
  sourceBranch: 'main',
121
- historicalBranchLabelMappings: [],
122
114
  })).rejects.toThrowError('No commit found on branch "main" with sha "myCommitSha"');
123
115
  });
124
116
  });
@@ -6,7 +6,6 @@ export declare function fetchCommitsByAuthor(options: {
6
6
  branchLabelMapping?: ValidConfigOptions['branchLabelMapping'];
7
7
  commitPaths?: string[];
8
8
  githubApiBaseUrlV4?: string;
9
- historicalBranchLabelMappings: ValidConfigOptions['historicalBranchLabelMappings'];
10
9
  maxNumber?: number;
11
10
  repoName: string;
12
11
  repoOwner: string;