backport 6.1.1 → 6.1.5

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 (81) hide show
  1. package/README.md +83 -70
  2. package/dist/entrypoint.module.d.ts +4 -1
  3. package/dist/entrypoint.module.js +10 -4
  4. package/dist/entrypoint.module.private.test.js +4 -1
  5. package/dist/main.js +5 -1
  6. package/dist/options/ConfigOptions.d.ts +3 -0
  7. package/dist/options/cliArgs.d.ts +5 -1
  8. package/dist/options/cliArgs.js +24 -2
  9. package/dist/options/cliArgs.test.js +0 -7
  10. package/dist/options/config/config.d.ts +7 -1
  11. package/dist/options/config/config.js +2 -2
  12. package/dist/options/config/config.test.js +1 -1
  13. package/dist/options/config/globalConfig.d.ts +1 -1
  14. package/dist/options/config/globalConfig.js +4 -8
  15. package/dist/options/config/readConfigFile.d.ts +4 -1
  16. package/dist/options/options.d.ts +10 -1
  17. package/dist/options/options.js +10 -2
  18. package/dist/options/options.test.js +113 -123
  19. package/dist/runSequentially.test.js +8 -5
  20. package/dist/services/HandledError.d.ts +1 -1
  21. package/dist/services/env.d.ts +2 -3
  22. package/dist/services/env.js +9 -10
  23. package/dist/services/env.test.js +0 -6
  24. package/dist/services/git.d.ts +2 -1
  25. package/dist/services/git.js +5 -3
  26. package/dist/services/github/v3/createPullRequest.js +1 -1
  27. package/dist/services/github/v3/createPullRequest.test.js +3 -3
  28. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  29. package/dist/services/github/v3/createStatusComment.js +50 -27
  30. package/dist/services/github/v3/createStatusComment.test.js +155 -73
  31. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  32. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  33. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  34. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  35. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  36. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  37. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  38. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  39. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  40. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  41. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  42. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  43. package/dist/services/github/v4/fetchProjectConfig.d.ts +1 -1
  44. package/dist/services/github/v4/fetchProjectConfig.js +3 -3
  45. package/dist/services/github/v4/fetchProjectConfig.private.test.js +5 -5
  46. package/dist/services/github/v4/fetchRemoteProjectConfig.d.ts +8 -0
  47. package/dist/services/github/v4/fetchRemoteProjectConfig.js +56 -0
  48. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.d.ts +1 -0
  49. package/dist/services/github/v4/fetchRemoteProjectConfig.private.test.js +52 -0
  50. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.d.ts +3 -0
  51. package/dist/services/github/v4/getOptionsFromGithub/getOptionsFromGithub.js +0 -7
  52. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  53. package/dist/services/logger.d.ts +0 -1
  54. package/dist/services/logger.js +3 -3
  55. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  56. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  57. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
  58. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  59. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  60. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  61. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  62. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  63. package/dist/test/inquirer.private.test.js +4 -15
  64. package/dist/test/integration/integration.private.test.js +2 -2
  65. package/dist/test/nockHelpers.js +1 -3
  66. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  67. package/dist/todo-delete.d.ts +1 -0
  68. package/dist/todo-delete.js +17 -0
  69. package/dist/ui/cherrypickAndCreateTargetPullRequest.d.ts +0 -9
  70. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +11 -48
  71. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +224 -260
  72. package/dist/ui/getCommits.js +1 -1
  73. package/dist/ui/getCommitsWithoutBackports.d.ts +11 -0
  74. package/dist/ui/getCommitsWithoutBackports.js +68 -0
  75. package/dist/ui/getCommitsWithoutBackports.test.d.ts +1 -0
  76. package/dist/ui/getCommitsWithoutBackports.test.js +259 -0
  77. package/dist/ui/maybeSetupRepo.js +0 -6
  78. package/dist/utils/redact.d.ts +1 -0
  79. package/dist/utils/redact.js +7 -0
  80. package/package.json +3 -3
  81. package/yarn.lock +462 -284
@@ -7,13 +7,13 @@ const apiRequestV4_1 = require("../apiRequestV4");
7
7
  async function fetchCommitBySha(options) {
8
8
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', repoName, repoOwner, sha, sourceBranch, } = options;
9
9
  const query = /* GraphQL */ `
10
- query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
11
- repository(owner: $repoOwner, name: $repoName) {
12
- object(expression: $oid) {
13
- ...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
10
+ query CommitsBySha($repoOwner: String!, $repoName: String!, $oid: String!) {
11
+ repository(owner: $repoOwner, name: $repoName) {
12
+ object(expression: $oid) {
13
+ ...SourceCommitWithTargetPullRequest
14
+ }
14
15
  }
15
16
  }
16
- }
17
17
 
18
18
  ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
19
19
  `;
@@ -1,12 +1,68 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
2
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
3
26
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
27
+ const apiRequestV4Module = __importStar(require("../apiRequestV4"));
4
28
  const fetchCommitBySha_1 = require("./fetchCommitBySha");
5
29
  describe('fetchCommitBySha', () => {
6
30
  let devAccessToken;
7
31
  beforeEach(async () => {
8
32
  devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
33
  });
34
+ describe('snapshot request/response', () => {
35
+ let spy;
36
+ let commit;
37
+ beforeEach(async () => {
38
+ spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
39
+ commit = await (0, fetchCommitBySha_1.fetchCommitBySha)({
40
+ repoOwner: 'elastic',
41
+ repoName: 'kibana',
42
+ accessToken: devAccessToken,
43
+ sha: 'd421ddcf6157150596581c7885afa3690cec6339',
44
+ sourceBranch: 'main',
45
+ historicalBranchLabelMappings: [],
46
+ });
47
+ });
48
+ it('makes the right queries', () => {
49
+ const queries = spy.mock.calls.reduce((acc, call) => {
50
+ 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 };
55
+ }, {});
56
+ const queryNames = Object.keys(queries);
57
+ expect(queryNames).toEqual(['CommitsBySha']);
58
+ queryNames.forEach((name) => {
59
+ expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
60
+ });
61
+ });
62
+ it('returns the correct response', async () => {
63
+ expect(commit).toMatchSnapshot();
64
+ });
65
+ });
10
66
  it('should return single commit with pull request', async () => {
11
67
  await expect(await (0, fetchCommitBySha_1.fetchCommitBySha)({
12
68
  repoOwner: 'elastic',
@@ -28,6 +84,10 @@ describe('fetchCommitBySha', () => {
28
84
  state: 'MERGED',
29
85
  number: 71014,
30
86
  url: 'https://github.com/elastic/kibana/pull/71014',
87
+ mergeCommit: {
88
+ message: '[APM] Add API tests (#70740) (#71014)',
89
+ sha: 'd15242be682582e58cd69f6b7707565434e99293',
90
+ },
31
91
  },
32
92
  ],
33
93
  });
@@ -11,6 +11,8 @@ export declare function fetchCommitsByAuthor(options: {
11
11
  repoName: string;
12
12
  repoOwner: string;
13
13
  sourceBranch: string;
14
+ dateSince: string | null;
15
+ dateUntil: string | null;
14
16
  }): Promise<Commit[]>;
15
17
  export interface CommitByAuthorResponse {
16
18
  repository: {
@@ -8,7 +8,7 @@ const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
8
8
  const apiRequestV4_1 = require("../apiRequestV4");
9
9
  const fetchAuthorId_1 = require("../fetchAuthorId");
10
10
  function fetchByCommitPath({ options, authorId, commitPath, }) {
11
- const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, } = options;
11
+ const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, dateSince, dateUntil, } = options;
12
12
  const query = /* GraphQL */ `
13
13
  query CommitsByAuthor(
14
14
  $repoOwner: String!
@@ -17,6 +17,8 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
17
17
  $sourceBranch: String!
18
18
  $authorId: ID
19
19
  $commitPath: String
20
+ $dateSince: GitTimestamp
21
+ $dateUntil: GitTimestamp
20
22
  ) {
21
23
  repository(owner: $repoOwner, name: $repoName) {
22
24
  ref(qualifiedName: $sourceBranch) {
@@ -26,10 +28,12 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
26
28
  first: $maxNumber
27
29
  author: { id: $authorId }
28
30
  path: $commitPath
31
+ since: $dateSince
32
+ until: $dateUntil
29
33
  ) {
30
34
  edges {
31
35
  node {
32
- ...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
36
+ ...SourceCommitWithTargetPullRequest
33
37
  }
34
38
  }
35
39
  }
@@ -41,18 +45,21 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
41
45
 
42
46
  ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
43
47
  `;
48
+ const variables = {
49
+ repoOwner,
50
+ repoName,
51
+ sourceBranch,
52
+ maxNumber,
53
+ authorId,
54
+ commitPath,
55
+ dateSince,
56
+ dateUntil,
57
+ };
44
58
  return (0, apiRequestV4_1.apiRequestV4)({
45
59
  githubApiBaseUrlV4,
46
60
  accessToken,
47
61
  query,
48
- variables: {
49
- repoOwner,
50
- repoName,
51
- sourceBranch,
52
- maxNumber,
53
- authorId,
54
- commitPath,
55
- },
62
+ variables,
56
63
  });
57
64
  }
58
65
  async function fetchCommitsByAuthor(options) {
@@ -1,12 +1,72 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
2
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
+ const graphql_tag_1 = __importDefault(require("graphql-tag"));
3
26
  const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
27
+ const apiRequestV4Module = __importStar(require("../apiRequestV4"));
4
28
  const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
5
29
  describe('fetchCommitsByAuthor', () => {
6
30
  let devAccessToken;
7
31
  beforeAll(async () => {
8
32
  devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
33
  });
34
+ describe('snapshot request/response', () => {
35
+ let spy;
36
+ let commits;
37
+ beforeEach(async () => {
38
+ spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
39
+ commits = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
40
+ accessToken: devAccessToken,
41
+ author: 'sqren',
42
+ historicalBranchLabelMappings: [],
43
+ maxNumber: 10,
44
+ repoName: 'kibana',
45
+ repoOwner: 'elastic',
46
+ sourceBranch: 'main',
47
+ dateSince: '2021-01-10T00:00:00Z',
48
+ dateUntil: '2022-01-01T00:00:00Z',
49
+ commitPaths: [],
50
+ });
51
+ });
52
+ it('makes the right queries', () => {
53
+ const queries = spy.mock.calls.reduce((acc, call) => {
54
+ const query = call[0].query;
55
+ const ast = (0, graphql_tag_1.default)(query);
56
+ //@ts-expect-error
57
+ const name = ast.definitions[0].name.value;
58
+ return { ...acc, [name]: query };
59
+ }, {});
60
+ const queryNames = Object.keys(queries);
61
+ expect(queryNames).toEqual(['AuthorId', 'CommitsByAuthor']);
62
+ queryNames.forEach((name) => {
63
+ expect(queries[name]).toMatchSnapshot(`Query: ${name}`);
64
+ });
65
+ });
66
+ it('returns the correct response', async () => {
67
+ expect(commits).toMatchSnapshot();
68
+ });
69
+ });
10
70
  describe('commitPaths', () => {
11
71
  const getOptions = () => ({
12
72
  accessToken: devAccessToken,
@@ -16,6 +76,8 @@ describe('fetchCommitsByAuthor', () => {
16
76
  repoName: 'repo-with-different-commit-paths',
17
77
  repoOwner: 'backport-org',
18
78
  sourceBranch: 'main',
79
+ dateSince: null,
80
+ dateUntil: null,
19
81
  });
20
82
  const getCommitMessages = (commits) => {
21
83
  return commits.map((c) => c.originalMessage.replace(/(\r\n|\n|\r)/gm, ''));
@@ -90,6 +152,8 @@ describe('fetchCommitsByAuthor', () => {
90
152
  repoOwner: 'backport-org',
91
153
  sourceBranch: 'master',
92
154
  author: null,
155
+ dateSince: null,
156
+ dateUntil: null,
93
157
  });
94
158
  });
95
159
  it('returns related OPEN PRs', async () => {
@@ -111,12 +175,20 @@ describe('fetchCommitsByAuthor', () => {
111
175
  state: 'MERGED',
112
176
  number: 6,
113
177
  url: 'https://github.com/backport-org/backport-e2e/pull/6',
178
+ mergeCommit: {
179
+ message: 'Add 🍏 emoji (#5) (#6)',
180
+ sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
181
+ },
114
182
  },
115
183
  {
116
184
  branch: '7.8',
117
185
  state: 'MERGED',
118
186
  number: 7,
119
187
  url: 'https://github.com/backport-org/backport-e2e/pull/7',
188
+ mergeCommit: {
189
+ message: 'Add 🍏 emoji (#5) (#7)',
190
+ sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
191
+ },
120
192
  },
121
193
  ]);
122
194
  });
@@ -16,6 +16,8 @@ const defaultOptions = {
16
16
  repoName: 'kibana',
17
17
  repoOwner: 'elastic',
18
18
  sourceBranch: 'source-branch-from-options',
19
+ dateSince: null,
20
+ dateUntil: null,
19
21
  };
20
22
  const authorIdMockData = { user: { id: 'myUserId' } };
21
23
  describe('fetchCommitsByAuthor', () => {
@@ -72,6 +74,10 @@ describe('fetchCommitsByAuthor', () => {
72
74
  state: 'MERGED',
73
75
  number: 99,
74
76
  url: 'https://github.com/elastic/kibana/pull/99',
77
+ mergeCommit: {
78
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
79
+ sha: 'target-merge-commit-sha',
80
+ },
75
81
  },
76
82
  ],
77
83
  sourceBranch: 'master',
@@ -13,7 +13,7 @@ async function fetchPullRequestBySearchQuery(options) {
13
13
  nodes {
14
14
  ... on PullRequest {
15
15
  mergeCommit {
16
- ...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
16
+ ...SourceCommitWithTargetPullRequest
17
17
  }
18
18
  }
19
19
  }
@@ -22,16 +22,17 @@ async function fetchPullRequestBySearchQuery(options) {
22
22
 
23
23
  ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.source}
24
24
  `;
25
- const authorFilter = author ? `author:${author}` : '';
26
- const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName} ${authorFilter} ${prFilter} base:${sourceBranch}`;
25
+ const authorFilter = author ? ` author:${author}` : '';
26
+ const searchQuery = `type:pr is:merged sort:updated-desc repo:${repoOwner}/${repoName}${authorFilter} ${prFilter} base:${sourceBranch}`;
27
+ const variables = {
28
+ query: searchQuery,
29
+ maxNumber: maxNumber,
30
+ };
27
31
  const res = await (0, apiRequestV4_1.apiRequestV4)({
28
32
  githubApiBaseUrlV4,
29
33
  accessToken,
30
34
  query,
31
- variables: {
32
- query: searchQuery,
33
- maxNumber: maxNumber,
34
- },
35
+ variables,
35
36
  });
36
37
  const commits = res.search.nodes.map((pullRequestNode) => {
37
38
  const sourceCommit = pullRequestNode.mergeCommit;
@@ -57,12 +57,20 @@ describe('fetchPullRequestBySearchQuery', () => {
57
57
  state: 'MERGED',
58
58
  number: 6,
59
59
  url: 'https://github.com/backport-org/backport-e2e/pull/6',
60
+ mergeCommit: {
61
+ message: 'Add 🍏 emoji (#5) (#6)',
62
+ sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
63
+ },
60
64
  },
61
65
  {
62
66
  branch: '7.8',
63
67
  state: 'MERGED',
64
68
  number: 7,
65
69
  url: 'https://github.com/backport-org/backport-e2e/pull/7',
70
+ mergeCommit: {
71
+ message: 'Add 🍏 emoji (#5) (#7)',
72
+ sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
73
+ },
66
74
  },
67
75
  ],
68
76
  originalMessage: 'Add 🍏 emoji (#5)',
@@ -1,5 +1,5 @@
1
1
  import { ConfigFileOptions } from '../../../entrypoint.module';
2
- export declare function fetchProjectConfig(options: {
2
+ export declare function fetchRemoteProjectConfig(options: {
3
3
  accessToken: string;
4
4
  githubApiBaseUrlV4?: string;
5
5
  repoName: string;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchProjectConfig = void 0;
3
+ exports.fetchRemoteProjectConfig = void 0;
4
4
  const readConfigFile_1 = require("../../../options/config/readConfigFile");
5
5
  const apiRequestV4_1 = require("./apiRequestV4");
6
- async function fetchProjectConfig(options) {
6
+ async function fetchRemoteProjectConfig(options) {
7
7
  const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch } = options;
8
8
  const query = /* GraphQL */ `
9
9
  query ProjectConfig(
@@ -53,4 +53,4 @@ async function fetchProjectConfig(options) {
53
53
  throw new Error('Project config does not exist');
54
54
  }
55
55
  }
56
- exports.fetchProjectConfig = fetchProjectConfig;
56
+ exports.fetchRemoteProjectConfig = fetchRemoteProjectConfig;
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
4
- const fetchProjectConfig_1 = require("./fetchProjectConfig");
5
- describe('fetchProjectConfig', () => {
4
+ const fetchRemoteProjectConfig_1 = require("./fetchRemoteProjectConfig");
5
+ describe('fetchRemoteProjectConfig', () => {
6
6
  let devAccessToken;
7
7
  beforeEach(async () => {
8
8
  devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
9
  });
10
10
  it('returns the backport config from "main" branch', async () => {
11
- const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
11
+ const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
12
12
  repoOwner: 'backport-org',
13
13
  repoName: 'repo-with-project-config',
14
14
  accessToken: devAccessToken,
@@ -28,7 +28,7 @@ describe('fetchProjectConfig', () => {
28
28
  });
29
29
  });
30
30
  it('returns the backport config from "branch-with-legacy-config" branch', async () => {
31
- const projectConfig = await (0, fetchProjectConfig_1.fetchProjectConfig)({
31
+ const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
32
32
  repoOwner: 'backport-org',
33
33
  repoName: 'repo-with-project-config',
34
34
  accessToken: devAccessToken,
@@ -41,7 +41,7 @@ describe('fetchProjectConfig', () => {
41
41
  });
42
42
  });
43
43
  it('throws an error if config does not exist', async () => {
44
- const promise = (0, fetchProjectConfig_1.fetchProjectConfig)({
44
+ const promise = (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
45
45
  repoOwner: 'backport-org',
46
46
  repoName: 'repo-with-project-config',
47
47
  accessToken: devAccessToken,
@@ -0,0 +1,8 @@
1
+ import { ConfigFileOptions } from '../../../entrypoint.module';
2
+ export declare function fetchRemoteProjectConfig(options: {
3
+ accessToken: string;
4
+ githubApiBaseUrlV4?: string;
5
+ repoName: string;
6
+ repoOwner: string;
7
+ sourceBranch: string;
8
+ }): Promise<ConfigFileOptions>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchRemoteProjectConfig = void 0;
4
+ const readConfigFile_1 = require("../../../options/config/readConfigFile");
5
+ const apiRequestV4_1 = require("./apiRequestV4");
6
+ async function fetchRemoteProjectConfig(options) {
7
+ const { accessToken, githubApiBaseUrlV4, repoName, repoOwner, sourceBranch } = options;
8
+ const query = /* GraphQL */ `
9
+ query ProjectConfig(
10
+ $repoOwner: String!
11
+ $repoName: String!
12
+ $sourceBranch: String!
13
+ ) {
14
+ repository(owner: $repoOwner, name: $repoName) {
15
+ ref(qualifiedName: $sourceBranch) {
16
+ target {
17
+ ... on Commit {
18
+ history(first: 1, path: ".backportrc.json") {
19
+ edges {
20
+ remoteConfig: node {
21
+ file(path: ".backportrc.json") {
22
+ ... on TreeEntry {
23
+ object {
24
+ ... on Blob {
25
+ text
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ `;
39
+ try {
40
+ const res = await (0, apiRequestV4_1.apiRequestV4)({
41
+ githubApiBaseUrlV4,
42
+ accessToken,
43
+ query,
44
+ variables: {
45
+ repoOwner,
46
+ repoName,
47
+ sourceBranch,
48
+ },
49
+ });
50
+ return (0, readConfigFile_1.withConfigMigrations)(JSON.parse(res.repository.ref.target.history.edges[0].remoteConfig.file.object.text));
51
+ }
52
+ catch (e) {
53
+ throw new Error('Project config does not exist');
54
+ }
55
+ }
56
+ exports.fetchRemoteProjectConfig = fetchRemoteProjectConfig;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../test/private/getDevAccessToken");
4
+ const fetchRemoteProjectConfig_1 = require("./fetchRemoteProjectConfig");
5
+ describe('fetchRemoteProjectConfig', () => {
6
+ let devAccessToken;
7
+ beforeEach(async () => {
8
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
9
+ });
10
+ it('returns the backport config from "main" branch', async () => {
11
+ const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
12
+ repoOwner: 'backport-org',
13
+ repoName: 'repo-with-project-config',
14
+ accessToken: devAccessToken,
15
+ sourceBranch: 'main',
16
+ });
17
+ expect(projectConfig).toEqual({
18
+ autoMerge: true,
19
+ autoMergeMethod: 'squash',
20
+ branchLabelMapping: {
21
+ '^v(\\d+).(\\d+).\\d+$': '$1.$2',
22
+ '^v8.1.0$': 'main',
23
+ },
24
+ targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
25
+ targetPRLabels: ['backport'],
26
+ repoOwner: 'backport-org',
27
+ repoName: 'repo-with-project-config',
28
+ });
29
+ });
30
+ it('returns the backport config from "branch-with-legacy-config" branch', async () => {
31
+ const projectConfig = await (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
32
+ repoOwner: 'backport-org',
33
+ repoName: 'repo-with-project-config',
34
+ accessToken: devAccessToken,
35
+ sourceBranch: 'branch-with-legacy-config',
36
+ });
37
+ expect(projectConfig).toEqual({
38
+ targetBranchChoices: ['main', '8.0', '7.17', '7.16'],
39
+ repoOwner: 'backport-org',
40
+ repoName: 'repo-with-project-config',
41
+ });
42
+ });
43
+ it('throws an error if config does not exist', async () => {
44
+ const promise = (0, fetchRemoteProjectConfig_1.fetchRemoteProjectConfig)({
45
+ repoOwner: 'backport-org',
46
+ repoName: 'repo-with-project-config',
47
+ accessToken: devAccessToken,
48
+ sourceBranch: 'branch-with-no-config',
49
+ });
50
+ await expect(promise).rejects.toThrowError('Project config does not exist');
51
+ });
52
+ });
@@ -28,9 +28,11 @@ export declare function getOptionsFromGithub(options: {
28
28
  }) => boolean | Promise<boolean>) | undefined;
29
29
  autoMerge?: boolean | undefined;
30
30
  autoMergeMethod?: string | undefined;
31
+ backportBinary?: string | undefined;
31
32
  cherrypickRef?: boolean | undefined;
32
33
  ci?: boolean | undefined;
33
34
  commitPaths?: string[] | undefined;
35
+ dir?: string | undefined;
34
36
  details?: boolean | undefined;
35
37
  editor?: string | undefined;
36
38
  fork?: boolean | undefined;
@@ -45,6 +47,7 @@ export declare function getOptionsFromGithub(options: {
45
47
  prDescription?: string | undefined;
46
48
  prFilter?: string | undefined;
47
49
  prTitle?: string | undefined;
50
+ publishStatusComment?: boolean | undefined;
48
51
  pullNumber?: number | undefined;
49
52
  repoName?: string | undefined;
50
53
  repoOwner?: string | undefined;
@@ -1,10 +1,6 @@
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.getOptionsFromGithub = void 0;
7
- const ora_1 = __importDefault(require("ora"));
8
4
  const readConfigFile_1 = require("../../../../options/config/readConfigFile");
9
5
  const filterEmpty_1 = require("../../../../utils/filterEmpty");
10
6
  const HandledError_1 = require("../../../HandledError");
@@ -16,7 +12,6 @@ const query_1 = require("./query");
16
12
  async function getOptionsFromGithub(options) {
17
13
  const { accessToken, githubApiBaseUrlV4, repoName, repoOwner } = options;
18
14
  let res;
19
- const spinner = (0, ora_1.default)().start('Initializing...');
20
15
  try {
21
16
  res = await (0, apiRequestV4_1.apiRequestV4)({
22
17
  githubApiBaseUrlV4,
@@ -25,10 +20,8 @@ async function getOptionsFromGithub(options) {
25
20
  variables: { repoOwner, repoName },
26
21
  handleError: false,
27
22
  });
28
- spinner.stop();
29
23
  }
30
24
  catch (e) {
31
- spinner.stop();
32
25
  const error = e;
33
26
  (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({
34
27
  error,
@@ -40,6 +40,10 @@ exports.commitsByAuthorMock = {
40
40
  nodes: [{ name: 'my-label-b' }],
41
41
  },
42
42
  number: 85,
43
+ sourceMergeCommit: {
44
+ oid: 'f3b618b9421fdecdb36862f907afbdd6344b361d',
45
+ message: 'Add witch (#85)',
46
+ },
43
47
  timelineItems: {
44
48
  edges: [],
45
49
  },
@@ -68,12 +72,24 @@ exports.commitsByAuthorMock = {
68
72
  },
69
73
  baseRefName: 'master',
70
74
  number: 80,
75
+ sourceMergeCommit: {
76
+ oid: '79cf18453ec32a4677009dcbab1c9c8c73fc14fe',
77
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
78
+ },
71
79
  timelineItems: {
72
80
  edges: [
73
81
  {
74
82
  node: {
75
83
  targetPullRequest: {
76
84
  __typename: 'PullRequest',
85
+ targetMergeCommit: {
86
+ oid: 'target-merge-commit-sha',
87
+ message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
88
+ },
89
+ repository: {
90
+ name: 'kibana',
91
+ owner: { login: 'elastic' },
92
+ },
77
93
  url: 'https://github.com/elastic/kibana/pull/99',
78
94
  title: 'some title',
79
95
  state: 'MERGED',
@@ -84,11 +100,6 @@ exports.commitsByAuthorMock = {
84
100
  {
85
101
  node: {
86
102
  targetCommit: {
87
- repository: {
88
- name: 'kibana',
89
- owner: { login: 'elastic' },
90
- },
91
- committedDate: '2021-12-23T00:00:00Z',
92
103
  oid: 'abc',
93
104
  message: 'Add SF mention (#80)\n\n* Add SF mention\r\n\r\n* Add several emojis!',
94
105
  },
@@ -9,7 +9,6 @@ export declare const logger: {
9
9
  debug: (message: string, meta?: unknown) => void;
10
10
  };
11
11
  export declare function updateLogger(options: ConfigFileOptions): void;
12
- export declare function redactAccessToken(str: string): string;
13
12
  export declare function initLogger(): {
14
13
  error: (message: string, meta?: unknown) => void;
15
14
  warn: (message: string, meta?: unknown) => void;