backport 6.1.3 → 6.1.4

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 (48) hide show
  1. package/dist/entrypoint.module.d.ts +2 -0
  2. package/dist/entrypoint.module.js +5 -1
  3. package/dist/entrypoint.module.private.test.js +4 -1
  4. package/dist/main.js +1 -1
  5. package/dist/options/cliArgs.d.ts +2 -0
  6. package/dist/options/cliArgs.js +14 -1
  7. package/dist/options/config/globalConfig.js +1 -1
  8. package/dist/options/options.d.ts +4 -0
  9. package/dist/options/options.js +3 -1
  10. package/dist/options/options.test.js +3 -1
  11. package/dist/runSequentially.test.js +7 -5
  12. package/dist/services/HandledError.d.ts +1 -1
  13. package/dist/services/git.d.ts +2 -1
  14. package/dist/services/git.js +4 -2
  15. package/dist/services/github/v3/createPullRequest.test.js +3 -3
  16. package/dist/services/github/v3/createStatusComment.d.ts +1 -1
  17. package/dist/services/github/v3/createStatusComment.js +31 -11
  18. package/dist/services/github/v3/createStatusComment.test.js +139 -86
  19. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.d.ts +1 -0
  20. package/dist/services/github/v4/fetchCommits/allFetchers.private.test.js +78 -0
  21. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.js +1 -1
  22. package/dist/services/github/v4/fetchCommits/fetchCommitByPullNumber.private.test.js +64 -0
  23. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.js +5 -5
  24. package/dist/services/github/v4/fetchCommits/fetchCommitBySha.private.test.js +60 -0
  25. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.d.ts +2 -0
  26. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.js +17 -10
  27. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.private.test.js +72 -0
  28. package/dist/services/github/v4/fetchCommits/fetchCommitsByAuthor.test.js +6 -0
  29. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.js +8 -7
  30. package/dist/services/github/v4/fetchCommits/fetchPullRequestBySearchQuery.private.test.js +8 -0
  31. package/dist/services/github/v4/mocks/commitsByAuthorMock.js +16 -5
  32. package/dist/services/sourceCommit/getExpectedTargetPullRequests.d.ts +4 -0
  33. package/dist/services/sourceCommit/getExpectedTargetPullRequests.js +8 -2
  34. package/dist/services/sourceCommit/getExpectedTargetPullRequests.test.js +20 -0
  35. package/dist/services/sourceCommit/getMockSourceCommit.d.ts +1 -0
  36. package/dist/services/sourceCommit/getMockSourceCommit.js +72 -46
  37. package/dist/services/sourceCommit/parseSourceCommit.d.ts +22 -8
  38. package/dist/services/sourceCommit/parseSourceCommit.js +29 -10
  39. package/dist/services/sourceCommit/parseSourceCommit.test.js +10 -2
  40. package/dist/test/integration/integration.private.test.js +2 -2
  41. package/dist/test/nockHelpers.js +1 -3
  42. package/dist/test/setupFiles/automatic-mocks.js +1 -0
  43. package/dist/ui/cherrypickAndCreateTargetPullRequest.js +3 -2
  44. package/dist/ui/cherrypickAndCreateTargetPullRequest.test.js +6 -4
  45. package/dist/ui/getCommits.js +1 -1
  46. package/dist/ui/getCommitsWithoutBackports.js +17 -2
  47. package/package.json +3 -3
  48. package/yarn.lock +462 -284
@@ -3,38 +3,47 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const HandledError_1 = require("../../HandledError");
4
4
  const createStatusComment_1 = require("./createStatusComment");
5
5
  describe('getCommentBody', () => {
6
- it('when an unknown error occurs', () => {
7
- expect((0, createStatusComment_1.getCommentBody)({
6
+ describe('when an unknown error occurs', () => {
7
+ const getParams = (opts) => ({
8
8
  options: {
9
9
  backportBinary: 'node scripts/backport',
10
+ ...opts,
10
11
  },
11
12
  pullNumber: 55,
12
13
  backportResponse: {
13
14
  status: 'failure',
14
15
  errorMessage: 'A terrible error occured',
15
16
  },
16
- })).toMatchInlineSnapshot(`
17
- "## 💔 Backport failed
18
- The pull request could not be backported due to the following error:
19
- \`A terrible error occured\`
17
+ });
18
+ it('posts a comment when running on ci', () => {
19
+ const params = getParams({ ci: true });
20
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
21
+ "## 💔 Backport failed
22
+ The pull request could not be backported due to the following error:
23
+ \`A terrible error occured\`
20
24
 
21
- ## How to fix
25
+ ### How to fix
26
+ Re-run the backport manually:
27
+ \`\`\`
28
+ node scripts/backport --pr 55
29
+ \`\`\`
22
30
 
23
- Re-run the backport manually:
24
- \`\`\`
25
- node scripts/backport --pr 55
26
- \`\`\`
27
-
28
- ### Questions ?
29
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
30
- `);
31
+ ### Questions ?
32
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
33
+ `);
34
+ });
35
+ it('does not post a comment when running manually', () => {
36
+ const params = getParams({ ci: false });
37
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
38
+ });
31
39
  });
32
- it('when all backports succeed', () => {
33
- expect((0, createStatusComment_1.getCommentBody)({
40
+ describe('when all backports succeed', () => {
41
+ const getParams = (opts) => ({
34
42
  options: {
35
43
  repoName: 'kibana',
36
44
  repoOwner: 'elastic',
37
45
  autoMerge: true,
46
+ ...opts,
38
47
  },
39
48
  pullNumber: 55,
40
49
  backportResponse: {
@@ -54,27 +63,48 @@ describe('getCommentBody', () => {
54
63
  },
55
64
  ],
56
65
  },
57
- })).toMatchInlineSnapshot(`
58
- "## 💚 All backports created successfully
66
+ });
67
+ it('posts a comment on ci', () => {
68
+ const params = getParams({ ci: true });
69
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
70
+ "## 💚 All backports created successfully
71
+
72
+ | Status | Branch | Result |
73
+ |:------:|:------:|:------|
74
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
75
+ |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
76
+
77
+ Note: Successful backport PRs will be merged automatically after passing CI.
59
78
 
60
- | Status | Branch | Result |
61
- |:------:|:------:|:------|
62
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
63
- |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
79
+ ### Questions ?
80
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
81
+ `);
82
+ });
83
+ it('posts a comment when running locally', () => {
84
+ const params = getParams({ ci: false });
85
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
86
+ "## 💚 All backports created successfully
64
87
 
65
- Note: Successful backport PRs will be merged automatically after passing CI.
88
+ | Status | Branch | Result |
89
+ |:------:|:------:|:------|
90
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr)|
91
+ |✅|7.1|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/66\\">](url-to-pr)|
66
92
 
67
- ### Questions ?
68
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
69
- `);
93
+ Note: Successful backport PRs will be merged automatically after passing CI.
94
+
95
+ ### Questions ?
96
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
97
+ `);
98
+ });
70
99
  });
71
- it('when all backports fail', () => {
72
- expect((0, createStatusComment_1.getCommentBody)({
100
+ describe('when all backports fail', () => {
101
+ const getParams = (opts) => ({
73
102
  options: {
74
103
  repoName: 'kibana',
75
104
  repoOwner: 'elastic',
76
105
  autoMerge: true,
77
106
  backportBinary: 'node scripts/backport',
107
+ ...opts,
78
108
  },
79
109
  pullNumber: 55,
80
110
  backportResponse: {
@@ -94,32 +124,40 @@ describe('getCommentBody', () => {
94
124
  },
95
125
  ],
96
126
  },
97
- })).toMatchInlineSnapshot(`
98
- "## 💔 Some backports could not be created
99
-
100
- | Status | Branch | Result |
101
- |:------:|:------:|:------|
102
- |❌|7.x|My boom error!|
103
- |❌|7.1|My boom error!|
127
+ });
128
+ it('posts a comment on CI', () => {
129
+ const params = getParams({ ci: true });
130
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
131
+ "## 💔 All backports failed
104
132
 
105
- ## How to fix
133
+ | Status | Branch | Result |
134
+ |:------:|:------:|:------|
135
+ |❌|7.x|My boom error!|
136
+ |❌|7.1|My boom error!|
106
137
 
107
- Re-run the backport manually:
108
- \`\`\`
109
- node scripts/backport --pr 55
110
- \`\`\`
138
+ ### How to fix
139
+ Re-run the backport manually:
140
+ \`\`\`
141
+ node scripts/backport --pr 55
142
+ \`\`\`
111
143
 
112
- ### Questions ?
113
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
114
- `);
144
+ ### Questions ?
145
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
146
+ `);
147
+ });
148
+ it('does not post a comment when running manaully', () => {
149
+ const params = getParams({ ci: false });
150
+ expect((0, createStatusComment_1.getCommentBody)(params)).toBe(undefined);
151
+ });
115
152
  });
116
- it('when some backports fail', () => {
117
- expect((0, createStatusComment_1.getCommentBody)({
153
+ describe('when some backports fail', () => {
154
+ const getParams = (opts) => ({
118
155
  options: {
119
156
  repoName: 'kibana',
120
157
  repoOwner: 'elastic',
121
158
  autoMerge: true,
122
159
  backportBinary: 'node scripts/backport',
160
+ ...opts,
123
161
  },
124
162
  pullNumber: 55,
125
163
  backportResponse: {
@@ -139,33 +177,41 @@ describe('getCommentBody', () => {
139
177
  },
140
178
  ],
141
179
  },
142
- })).toMatchInlineSnapshot(`
143
- "## 💔 Some backports could not be created
180
+ });
181
+ it('post a comment when running on CI', () => {
182
+ const params = getParams({ ci: true });
183
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
184
+ "## 💔 Some backports could not be created
144
185
 
145
- | Status | Branch | Result |
146
- |:------:|:------:|:------|
147
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
148
- |❌|7.1|My boom error!|
186
+ | Status | Branch | Result |
187
+ |:------:|:------:|:------|
188
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
189
+ |❌|7.1|My boom error!|
149
190
 
150
- ## How to fix
191
+ ### How to fix
192
+ Re-run the backport manually:
193
+ \`\`\`
194
+ node scripts/backport --pr 55
195
+ \`\`\`
196
+ Note: Successful backport PRs will be merged automatically after passing CI.
151
197
 
152
- Re-run the backport manually:
153
- \`\`\`
154
- node scripts/backport --pr 55
155
- \`\`\`
156
- Note: Successful backport PRs will be merged automatically after passing CI.
157
-
158
- ### Questions ?
159
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
160
- `);
198
+ ### Questions ?
199
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
200
+ `);
201
+ });
202
+ it('does not post a comment when running manually because some backports failed', () => {
203
+ const params = getParams({ ci: false });
204
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
205
+ });
161
206
  });
162
- it('when some backports fail due to conflicts', () => {
163
- expect((0, createStatusComment_1.getCommentBody)({
207
+ describe('when some backports fail due to conflicts', () => {
208
+ const getParams = (opts) => ({
164
209
  options: {
165
210
  repoName: 'kibana',
166
211
  repoOwner: 'elastic',
167
212
  autoMerge: true,
168
213
  backportBinary: 'node scripts/backport',
214
+ ...opts,
169
215
  },
170
216
  pullNumber: 55,
171
217
  backportResponse: {
@@ -182,7 +228,7 @@ describe('getCommentBody', () => {
182
228
  targetBranch: '7.1',
183
229
  errorMessage: 'My boom error!',
184
230
  error: new HandledError_1.HandledError('Boom!', {
185
- type: 'commitsWithoutBackports',
231
+ type: 'merge-conflict-due-to-missing-backports',
186
232
  commitsWithoutBackports: [
187
233
  {
188
234
  //@ts-expect-error
@@ -208,31 +254,38 @@ describe('getCommentBody', () => {
208
254
  targetBranch: '7.2',
209
255
  errorMessage: 'My boom error!',
210
256
  error: new HandledError_1.HandledError('Boom!', {
211
- type: 'commitsWithoutBackports',
257
+ type: 'merge-conflict-due-to-missing-backports',
212
258
  commitsWithoutBackports: [],
213
259
  }),
214
260
  },
215
261
  ],
216
262
  },
217
- })).toMatchInlineSnapshot(`
218
- "## 💔 Some backports could not be created
219
-
220
- | Status | Branch | Result |
221
- |:------:|:------:|:------|
222
- |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
223
- |❌|7.1|**Backport failed because of merge conflicts**<br><br>You might need to backport the following PRs to 7.1:<br> - [New Zealand commit message](url-to-pr-5)<br> - [Australia commit](url-to-pr-44)|
224
- |❌|7.2|**Backport failed because of merge conflicts**|
225
-
226
- ## How to fix
227
-
228
- Re-run the backport manually:
229
- \`\`\`
230
- node scripts/backport --pr 55
231
- \`\`\`
232
- Note: Successful backport PRs will be merged automatically after passing CI.
233
-
234
- ### Questions ?
235
- Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
236
- `);
263
+ });
264
+ it('posts a comment when running on CI', () => {
265
+ const params = getParams({ ci: true });
266
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`
267
+ "## 💔 Some backports could not be created
268
+
269
+ | Status | Branch | Result |
270
+ |:------:|:------:|:------|
271
+ |✅|7.x|[<img src=\\"https://img.shields.io/github/pulls/detail/state/elastic/kibana/55\\">](url-to-pr-55)|
272
+ |❌|7.1|**Backport failed because of merge conflicts**<br><br>You might need to backport the following PRs to 7.1:<br> - [New Zealand commit message](url-to-pr-5)<br> - [Australia commit](url-to-pr-44)|
273
+ |❌|7.2|**Backport failed because of merge conflicts**|
274
+
275
+ ### How to fix
276
+ Re-run the backport manually:
277
+ \`\`\`
278
+ node scripts/backport --pr 55
279
+ \`\`\`
280
+ Note: Successful backport PRs will be merged automatically after passing CI.
281
+
282
+ ### Questions ?
283
+ Please refer to the [Backport tool documentation](https://github.com/sqren/backport)"
284
+ `);
285
+ });
286
+ it('does not post a comment when running manually because some backports failed', () => {
287
+ const params = getParams({ ci: false });
288
+ expect((0, createStatusComment_1.getCommentBody)(params)).toMatchInlineSnapshot(`undefined`);
289
+ });
237
290
  });
238
291
  });
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const getDevAccessToken_1 = require("../../../../test/private/getDevAccessToken");
4
+ const fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
5
+ const fetchCommitBySha_1 = require("./fetchCommitBySha");
6
+ const fetchCommitsByAuthor_1 = require("./fetchCommitsByAuthor");
7
+ const fetchPullRequestBySearchQuery_1 = require("./fetchPullRequestBySearchQuery");
8
+ describe('allFetchers', () => {
9
+ let devAccessToken;
10
+ beforeEach(async () => {
11
+ devAccessToken = await (0, getDevAccessToken_1.getDevAccessToken)();
12
+ });
13
+ it('all fetchers return the same commit', async () => {
14
+ const commitsByAuthor = await (0, fetchCommitsByAuthor_1.fetchCommitsByAuthor)({
15
+ accessToken: devAccessToken,
16
+ author: 'sqren',
17
+ historicalBranchLabelMappings: [],
18
+ maxNumber: 1,
19
+ repoName: 'kibana',
20
+ repoOwner: 'elastic',
21
+ sourceBranch: 'main',
22
+ dateSince: '2021-01-10T00:00:00Z',
23
+ dateUntil: '2022-01-01T00:00:00Z',
24
+ commitPaths: [],
25
+ });
26
+ const commitByAuthor = commitsByAuthor[0];
27
+ if (!commitByAuthor.pullNumber) {
28
+ throw new Error('Missing pullnumber!');
29
+ }
30
+ const commitByPullNumber = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
31
+ repoOwner: 'elastic',
32
+ repoName: 'kibana',
33
+ accessToken: devAccessToken,
34
+ pullNumber: commitByAuthor.pullNumber,
35
+ sourceBranch: 'master',
36
+ historicalBranchLabelMappings: [],
37
+ });
38
+ const commitBySha = await (0, fetchCommitBySha_1.fetchCommitBySha)({
39
+ repoOwner: 'elastic',
40
+ repoName: 'kibana',
41
+ accessToken: devAccessToken,
42
+ sha: commitByAuthor.sha,
43
+ sourceBranch: 'main',
44
+ historicalBranchLabelMappings: [],
45
+ });
46
+ const commitsBySearchQuery = await (0, fetchPullRequestBySearchQuery_1.fetchPullRequestBySearchQuery)({
47
+ repoOwner: 'elastic',
48
+ repoName: 'kibana',
49
+ accessToken: devAccessToken,
50
+ maxNumber: 1,
51
+ prFilter: `[APM] Add note about synthtrace to APM docs`,
52
+ sourceBranch: 'main',
53
+ });
54
+ expect(commitByAuthor).toEqual(commitByPullNumber);
55
+ expect(commitByAuthor).toEqual(commitBySha);
56
+ expect(commitByAuthor).toEqual(commitsBySearchQuery[0]);
57
+ expect(commitByAuthor).toEqual({
58
+ committedDate: '2021-12-20T14:20:16Z',
59
+ expectedTargetPullRequests: [
60
+ {
61
+ branch: '8.0',
62
+ mergeCommit: {
63
+ message: '[APM] Add note about synthtrace to APM docs (#121633) (#121643)\n\nCo-authored-by: Søren Louv-Jansen <soren.louv@elastic.co>',
64
+ sha: '842adfdeb5541b059231857522f9009771a46107',
65
+ },
66
+ number: 121643,
67
+ state: 'MERGED',
68
+ url: 'https://github.com/elastic/kibana/pull/121643',
69
+ },
70
+ ],
71
+ originalMessage: '[APM] Add note about synthtrace to APM docs (#121633)',
72
+ pullNumber: 121633,
73
+ pullUrl: 'https://github.com/elastic/kibana/pull/121633',
74
+ sha: 'd421ddcf6157150596581c7885afa3690cec6339',
75
+ sourceBranch: 'main',
76
+ });
77
+ });
78
+ });
@@ -15,7 +15,7 @@ async function fetchCommitByPullNumber(options) {
15
15
  repository(owner: $repoOwner, name: $repoName) {
16
16
  pullRequest(number: $pullNumber) {
17
17
  mergeCommit {
18
- ...${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment.name}
18
+ ...SourceCommitWithTargetPullRequest
19
19
  }
20
20
  }
21
21
  }
@@ -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 fetchCommitByPullNumber_1 = require("./fetchCommitByPullNumber");
5
29
  describe('fetchCommitByPullNumber', () => {
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 commit;
37
+ beforeEach(async () => {
38
+ spy = jest.spyOn(apiRequestV4Module, 'apiRequestV4');
39
+ commit = await (0, fetchCommitByPullNumber_1.fetchCommitByPullNumber)({
40
+ repoOwner: 'elastic',
41
+ repoName: 'kibana',
42
+ accessToken: devAccessToken,
43
+ pullNumber: 121633,
44
+ sourceBranch: 'master',
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(['CommitByPullNumber']);
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
  describe('when PR was merged', () => {
11
67
  it('is returned', async () => {
12
68
  const options = {
@@ -30,12 +86,20 @@ describe('fetchCommitByPullNumber', () => {
30
86
  state: 'MERGED',
31
87
  number: 6,
32
88
  url: 'https://github.com/backport-org/backport-e2e/pull/6',
89
+ mergeCommit: {
90
+ message: 'Add 🍏 emoji (#5) (#6)',
91
+ sha: '4bcd876d4ceaa73cf437bfc89b74d1a4e704c0a6',
92
+ },
33
93
  },
34
94
  {
35
95
  branch: '7.8',
36
96
  state: 'MERGED',
37
97
  number: 7,
38
98
  url: 'https://github.com/backport-org/backport-e2e/pull/7',
99
+ mergeCommit: {
100
+ message: 'Add 🍏 emoji (#5) (#7)',
101
+ sha: '46cd6f9999effdf894a36dbc7db90e890f4be840',
102
+ },
39
103
  },
40
104
  ],
41
105
  });
@@ -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: {