backport 8.5.2 → 8.5.3

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.
@@ -1,13 +1,10 @@
1
1
  import { Commit } from '../entrypoint.module';
2
2
  import { ValidConfigOptions } from '../options/options';
3
- export declare type GitConfigAuthor = {
4
- name?: string;
5
- email?: string;
3
+ export declare type CommitAuthor = {
4
+ name: string;
5
+ email: string;
6
6
  };
7
- export declare function getGitConfigAuthor(options: ValidConfigOptions): Promise<GitConfigAuthor | undefined>;
8
- export declare type CommitAuthor = Required<GitConfigAuthor>;
9
- export declare function getCommitAuthor({ options, commit, gitConfigAuthor, }: {
7
+ export declare function getCommitAuthor({ options, commit, }: {
10
8
  options: ValidConfigOptions;
11
9
  commit: Commit;
12
- gitConfigAuthor?: GitConfigAuthor;
13
10
  }): CommitAuthor;
@@ -1,19 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCommitAuthor = exports.getGitConfigAuthor = void 0;
4
- const git_1 = require("./git");
5
- async function getGitConfigAuthor(options) {
6
- const localRepoPath = await (0, git_1.getLocalSourceRepoPath)(options);
7
- if (!localRepoPath) {
8
- return;
9
- }
10
- return {
11
- name: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.name' }),
12
- email: await (0, git_1.getGitConfig)({ dir: localRepoPath, key: 'user.email' }),
13
- };
14
- }
15
- exports.getGitConfigAuthor = getGitConfigAuthor;
16
- function getCommitAuthor({ options, commit, gitConfigAuthor, }) {
3
+ exports.getCommitAuthor = void 0;
4
+ function getCommitAuthor({ options, commit, }) {
17
5
  if (options.resetAuthor) {
18
6
  return {
19
7
  name: options.authenticatedUsername,
@@ -21,8 +9,8 @@ function getCommitAuthor({ options, commit, gitConfigAuthor, }) {
21
9
  };
22
10
  }
23
11
  return {
24
- name: options.gitAuthorName ?? gitConfigAuthor?.name ?? commit.author.name,
25
- email: options.gitAuthorEmail ?? gitConfigAuthor?.email ?? commit.author.email,
12
+ name: options.gitAuthorName ?? commit.author.name,
13
+ email: options.gitAuthorEmail ?? commit.author.email,
26
14
  };
27
15
  }
28
16
  exports.getCommitAuthor = getCommitAuthor;
@@ -35,17 +35,14 @@ async function cherrypickAndCreateTargetPullRequest({ options, commits, targetBr
35
35
  const repoForkOwner = (0, git_1.getRepoForkOwner)(options);
36
36
  (0, logger_1.consoleLog)(`\n${chalk_1.default.bold(`Backporting to ${targetBranch}:`)}`);
37
37
  await (0, validateTargetBranch_1.validateTargetBranch)({ ...options, branchName: targetBranch });
38
- const [gitConfigAuthor] = await Promise.all([
39
- (0, author_1.getGitConfigAuthor)(options),
40
- (0, git_1.createBackportBranch)({
41
- options,
42
- sourceBranch: getSourceBranchFromCommits(commits),
43
- targetBranch,
44
- backportBranch,
45
- }),
46
- ]);
38
+ await (0, git_1.createBackportBranch)({
39
+ options,
40
+ sourceBranch: getSourceBranchFromCommits(commits),
41
+ targetBranch,
42
+ backportBranch,
43
+ });
47
44
  const commitsFlattened = (0, lodash_1.flatten)(await Promise.all(commits.map((c) => getMergeCommits(options, c))));
48
- await (0, sequentially_1.sequentially)(commitsFlattened, (commit) => waitForCherrypick(options, commit, targetBranch, gitConfigAuthor));
45
+ await (0, sequentially_1.sequentially)(commitsFlattened, (commit) => waitForCherrypick(options, commit, targetBranch));
49
46
  if (options.dryRun) {
50
47
  (0, ora_1.ora)(options.interactive).succeed('Dry run complete');
51
48
  return { url: 'https://localhost/dry-run', didUpdate: false, number: 1337 };
@@ -121,10 +118,10 @@ function getBackportBranchName(targetBranch, commits) {
121
118
  .slice(0, 200);
122
119
  return `backport/${targetBranch}/${refValues}`;
123
120
  }
124
- async function waitForCherrypick(options, commit, targetBranch, gitConfigAuthor) {
121
+ async function waitForCherrypick(options, commit, targetBranch) {
125
122
  const spinnerText = `Cherry-picking: ${chalk_1.default.greenBright((0, commitFormatters_1.getFirstLine)(commit.sourceCommit.message))}`;
126
123
  const cherrypickSpinner = (0, ora_1.ora)(options.interactive, spinnerText).start();
127
- const commitAuthor = (0, author_1.getCommitAuthor)({ options, commit, gitConfigAuthor });
124
+ const commitAuthor = (0, author_1.getCommitAuthor)({ options, commit });
128
125
  await cherrypickAndHandleConflicts({
129
126
  options,
130
127
  commit,
package/dist/lib/git.d.ts CHANGED
@@ -53,10 +53,6 @@ export declare function getConflictingFiles(options: ValidConfigOptions): Promis
53
53
  relative: string;
54
54
  }[]>;
55
55
  export declare function getUnstagedFiles(options: ValidConfigOptions): Promise<string[]>;
56
- export declare function getGitConfig({ dir, key, }: {
57
- dir: string;
58
- key: 'user.name' | 'user.email';
59
- }): Promise<string | undefined>;
60
56
  export declare function createBackportBranch({ options, sourceBranch, backportBranch, targetBranch, }: {
61
57
  options: ValidConfigOptions;
62
58
  sourceBranch: string;
package/dist/lib/git.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLocalSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.getGitConfig = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getShasInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRootPath = exports.getRepoInfoFromGitRemotes = exports.isLocalConfigFileModified = exports.isLocalConfigFileUntracked = exports.getLocalConfigFileCommitDate = exports.cloneRepo = exports.getRemoteUrl = void 0;
3
+ exports.getLocalSourceRepoPath = exports.pushBackportBranch = exports.getRepoForkOwner = exports.deleteBackportBranch = exports.createBackportBranch = exports.getUnstagedFiles = exports.getConflictingFiles = exports.commitChanges = exports.cherrypick = exports.getShasInMergeCommit = exports.getIsMergeCommit = exports.fetchBranch = exports.addRemote = exports.deleteRemote = exports.getIsCommitInBranch = exports.getGitProjectRootPath = 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("../lib/ora");
@@ -339,17 +339,6 @@ async function getUnstagedFiles(options) {
339
339
  return (0, lodash_1.uniq)(files);
340
340
  }
341
341
  exports.getUnstagedFiles = getUnstagedFiles;
342
- async function getGitConfig({ dir, key, }) {
343
- try {
344
- const cwd = dir;
345
- const res = await (0, child_process_promisified_1.spawnPromise)('git', ['config', key], cwd);
346
- return res.stdout.trim();
347
- }
348
- catch (e) {
349
- return;
350
- }
351
- }
352
- exports.getGitConfig = getGitConfig;
353
342
  // How the commit flows:
354
343
  // ${sourceBranch} -> ${backportBranch} -> ${targetBranch}
355
344
  // master -> backport/7.x/pr-1234 -> 7.x
@@ -97,32 +97,6 @@ describe('git.private', () => {
97
97
  expect(res).toBe(undefined);
98
98
  });
99
99
  });
100
- describe('getGitConfig', () => {
101
- const cwd = (0, sandbox_1.getSandboxPath)({
102
- filename: __filename,
103
- specname: 'getGitConfig',
104
- });
105
- beforeEach(async () => {
106
- await (0, sandbox_1.resetSandbox)(cwd);
107
- await gitInit(cwd);
108
- await childProcess.exec(`git config user.name "John Doe"`, { cwd });
109
- await childProcess.exec(`git config user.email "john@jubii.dk"`, { cwd });
110
- });
111
- it('should retrive name', async () => {
112
- const name = await (0, git_1.getGitConfig)({
113
- dir: cwd,
114
- key: 'user.name',
115
- });
116
- expect(name).toEqual('John Doe');
117
- });
118
- it('should retrive email', async () => {
119
- const email = await (0, git_1.getGitConfig)({
120
- dir: cwd,
121
- key: 'user.email',
122
- });
123
- expect(email).toEqual('john@jubii.dk');
124
- });
125
- });
126
100
  describe('createBackportBranch', () => {
127
101
  const cwd = (0, sandbox_1.getSandboxPath)({
128
102
  filename: __filename,
@@ -243,9 +243,6 @@ describe('setupRepo', () => {
243
243
  jest
244
244
  .spyOn(gitModule, 'getLocalSourceRepoPath')
245
245
  .mockResolvedValue('/path/to/source/repo');
246
- jest
247
- .spyOn(gitModule, 'getGitConfig')
248
- .mockResolvedValue('email-or-username');
249
246
  mockGitClone();
250
247
  await (0, setupRepo_1.setupRepo)({
251
248
  repoName: 'kibana',
@@ -61,7 +61,7 @@ async function getOptions({ optionsFromCliArgs, optionsFromModule, }) {
61
61
  repoOwner,
62
62
  });
63
63
  const options = {
64
- // default author
64
+ // default author to filter commits by
65
65
  author: optionsFromGithub.authenticatedUsername,
66
66
  // default fork owner
67
67
  repoForkOwner: optionsFromGithub.authenticatedUsername,
@@ -1,14 +1,11 @@
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
- const promises_1 = __importDefault(require("fs/promises"));
7
3
  const child_process_promisified_1 = require("../../../lib/child-process-promisified");
8
4
  const getDevAccessToken_1 = require("../../private/getDevAccessToken");
9
5
  const sandbox_1 = require("../../sandbox");
10
6
  const runBackportViaCli_1 = require("./runBackportViaCli");
11
7
  const accessToken = (0, getDevAccessToken_1.getDevAccessToken)();
8
+ const COMMIT_BY_JOHN_DOE_SHA = 'c3f837226bea3c7a50f2ba16d807fbe846ed3453';
12
9
  describe('commit author', () => {
13
10
  let sourceRepo;
14
11
  let backportRepo;
@@ -17,76 +14,61 @@ describe('commit author', () => {
17
14
  await (0, sandbox_1.resetSandbox)(sandboxPath);
18
15
  sourceRepo = `${sandboxPath}/sourceRepo`;
19
16
  backportRepo = `${sandboxPath}/backportRepo`;
20
- await (0, child_process_promisified_1.exec)(`git clone https://github.com/backport-org/commit-author.git ${sourceRepo}`, { cwd: sandboxPath });
21
- await promises_1.default.writeFile(`${sandboxPath}/.backportrc.json`, JSON.stringify({
22
- repoName: 'commit-author',
23
- repoOwner: 'backport-org',
24
- }));
25
- });
26
- // eslint-disable-next-line jest/no-commented-out-tests
27
- // it('use commit author from source commit', async () => {
28
- // await runBackportViaCli(
29
- // [
30
- // `--accessToken=${accessToken}`,
31
- // `--dir=${backportRepo}`,
32
- // '--branch=production',
33
- // '--pr=2',
34
- // '--dry-run',
35
- // ],
36
- // { waitForString: 'Dry run complete', cwd: sourceRepo, showOra: true }
37
- // );
38
- // const { authorEmail, authorName } = await getCommitAuthor({
39
- // cwd: backportRepo,
40
- // });
41
- // expect(authorName).toEqual('Sonny Long (demo)');
42
- // expect(authorEmail).toEqual('71195571+sqren-demo@users.noreply.github.com');
43
- // });
44
- it('use commit author from git config in source repo', async () => {
17
+ await (0, child_process_promisified_1.exec)(`git clone https://github.com/backport-org/repo-with-different-commits-authors.git ${sourceRepo}`, { cwd: sandboxPath });
18
+ // set dummy git author. This should not have any effect and should never be used
45
19
  await (0, child_process_promisified_1.exec)(`git config user.name "Peter Kanin"`, { cwd: sourceRepo });
46
20
  await (0, child_process_promisified_1.exec)(`git config user.email "kanin@zoo.dk"`, { cwd: sourceRepo });
47
- await (0, runBackportViaCli_1.runBackportViaCli)([
48
- `--accessToken=${accessToken}`,
49
- `--dir=${backportRepo}`,
50
- '--branch=production',
51
- '--pr=2',
52
- '--dry-run',
53
- ], { cwd: sourceRepo, showOra: true });
54
- const { authorEmail, authorName } = await getCommitAuthor({
55
- cwd: backportRepo,
21
+ });
22
+ describe('when nothing is specified (default)', () => {
23
+ it('uses commit author from source commit', async () => {
24
+ await (0, runBackportViaCli_1.runBackportViaCli)([
25
+ `--accessToken=${accessToken}`,
26
+ `--dir=${backportRepo}`,
27
+ '--branch=production',
28
+ `--sha=${COMMIT_BY_JOHN_DOE_SHA}`,
29
+ '--dry-run',
30
+ ], { cwd: sourceRepo, showOra: true });
31
+ const { authorEmail, authorName } = await getCommitAuthor({
32
+ cwd: backportRepo,
33
+ });
34
+ expect(authorName).toEqual('John Doe');
35
+ expect(authorEmail).toEqual('john.doe@backport-testing.dk');
56
36
  });
57
- expect(authorName).toEqual('Peter Kanin');
58
- expect(authorEmail).toEqual('kanin@zoo.dk');
59
37
  });
60
- it('use commit author from cli args', async () => {
61
- await (0, runBackportViaCli_1.runBackportViaCli)([
62
- `--accessToken=${accessToken}`,
63
- `--dir=${backportRepo}`,
64
- '--branch=production',
65
- '--pr=2',
66
- '--dry-run',
67
- '--gitAuthorName="Donald Duck"',
68
- '--gitAuthorEmail=duck@disney.com',
69
- ], { cwd: sourceRepo, showOra: true });
70
- const { authorEmail, authorName } = await getCommitAuthor({
71
- cwd: backportRepo,
38
+ describe('when setting author via `--gitAuthor*` cli options', () => {
39
+ it('respects the settings', async () => {
40
+ await (0, runBackportViaCli_1.runBackportViaCli)([
41
+ `--accessToken=${accessToken}`,
42
+ `--dir=${backportRepo}`,
43
+ '--branch=production',
44
+ `--sha=${COMMIT_BY_JOHN_DOE_SHA}`,
45
+ '--dry-run',
46
+ '--gitAuthorName="Donald Duck"',
47
+ '--gitAuthorEmail=duck@disney.com',
48
+ ], { cwd: sourceRepo, showOra: true });
49
+ const { authorEmail, authorName } = await getCommitAuthor({
50
+ cwd: backportRepo,
51
+ });
52
+ expect(authorName).toEqual('Donald Duck');
53
+ expect(authorEmail).toEqual('duck@disney.com');
72
54
  });
73
- expect(authorName).toEqual('Donald Duck');
74
- expect(authorEmail).toEqual('duck@disney.com');
75
55
  });
76
- it('use resetAuthor option to set current user as author of commit', async () => {
77
- await (0, runBackportViaCli_1.runBackportViaCli)([
78
- `--accessToken=${accessToken}`,
79
- `--dir=${backportRepo}`,
80
- '--branch=production',
81
- '--pr=2',
82
- '--dry-run',
83
- '--reset-author',
84
- ], { cwd: sourceRepo, showOra: true });
85
- const { authorEmail, authorName } = await getCommitAuthor({
86
- cwd: backportRepo,
56
+ describe('when using `--resetAuthor` option', () => {
57
+ it('sets the current user as author of commit', async () => {
58
+ await (0, runBackportViaCli_1.runBackportViaCli)([
59
+ `--accessToken=${accessToken}`,
60
+ `--dir=${backportRepo}`,
61
+ '--branch=production',
62
+ `--sha=${COMMIT_BY_JOHN_DOE_SHA}`,
63
+ '--dry-run',
64
+ '--reset-author',
65
+ ], { cwd: sourceRepo, showOra: true });
66
+ const { authorEmail, authorName } = await getCommitAuthor({
67
+ cwd: backportRepo,
68
+ });
69
+ expect(authorName).toEqual('sqren');
70
+ expect(authorEmail).toEqual('sqren@users.noreply.github.com');
87
71
  });
88
- expect(authorName).toEqual('sqren');
89
- expect(authorEmail).toEqual('sqren@users.noreply.github.com');
90
72
  });
91
73
  });
92
74
  async function getCommitAuthor({ cwd }) {
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "8.5.2";
1
+ export declare const PACKAGE_VERSION = "8.5.3";
@@ -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 = '8.5.2';
4
+ exports.PACKAGE_VERSION = '8.5.3';
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "branches",
15
15
  "branching"
16
16
  ],
17
- "version": "8.5.2",
17
+ "version": "8.5.3",
18
18
  "main": "./dist/entrypoint.module.js",
19
19
  "types": "dist/entrypoint.module.d.ts",
20
20
  "bin": {