backport 7.1.0 → 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.
@@ -251,6 +251,62 @@ describe('inquirer cli', () => {
251
251
  6. Bump to 8.0.0"
252
252
  `);
253
253
  });
254
+ describe('repo: repo-with-backportrc-removed (missing .backportrc.json config file)', () => {
255
+ it('should list commits', async () => {
256
+ const output = await runBackportAsync([
257
+ '--branch',
258
+ 'foo',
259
+ '--repo',
260
+ 'backport-org/repo-with-backportrc-removed',
261
+ '--accessToken',
262
+ devAccessToken,
263
+ ], { waitForString: 'Select commit' });
264
+ expect(output).toMatchInlineSnapshot(`
265
+ "? Select commit (Use arrow keys)
266
+ ❯ 1. Rename README.me to README.md
267
+ 2. Merge pull request #1 from backport-org/add-readme
268
+ 3. Create README.me
269
+ 4. Delete .backportrc.json
270
+ 5. Create .backportrc.json
271
+ 6. Delete .backportrc.json
272
+ 7. Create .backportrc.json"
273
+ `);
274
+ });
275
+ it('should attempt to backport by PR', async () => {
276
+ const output = await runBackportAsync([
277
+ '--branch',
278
+ 'foo',
279
+ '--repo',
280
+ 'backport-org/repo-with-backportrc-removed',
281
+ '--pr',
282
+ '1',
283
+ '--accessToken',
284
+ devAccessToken,
285
+ ], { waitForString: "is invalid or doesn't exist" });
286
+ expect(output).toMatchInlineSnapshot(`
287
+ "
288
+ Backporting to foo:
289
+ The branch \\"foo\\" is invalid or doesn't exist"
290
+ `);
291
+ });
292
+ it('should attempt to backport by commit sha', async () => {
293
+ const output = await runBackportAsync([
294
+ '--branch',
295
+ 'foo',
296
+ '--repo',
297
+ 'backport-org/repo-with-backportrc-removed',
298
+ '--sha',
299
+ 'be59df6912a550c8cb49ba3e18be3e512f3d608c',
300
+ '--accessToken',
301
+ devAccessToken,
302
+ ], { waitForString: "is invalid or doesn't exist" });
303
+ expect(output).toMatchInlineSnapshot(`
304
+ "
305
+ Backporting to foo:
306
+ The branch \\"foo\\" is invalid or doesn't exist"
307
+ `);
308
+ });
309
+ });
254
310
  describe('repo: different-merge-strategies', () => {
255
311
  it('list all commits regardless how they were merged', async () => {
256
312
  jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
@@ -263,16 +319,27 @@ describe('inquirer cli', () => {
263
319
  'different-merge-strategies',
264
320
  '--accessToken',
265
321
  devAccessToken,
322
+ '-n',
323
+ '20',
266
324
  ], { waitForString: 'Select commit' });
267
325
  expect(output).toMatchInlineSnapshot(`
268
326
  "? Select commit (Use arrow keys)
269
- ❯ 1. Using squash to merge commits (#3) 7.x
270
- 2. Rebase strategy: Second commit 7.x
271
- 3. Rebase strategy: First commit
272
- 4. Merge pull request #1 from backport-org/merge-strategy
273
- 5. Merge strategy: Second commit
274
- 6. Merge strategy: First commit
275
- 7. Initial commit"
327
+ ❯ 1. Merge pull request #9 from backport-org/many-merge-commits
328
+ 2. Merge strategy: Eighth of many merges
329
+ 3. Merge strategy: Seventh of many merges
330
+ 4. Merge strategy: Sixth of many merges
331
+ 5. Merge strategy: Fifth of many merges
332
+ 6. Merge strategy: Fourth of many merges
333
+ 7. Merge strategy: Third of many merges
334
+ 8. Merge strategy: Second of many merges
335
+ 9. Merge strategy: First of many merges
336
+ 10.Using squash to merge commits (#3) 7.x
337
+ 11.Rebase strategy: Second commit 7.x
338
+ 12.Rebase strategy: First commit
339
+ 13.Merge pull request #1 from backport-org/merge-strategy
340
+ 14.Merge strategy: Second commit
341
+ 15.Merge strategy: First commit
342
+ 16.Initial commit"
276
343
  `);
277
344
  });
278
345
  });
@@ -26,6 +26,7 @@ async function runSequentially({ options, commits, targetBranches, }) {
26
26
  });
27
27
  }
28
28
  catch (e) {
29
+ process.exitCode = 1;
29
30
  results.push({
30
31
  targetBranch,
31
32
  status: 'failure',
@@ -106,7 +106,7 @@ describe('runSequentially', () => {
106
106
  };
107
107
  rpcExecMock = jest
108
108
  .spyOn(childProcess, 'exec')
109
- .mockResolvedValue({ stdout: 'success', stderr: '' });
109
+ .mockResolvedValue({ stdout: '', stderr: '' });
110
110
  rpcExecOriginalMock = jest.spyOn(childProcess, 'execAsCallback');
111
111
  const scope = (0, nock_1.default)('https://api.github.com')
112
112
  .post('/repos/elastic/kibana/pulls')
@@ -183,6 +183,7 @@ describe('runSequentially', () => {
183
183
  '/myHomeDir/.backport/repositories/elastic/kibana',
184
184
  '/myHomeDir/.backport/repositories/elastic/kibana',
185
185
  '/myHomeDir/.backport/repositories/elastic/kibana',
186
+ '/myHomeDir/.backport/repositories/elastic/kibana',
186
187
  ]);
187
188
  });
188
189
  it('exec commands should be called with correct args', () => {
@@ -195,6 +196,7 @@ describe('runSequentially', () => {
195
196
  'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
196
197
  'git reset --hard && git clean -d --force && git fetch elastic 7.x && git checkout -B backport/7.x/pr-55 elastic/7.x --no-track',
197
198
  'git fetch elastic master:master --force',
199
+ 'git rev-list -1 --merges abcd~1..abcd',
198
200
  'git cherry-pick -x abcd',
199
201
  'git push sqren_authenticated backport/7.x/pr-55:backport/7.x/pr-55 --force',
200
202
  'git reset --hard && git checkout my-source-branch-from-options && git branch -D backport/7.x/pr-55',
@@ -28,6 +28,8 @@ export declare function getIsCommitInBranch(options: ValidConfigOptions, commitS
28
28
  export declare function deleteRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
29
29
  export declare function addRemote(options: ValidConfigOptions, remoteName: string): Promise<void>;
30
30
  export declare function fetchBranch(options: ValidConfigOptions, branch: string): Promise<void>;
31
+ export declare function getIsMergeCommit(options: ValidConfigOptions, sha: string): Promise<boolean>;
32
+ export declare function getCommitsInMergeCommit(options: ValidConfigOptions, sha: string): Promise<string[]>;
31
33
  export declare function cherrypick(options: ValidConfigOptions, sha: string, mergedTargetPullRequest?: ExpectedTargetPullRequest): Promise<{
32
34
  conflictingFiles: {
33
35
  absolute: string;
@@ -31,19 +31,6 @@ const git_1 = require("./git");
31
31
  const commitFormatters_1 = require("./github/commitFormatters");
32
32
  jest.unmock('del');
33
33
  jest.unmock('make-dir');
34
- async function createAndCommitFile({ filename, content, execOpts, }) {
35
- await childProcess.exec(`echo "${content}" > "${filename}"`, execOpts);
36
- await childProcess.exec(`git add -A && git commit -m 'Update ${filename}'`, execOpts);
37
- return getCurrentSha(execOpts);
38
- }
39
- async function getCurrentSha(execOpts) {
40
- const { stdout } = await childProcess.exec('git rev-parse HEAD', execOpts);
41
- return stdout.trim();
42
- }
43
- async function getCurrentMessage(execOpts) {
44
- const { stdout } = await childProcess.exec('git --no-pager log -1 --pretty=%B', execOpts);
45
- return stdout.trim();
46
- }
47
34
  describe('git.integration', () => {
48
35
  describe('getIsCommitInBranch', () => {
49
36
  let firstSha;
@@ -239,7 +226,73 @@ describe('git.integration', () => {
239
226
  expect(await (0, git_1.getSourceRepoPath)(options)).toBe('https://x-access-token:verysecret@github.com/not-a-match/kibana.git');
240
227
  });
241
228
  });
229
+ describe('when cloning "backport-org/different-merge-strategies"', () => {
230
+ const MERGE_COMMIT_HASH_1 = 'bdc5a17f81e5f32129e27b05c742e055c650bc54';
231
+ const MERGE_COMMIT_HASH_2 = '0db7f1ac1233461563d8708511d1c14adbab46da';
232
+ const SQUASH_COMMIT_HASH = '74a76fa64b34e3ffe8f2a3f73840e1b42fd07299';
233
+ const REBASE_COMMIT_HASH = '9059ae0ca31caa2eebc035f2542842d6c2fde83b';
234
+ let sandboxPath;
235
+ beforeAll(async () => {
236
+ sandboxPath = (0, sandbox_1.getSandboxPath)({
237
+ filename: __filename,
238
+ specname: 'different-merge-strategies',
239
+ });
240
+ await (0, sandbox_1.resetSandbox)(sandboxPath);
241
+ await childProcess.exec('git clone https://github.com/backport-org/different-merge-strategies.git ./', { cwd: sandboxPath });
242
+ });
243
+ describe('getIsMergeCommit', () => {
244
+ it('returns true for first merge commit', async () => {
245
+ const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, MERGE_COMMIT_HASH_1);
246
+ expect(res).toBe(true);
247
+ });
248
+ it('returns true for second merge commit', async () => {
249
+ const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, MERGE_COMMIT_HASH_2);
250
+ expect(res).toBe(true);
251
+ });
252
+ it('returns false for rebased commits', async () => {
253
+ const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, REBASE_COMMIT_HASH);
254
+ expect(res).toBe(false);
255
+ });
256
+ it('returns false for squashed commits', async () => {
257
+ const res = await (0, git_1.getIsMergeCommit)({ dir: sandboxPath }, SQUASH_COMMIT_HASH);
258
+ expect(res).toBe(false);
259
+ });
260
+ });
261
+ describe('getCommitsInMergeCommit', () => {
262
+ it('returns a list of commit hashes - excluding the merge hash itself', async () => {
263
+ const res = await (0, git_1.getCommitsInMergeCommit)({ dir: sandboxPath }, MERGE_COMMIT_HASH_1);
264
+ expect(res).not.toContain(MERGE_COMMIT_HASH_1);
265
+ expect(res).toEqual([
266
+ 'f9a760e0d9eb3ebcc64f8cb75ce885714b836496',
267
+ '7b92e29e88266004485ce0fae0260605b01df887',
268
+ 'a1facf8c006fb815d6a6ecd1b2907e6e64f29576',
269
+ 'b8d4bcfb0fd875be4ab0230f6db40ddf72f45378',
270
+ '6f224054db5f7772b04f23f17659070216bae84c',
271
+ '7fed54cbd1ba9cb973462670ff82ac80bf8a79f8',
272
+ '78c24d0058859e7d511d10ce91ebf279c7b58ac2',
273
+ '709ccf707d443dd8c001b3c3ae40fdf037bb43f5',
274
+ ]);
275
+ });
276
+ it('returns empty for squash commits', async () => {
277
+ const res = await (0, git_1.getCommitsInMergeCommit)({ dir: sandboxPath }, SQUASH_COMMIT_HASH);
278
+ expect(res).toEqual([]);
279
+ });
280
+ });
281
+ });
242
282
  });
283
+ async function createAndCommitFile({ filename, content, execOpts, }) {
284
+ await childProcess.exec(`echo "${content}" > "${filename}"`, execOpts);
285
+ await childProcess.exec(`git add -A && git commit -m 'Update ${filename}'`, execOpts);
286
+ return getCurrentSha(execOpts);
287
+ }
288
+ async function getCurrentSha(execOpts) {
289
+ const { stdout } = await childProcess.exec('git rev-parse HEAD', execOpts);
290
+ return stdout.trim();
291
+ }
292
+ async function getCurrentMessage(execOpts) {
293
+ const { stdout } = await childProcess.exec('git --no-pager log -1 --pretty=%B', execOpts);
294
+ return stdout.trim();
295
+ }
243
296
  function mockRepoOwnerAndName({ repoName, parentRepoOwner, childRepoOwner, }) {
244
297
  return (0, nockHelpers_1.mockGqlRequest)({
245
298
  name: 'RepoOwnerAndName',
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRoot = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
3
+ exports.getSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.setCommitAuthor = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getCommitsInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRoot = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
4
4
  const path_1 = require("path");
5
5
  const lodash_1 = require("lodash");
6
6
  const ora_1 = require("../ui/ora");
@@ -156,10 +156,50 @@ async function fetchBranch(options, branch) {
156
156
  });
157
157
  }
158
158
  exports.fetchBranch = fetchBranch;
159
+ async function getIsMergeCommit(options, sha) {
160
+ const res = await (0, child_process_promisified_1.exec)(`git rev-list -1 --merges ${sha}~1..${sha}`, {
161
+ cwd: (0, env_1.getRepoPath)(options),
162
+ });
163
+ return res.stdout !== '';
164
+ }
165
+ exports.getIsMergeCommit = getIsMergeCommit;
166
+ async function getCommitsInMergeCommit(options, sha) {
167
+ try {
168
+ const res = await (0, child_process_promisified_1.exec)(`git --no-pager log ${sha}^1..${sha}^2 --pretty=format:"%H"`, {
169
+ cwd: (0, env_1.getRepoPath)(options),
170
+ });
171
+ return res.stdout.split('\n');
172
+ }
173
+ catch (e) {
174
+ // swallow error
175
+ if (e.code === 128) {
176
+ return [];
177
+ }
178
+ throw e;
179
+ }
180
+ }
181
+ exports.getCommitsInMergeCommit = getCommitsInMergeCommit;
159
182
  async function cherrypick(options, sha, mergedTargetPullRequest) {
160
183
  const mainlinArg = options.mainline != undefined ? ` --mainline ${options.mainline}` : '';
161
184
  const cherrypickRefArg = options.cherrypickRef === false ? '' : ' -x';
162
- const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${sha}`;
185
+ let shaOrRange = sha;
186
+ if (!options.mainline) {
187
+ try {
188
+ const isMergeCommit = await getIsMergeCommit(options, sha);
189
+ if (isMergeCommit) {
190
+ const shas = await getCommitsInMergeCommit(options, sha);
191
+ shaOrRange = `${(0, lodash_1.last)(shas)}^..${(0, lodash_1.first)(shas)}`;
192
+ }
193
+ }
194
+ catch (e) {
195
+ // swallow error if it's a known error
196
+ // exit 128 will happen for many things, among others when the cherrypicked commit is empty
197
+ if (e.code !== 128) {
198
+ throw e;
199
+ }
200
+ }
201
+ }
202
+ const cmd = `git cherry-pick${cherrypickRefArg}${mainlinArg} ${shaOrRange}`;
163
203
  try {
164
204
  await (0, child_process_promisified_1.exec)(cmd, { cwd: (0, env_1.getRepoPath)(options) });
165
205
  return { conflictingFiles: [], unstagedFiles: [], needsResolving: false };
@@ -275,7 +275,9 @@ describe('cherrypick', () => {
275
275
  it('should return `needsResolving: false` when no errors are encountered', async () => {
276
276
  jest
277
277
  .spyOn(childProcess, 'exec')
278
- // mock cherry pick command
278
+ // mock getIsMergeCommit(...)
279
+ .mockResolvedValueOnce({ stderr: '', stdout: '' })
280
+ // mock cherrypick(...)
279
281
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
280
282
  expect(await (0, git_1.cherrypick)(options, 'abcd')).toEqual({
281
283
  conflictingFiles: [],
@@ -286,6 +288,8 @@ describe('cherrypick', () => {
286
288
  it('should use mainline option when specified', async () => {
287
289
  const execSpy = jest
288
290
  .spyOn(childProcess, 'exec')
291
+ // mock getIsMergeCommit(...)
292
+ .mockResolvedValueOnce({ stderr: '', stdout: '' })
289
293
  // mock cherry pick command
290
294
  .mockResolvedValueOnce({ stderr: '', stdout: '' });
291
295
  await (0, git_1.cherrypick)({ ...options, mainline: 1 }, 'abcd');
@@ -294,6 +298,8 @@ describe('cherrypick', () => {
294
298
  it('should return `needsResolving: true` upon cherrypick error', async () => {
295
299
  jest
296
300
  .spyOn(childProcess, 'exec')
301
+ // mock getIsMergeCommit(...)
302
+ .mockResolvedValueOnce({ stderr: '', stdout: '' })
297
303
  // mock cherry pick command
298
304
  .mockRejectedValueOnce(new ExecError_1.ExecError({
299
305
  killed: false,
@@ -325,6 +331,8 @@ describe('cherrypick', () => {
325
331
  it('should let the user know about the "--mainline" argument when cherry-picking a merge commit without specifying it', async () => {
326
332
  jest
327
333
  .spyOn(childProcess, 'exec')
334
+ // mock getIsMergeCommit(...)
335
+ .mockResolvedValueOnce({ stderr: '', stdout: '' })
328
336
  // mock cherry pick command
329
337
  .mockRejectedValueOnce(new ExecError_1.ExecError({
330
338
  killed: false,
@@ -348,6 +356,8 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
348
356
  it('should gracefully handle empty commits', async () => {
349
357
  jest
350
358
  .spyOn(childProcess, 'exec')
359
+ // mock getIsMergeCommit(...)
360
+ .mockResolvedValueOnce({ stderr: '', stdout: '' })
351
361
  // mock cherry pick command
352
362
  .mockRejectedValueOnce(new ExecError_1.ExecError({
353
363
  killed: false,
@@ -362,6 +372,8 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
362
372
  it('gracefully handles missing git info', async () => {
363
373
  jest
364
374
  .spyOn(childProcess, 'exec')
375
+ // mock getIsMergeCommit(...)
376
+ .mockResolvedValueOnce({ stderr: '', stdout: '' })
365
377
  // mock cherry pick command
366
378
  .mockRejectedValueOnce(new ExecError_1.ExecError({
367
379
  killed: false,
@@ -392,6 +404,8 @@ Or refer to the git documentation for more information: https://git-scm.com/docs
392
404
  it('should re-throw non-cherrypick errors', async () => {
393
405
  jest
394
406
  .spyOn(childProcess, 'exec')
407
+ // mock getIsMergeCommit(...)
408
+ .mockResolvedValueOnce({ stderr: '', stdout: '' })
395
409
  // mock cherry pick command
396
410
  .mockRejectedValueOnce(new Error('non-cherrypick error'))
397
411
  // getConflictingFiles
@@ -23,7 +23,9 @@ export declare function apiRequestV4<DataResponse>({ githubApiBaseUrlV4, accessT
23
23
  declare type AxiosGithubResponse<DataResponse> = AxiosResponse<GithubV4Response<DataResponse | null>, any>;
24
24
  export declare class GithubV4Exception<DataResponse> extends Error {
25
25
  message: string;
26
- axiosResponse: AxiosGithubResponse<DataResponse>;
26
+ axiosResponse: AxiosGithubResponse<DataResponse> & {
27
+ request: undefined;
28
+ };
27
29
  constructor(message: string, axiosResponse: AxiosGithubResponse<DataResponse>);
28
30
  }
29
31
  export declare function getQueryName(query: DocumentNode): string;
@@ -60,9 +60,9 @@ 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;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fetchCommitByPullNumber = void 0;
7
7
  const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const HandledError_1 = require("../../../HandledError");
9
+ const remoteConfig_1 = require("../../../remoteConfig");
9
10
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
10
11
  const apiRequestV4_1 = require("../apiRequestV4");
11
12
  async function fetchCommitByPullNumber(options) {
@@ -27,16 +28,22 @@ async function fetchCommitByPullNumber(options) {
27
28
 
28
29
  ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
29
30
  `;
30
- const res = await (0, apiRequestV4_1.apiRequestV4)({
31
- githubApiBaseUrlV4,
32
- accessToken,
33
- query,
34
- variables: {
35
- repoOwner,
36
- repoName,
37
- pullNumber,
38
- },
39
- });
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
+ }
40
47
  const pullRequestNode = res.repository.pullRequest;
41
48
  if (!pullRequestNode) {
42
49
  throw new HandledError_1.HandledError(`The PR #${pullNumber} does not exist`);
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.fetchCommitBySha = void 0;
7
7
  const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const HandledError_1 = require("../../../HandledError");
9
+ const remoteConfig_1 = require("../../../remoteConfig");
9
10
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
10
11
  const apiRequestV4_1 = require("../apiRequestV4");
11
12
  async function fetchCommitBySha(options) {
@@ -21,16 +22,22 @@ async function fetchCommitBySha(options) {
21
22
 
22
23
  ${parseSourceCommit_1.sourceCommitWithTargetPullRequestFragment}
23
24
  `;
24
- const res = await (0, apiRequestV4_1.apiRequestV4)({
25
- githubApiBaseUrlV4,
26
- accessToken,
27
- query,
28
- variables: {
29
- repoOwner,
30
- repoName,
31
- sha,
32
- },
33
- });
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
+ }
34
41
  const sourceCommit = res.repository.object;
35
42
  if (!sourceCommit) {
36
43
  throw new HandledError_1.HandledError(`No commit found on branch "${sourceBranch}" with sha "${sha}"`);
@@ -8,10 +8,11 @@ const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const lodash_1 = require("lodash");
9
9
  const filterEmpty_1 = require("../../../../utils/filterEmpty");
10
10
  const HandledError_1 = require("../../../HandledError");
11
+ const remoteConfig_1 = require("../../../remoteConfig");
11
12
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
12
13
  const apiRequestV4_1 = require("../apiRequestV4");
13
14
  const fetchAuthorId_1 = require("../fetchAuthorId");
14
- function fetchByCommitPath({ options, authorId, commitPath, }) {
15
+ async function fetchByCommitPath({ options, authorId, commitPath, }) {
15
16
  const { accessToken, githubApiBaseUrlV4 = 'https://api.github.com/graphql', maxNumber = 10, repoName, repoOwner, sourceBranch, dateSince, dateUntil, } = options;
16
17
  const query = (0, graphql_tag_1.default) `
17
18
  query CommitsByAuthor(
@@ -59,12 +60,17 @@ function fetchByCommitPath({ options, authorId, commitPath, }) {
59
60
  dateSince,
60
61
  dateUntil,
61
62
  };
62
- return (0, apiRequestV4_1.apiRequestV4)({
63
- githubApiBaseUrlV4,
64
- accessToken,
65
- query,
66
- variables,
67
- });
63
+ try {
64
+ return await (0, apiRequestV4_1.apiRequestV4)({
65
+ githubApiBaseUrlV4,
66
+ accessToken,
67
+ query,
68
+ variables,
69
+ });
70
+ }
71
+ catch (e) {
72
+ return (0, remoteConfig_1.swallowMissingConfigFileException)(e);
73
+ }
68
74
  }
69
75
  async function fetchCommitsByAuthor(options) {
70
76
  const { sourceBranch, commitPaths = [] } = options;
@@ -7,6 +7,7 @@ exports.fetchPullRequestBySearchQuery = void 0;
7
7
  const graphql_tag_1 = __importDefault(require("graphql-tag"));
8
8
  const lodash_1 = require("lodash");
9
9
  const HandledError_1 = require("../../../HandledError");
10
+ const remoteConfig_1 = require("../../../remoteConfig");
10
11
  const parseSourceCommit_1 = require("../../../sourceCommit/parseSourceCommit");
11
12
  const apiRequestV4_1 = require("../apiRequestV4");
12
13
  async function fetchPullRequestBySearchQuery(options) {
@@ -32,12 +33,18 @@ async function fetchPullRequestBySearchQuery(options) {
32
33
  query: searchQuery,
33
34
  maxNumber: maxNumber,
34
35
  };
35
- const res = await (0, apiRequestV4_1.apiRequestV4)({
36
- githubApiBaseUrlV4,
37
- accessToken,
38
- query,
39
- variables,
40
- });
36
+ let res;
37
+ try {
38
+ res = await (0, apiRequestV4_1.apiRequestV4)({
39
+ githubApiBaseUrlV4,
40
+ accessToken,
41
+ query,
42
+ variables,
43
+ });
44
+ }
45
+ catch (e) {
46
+ res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
47
+ }
41
48
  const commits = res.search.nodes.map((pullRequestNode) => {
42
49
  const sourceCommit = pullRequestNode.mergeCommit;
43
50
  return (0, parseSourceCommit_1.parseSourceCommit)({ options, sourceCommit });
@@ -23,9 +23,8 @@ async function getOptionsFromGithub(options) {
23
23
  if (!(e instanceof apiRequestV4_1.GithubV4Exception)) {
24
24
  throw e;
25
25
  }
26
- const error = e;
27
- (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({ error, repoName, repoOwner });
28
- res = swallowErrorIfConfigFileIsMissing(error);
26
+ (0, throwOnInvalidAccessToken_1.throwOnInvalidAccessToken)({ error: e, repoName, repoOwner });
27
+ res = (0, remoteConfig_1.swallowMissingConfigFileException)(e);
29
28
  }
30
29
  // it is not possible to have a branch named "backport"
31
30
  if (res.repository.illegalBackportBranch) {
@@ -72,15 +71,3 @@ async function getRemoteConfigFileOptions(res, cwd, skipRemoteConfig) {
72
71
  }
73
72
  return (0, remoteConfig_1.parseRemoteConfig)(remoteConfig);
74
73
  }
75
- function swallowErrorIfConfigFileIsMissing(error) {
76
- const { data, errors } = error.axiosResponse.data;
77
- const missingConfigError = errors?.some((error) => {
78
- return error.path.includes('remoteConfig') && error.type === 'NOT_FOUND';
79
- });
80
- // swallow error if it's just the config file that's missing
81
- if (missingConfigError && data != null) {
82
- return data;
83
- }
84
- // Throw unexpected error
85
- throw error;
86
- }
@@ -1,4 +1,5 @@
1
1
  import { ConfigFileOptions } from '../entrypoint.module';
2
+ import { GithubV4Exception } from './github/v4/apiRequestV4';
2
3
  export declare const RemoteConfigHistoryFragment: import("graphql").DocumentNode;
3
4
  export interface RemoteConfig {
4
5
  committedDate: string;
@@ -16,3 +17,4 @@ export interface RemoteConfigHistory {
16
17
  };
17
18
  }
18
19
  export declare function parseRemoteConfig(remoteConfig: RemoteConfig): ConfigFileOptions | undefined;
20
+ export declare function swallowMissingConfigFileException<T>(error: GithubV4Exception<T>): T;
@@ -3,7 +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
- exports.parseRemoteConfig = exports.RemoteConfigHistoryFragment = void 0;
6
+ exports.swallowMissingConfigFileException = exports.parseRemoteConfig = exports.RemoteConfigHistoryFragment = void 0;
7
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");
@@ -37,3 +37,16 @@ function parseRemoteConfig(remoteConfig) {
37
37
  }
38
38
  }
39
39
  exports.parseRemoteConfig = parseRemoteConfig;
40
+ function swallowMissingConfigFileException(error) {
41
+ const { data, errors } = error.axiosResponse.data;
42
+ const missingConfigError = errors?.some((error) => {
43
+ return error.path.includes('remoteConfig') && error.type === 'NOT_FOUND';
44
+ });
45
+ // swallow error if it's just the config file that's missing
46
+ if (missingConfigError && data != null) {
47
+ return data;
48
+ }
49
+ // Throw unexpected error
50
+ throw error;
51
+ }
52
+ exports.swallowMissingConfigFileException = swallowMissingConfigFileException;
@@ -450,6 +450,10 @@ function setupExecSpyForCherryPick() {
450
450
  if (cmd.includes('git branch -D ')) {
451
451
  return { stdout: ``, stderr: '' };
452
452
  }
453
+ // getIsMergeCommit
454
+ if (cmd.startsWith('git rev-list -1 --merges')) {
455
+ return { stdout: ``, stderr: '' };
456
+ }
453
457
  throw new Error(`Missing exec mock for "${cmd}"`);
454
458
  });
455
459
  }
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "7.1.0";
1
+ export declare const PACKAGE_VERSION = "7.2.0-beta.1";
@@ -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.1.0';
4
+ exports.PACKAGE_VERSION = '7.2.0-beta.1';
package/package.json CHANGED
@@ -14,11 +14,11 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "7.1.0",
17
+ "version": "7.2.0-beta.1",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {
21
- "backport": "./dist/entrypoint.cli.js"
21
+ "backport": "./bin/backport"
22
22
  },
23
23
  "license": "MIT",
24
24
  "scripts": {
@@ -1 +0,0 @@
1
- export {};
@@ -1,61 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
22
- const core = __importStar(require("@actions/core"));
23
- const exec_1 = require("@actions/exec");
24
- const github_1 = require("@actions/github");
25
- const backport_1 = require("backport");
26
- async function init() {
27
- const { payload, repo } = github_1.context;
28
- if (!payload.pull_request) {
29
- throw Error('Only pull_request events are supported.');
30
- }
31
- const pullRequest = payload.pull_request;
32
- const prAuthor = pullRequest.user.login;
33
- const accessToken = core.getInput('github_token', { required: true });
34
- const commitUser = core.getInput('commit_user', { required: false });
35
- const commitEmail = core.getInput('commit_email', { required: false });
36
- const autoMerge = core.getInput('auto_merge', { required: false }) === 'true';
37
- const autoMergeMethod = core.getInput('auto_merge_method', {
38
- required: false,
39
- });
40
- const targetPRLabels = core
41
- .getInput('target_pr_labels', { required: false })
42
- .split(',')
43
- .map((label) => label.trim());
44
- await (0, exec_1.exec)(`git config --global user.name "${commitUser}"`);
45
- await (0, exec_1.exec)(`git config --global user.email "${commitEmail}"`);
46
- await (0, backport_1.backportRun)({
47
- repoOwner: repo.owner,
48
- repoName: repo.repo,
49
- accessToken,
50
- ci: true,
51
- pullNumber: pullRequest.number,
52
- targetPRLabels: targetPRLabels,
53
- assignees: [prAuthor],
54
- autoMerge: autoMerge,
55
- autoMergeMethod: autoMergeMethod,
56
- });
57
- }
58
- init().catch((error) => {
59
- console.error('An error occurred', error);
60
- core.setFailed(error.message);
61
- });