Skip to content

Commit

Permalink
Merge 9e4509a into 679a028
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Dec 19, 2021
2 parents 679a028 + 9e4509a commit c16cd1c
Show file tree
Hide file tree
Showing 44 changed files with 1,441 additions and 1,455 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Please note that dashes between the words are optional, for instance you can typ
| --path | -p | Only list commits touching files under a specific path | | `string` |
| --pull-number | --pr | Pull request to backport | | `number` |
| --pr-description | --description | Pull request description suffix | | `string` |
| --pr-filter | | List commits from PRs filtered by a given query | | `string` |
| --pr-filter | | Find PRs using [Github's search syntax][1] | | `string` |
| --pr-title | --title | Title of pull request | | `string` |
| --reset-author | | Set yourself as commit author | | `boolean` |
| --sha | | Sha of commit to backport | | `string` |
Expand Down Expand Up @@ -119,3 +119,5 @@ This tools is for anybody who is working on a codebase where they have to mainta
## Contributing

See [CONTRIBUTING.md](https://github.com/sqren/backport/blob/master/CONTRIBUTING.md)

[1]: https://docs.github.com/en/search-github/getting-started-with-searching-on-github/understanding-the-search-syntax
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"ora": "^5.4.1",
"safe-json-stringify": "^1.2.0",
"strip-json-comments": "^3.1.1",
"terminal-link": "^2.1.1",
"winston": "^3.3.3",
"yargs": "^17.3.0"
},
Expand All @@ -84,22 +85,22 @@
"@types/yargs-parser": "^20.2.1",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"eslint": "^8.4.1",
"eslint": "^8.5.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jest": "^25.3.0",
"eslint-plugin-prettier": "^4.0.0",
"graphql": "^16.1.0",
"graphql": "^16.2.0",
"graphql-config": "^4.1.0",
"graphql-tag": "^2.12.6",
"husky": "^7.0.4",
"jest": "^27.4.5",
"jest-snapshot-serializer-ansi": "^1.0.0",
"lint-staged": "^12.1.2",
"lint-staged": "^12.1.3",
"nock": "^13.2.1",
"prettier": "^2.5.1",
"strip-ansi": "^6.0.1",
"ts-jest": "^27.1.1",
"ts-jest": "^27.1.2",
"ts-node": "^10.4.0",
"typescript": "^4.5.4"
}
Expand Down
2 changes: 1 addition & 1 deletion src/entrypoint.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function run(
// public API
export { BackportResponse } from './main';
export { ConfigOptions } from './options/ConfigOptions';
export { getTargetBranchForLabel } from './services/github/v4/getTargetBranchesFromLabels';
export { getTargetBranchForLabel } from './services/sourceCommit/getExpectedTargetPullRequests';
export { fetchCommitsByAuthor } from './services/github/v4/fetchCommits/fetchCommitsByAuthor';
export { fetchCommitByPullNumber } from './services/github/v4/fetchCommits/fetchCommitByPullNumber';
export { fetchCommitBySha } from './services/github/v4/fetchCommits/fetchCommitBySha';
5 changes: 3 additions & 2 deletions src/options/ConfigOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ export type ConfigOptions = Partial<{
assignees: string[];
author: string;
autoAssign: boolean;
autoFixConflicts: AutoFixConflictsHandler;
autoMerge: boolean;
autoMergeMethod: string;
autoFixConflicts: AutoFixConflictsHandler;
branchLabelMapping: Record<string, string>;
ci: boolean;
commitPaths: string[];
details: boolean;
editor: string;
forceLocalConfig: boolean;
fork: boolean;
Expand All @@ -40,7 +42,6 @@ export type ConfigOptions = Partial<{
multipleBranches: boolean;
multipleCommits: boolean;
noVerify: boolean;
commitPaths: string[];
prDescription: string;
prFilter: string;
prTitle: string;
Expand Down
39 changes: 22 additions & 17 deletions src/options/cliArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ export function getOptionsFromCliArgs(
type: 'boolean',
})

.option('author', {
description: 'Show commits by specific author',
type: 'string',
})

.option('assignee', {
description: 'Add assignees to the target pull request',
alias: 'assign',
Expand All @@ -40,6 +35,11 @@ export function getOptionsFromCliArgs(
conflicts: ['autoAssign'],
})

.option('author', {
description: 'Show commits by specific author',
type: 'string',
})

.option('autoAssign', {
description: 'Auto assign the target pull request to yourself',
type: 'boolean',
Expand All @@ -63,6 +63,11 @@ export function getOptionsFromCliArgs(
type: 'boolean',
})

.option('details', {
description: 'Show details about each commit',
type: 'boolean',
})

.option('editor', {
description: 'Editor to be opened during conflict resolution',
type: 'string',
Expand Down Expand Up @@ -158,18 +163,18 @@ export function getOptionsFromCliArgs(
string: true,
})

.option('prTitle', {
description: 'Title of pull request',
alias: 'title',
type: 'string',
})

.option('prDescription', {
description: 'Description to be added to pull request',
alias: 'description',
type: 'string',
})

.option('prTitle', {
description: 'Title of pull request',
alias: 'title',
type: 'string',
})

.option('prFilter', {
conflicts: ['pullNumber', 'sha'],
description: `Filter source pull requests by a query`,
Expand Down Expand Up @@ -227,12 +232,6 @@ export function getOptionsFromCliArgs(
string: true,
})

// cli-only
.option('verify', {
description: `Opposite of no-verify`,
type: 'boolean',
})

.option('upstream', {
description: 'Name of repository',
alias: 'up',
Expand All @@ -249,6 +248,12 @@ export function getOptionsFromCliArgs(
type: 'boolean',
})

// cli-only
.option('verify', {
description: `Opposite of no-verify`,
type: 'boolean',
})

.alias('version', 'v')
.alias('version', 'V')
.help()
Expand Down
1 change: 1 addition & 0 deletions src/options/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('getOptionsFromConfigFiles', () => {
autoMerge: false,
autoMergeMethod: 'merge',
ci: false,
details: false,
fork: true,
gitHostname: 'github.com',
githubApiBaseUrlV3: 'https://api.github.com',
Expand Down
3 changes: 2 additions & 1 deletion src/options/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const defaultConfigOptions = {
autoMerge: false,
autoMergeMethod: 'merge',
ci: false,
details: false,
fork: true,
gitHostname: 'github.com',
githubApiBaseUrlV3: 'https://api.github.com',
Expand All @@ -22,8 +23,8 @@ export const defaultConfigOptions = {
prTitle: '[{targetBranch}] {commitMessages}',
resetAuthor: false,
sourcePRLabels: [],
targetBranches: [],
targetBranchChoices: [],
targetBranches: [],
targetPRLabels: [],
verbose: false,
};
Expand Down
1 change: 1 addition & 0 deletions src/options/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe('getOptions', () => {
autoMerge: false,
autoMergeMethod: 'merge',
ci: false,
details: false,
fork: true,
gitHostname: 'github.com',
githubApiBaseUrlV3: 'https://api.github.com',
Expand Down
15 changes: 8 additions & 7 deletions src/runWithOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ describe('runWithOptions', () => {
autoMergeMethod: 'merge',
branchLabelMapping: undefined,
ci: false,
commitPaths: [],
details: false,
editor: 'code',
forceLocalConfig: undefined,
fork: true,
Expand All @@ -66,19 +68,18 @@ describe('runWithOptions', () => {
multipleBranches: false,
multipleCommits: false,
noVerify: true,
commitPaths: [],
prDescription: 'myPrDescription',
prFilter: undefined,
prTitle: 'myPrTitle {targetBranch} {commitMessages}',
pullNumber: undefined,
upstream: 'elastic/kibana',
repoName: 'kibana',
repoOwner: 'elastic',
resetAuthor: false,
sha: undefined,
sourceBranch: 'my-source-branch-from-options',
sourcePRLabels: [],
prFilter: undefined,
targetBranches: [],
upstream: 'elastic/kibana',
targetBranchChoices: [
{ name: '6.x' },
{ name: '6.0' },
Expand Down Expand Up @@ -144,7 +145,7 @@ describe('runWithOptions', () => {
base: '6.x',
body: 'Backports the following commits to 6.x:\n - Add 👻 (2e63475c)\n\nmyPrDescription',
head: 'sqren:backport/6.x/commit-2e63475c',
title: 'myPrTitle 6.x Add 👻 (2e63475c)',
title: 'myPrTitle 6.x Add 👻',
},
]);
});
Expand Down Expand Up @@ -192,7 +193,7 @@ describe('runWithOptions', () => {
).toMatchInlineSnapshot(`
Array [
Object {
"name": "1. Add 👻 (2e63475c) ",
"name": "1. Add 👻 ",
"short": "2e63475c",
},
Object {
Expand All @@ -204,11 +205,11 @@ describe('runWithOptions', () => {
"short": "#80 (79cf1845)",
},
Object {
"name": "4. Add backport config (3827bbba) ",
"name": "4. Add backport config ",
"short": "3827bbba",
},
Object {
"name": "5. Initial commit (5ea0da55) ",
"name": "5. Initial commit ",
"short": "5ea0da55",
},
]
Expand Down
11 changes: 2 additions & 9 deletions src/services/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
getUpstreamFromGitRemote,
getIsCommitInBranch,
} from './git';
import { Commit } from './sourceCommit';
import { Commit } from './sourceCommit/parseSourceCommit';

jest.unmock('make-dir');
jest.unmock('del');
Expand Down Expand Up @@ -392,16 +392,9 @@ describe('cherrypick', () => {
const commit: Commit = {
committedDate: '2021-01-25T00:00:00',
sourceBranch: '7.x',
formattedMessage: '',
originalMessage: '',
sha: 'abcd',
targetBranchesFromLabels: {
expected: [],
missing: [],
unmerged: [],
merged: [],
},
existingTargetPullRequests: [],
expectedTargetPullRequests: [],
};

it('should return `needsResolving: false` when no errors are encountered', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/services/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getRepoOwnerPath, getRepoPath } from './env';
import { stat } from './fs-promisified';
import { getShortSha } from './github/commitFormatters';
import { logger } from './logger';
import { Commit } from './sourceCommit';
import { Commit } from './sourceCommit/parseSourceCommit';

async function folderExists(path: string): Promise<boolean> {
try {
Expand Down Expand Up @@ -313,7 +313,7 @@ export async function setCommitAuthor(
options: ValidConfigOptions,
username: string
) {
const spinner = ora(`Changing author to "${options.username}"`).start();
const spinner = ora(`Changing author to "${username}"`).start();
try {
const res = await exec(
`git commit --amend --no-edit --author "${username} <${username}@users.noreply.github.com>"`,
Expand Down
42 changes: 3 additions & 39 deletions src/services/github/commitFormatters.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,15 @@
import {
getFirstCommitMessageLine,
getFormattedCommitMessage,
} from './commitFormatters';
import { getFirstLine } from './commitFormatters';

describe('getFirstCommitMessageLine', () => {
it('should only return the first line of the message', () => {
expect(
getFirstCommitMessageLine(
getFirstLine(
'My commit message (#1234)\n\n Additional commit message body'
)
).toEqual('My commit message (#1234)');
});

it('should return the commit message as-is', () => {
expect(getFirstCommitMessageLine('My commit message')).toEqual(
'My commit message'
);
});
});

describe('getFormattedCommitMessage', () => {
it('should return the first message line verbatim', () => {
expect(
getFormattedCommitMessage({
message: 'This is my commit message (#1234)\n\nthis is a second line',
pullNumber: 1234,
sha: 'sha123456789',
})
).toBe('This is my commit message (#1234)');
});

it('should add pullNumber as suffix', () => {
expect(
getFormattedCommitMessage({
message: 'This is my commit message\n\nthis is a second line',
pullNumber: 1234,
sha: 'sha123456789',
})
).toBe('This is my commit message (#1234)');
});

it('should add commit sha as suffix', () => {
expect(
getFormattedCommitMessage({
message: 'This is my commit message\n\nthis is a second line',
sha: 'sha123456789',
})
).toBe('This is my commit message (sha12345)');
expect(getFirstLine('My commit message')).toEqual('My commit message');
});
});
Loading

0 comments on commit c16cd1c

Please sign in to comment.