Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Show all commits in list #297

Merged
merged 25 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
/dist
/yarn-error.log
.DS_Store
/src/test/private/accessToken.txt
/src/test/_tmp_sandbox_

/.env
15 changes: 2 additions & 13 deletions .graphqlrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
const fs = require('fs');
const path = require('path');
require('dotenv').config();

// get credentials from config file
const accessTokenFile = path.resolve(
__dirname,
'./src/test/private/accessToken.txt'
);

const accessToken = fs
.readFileSync(accessTokenFile, {
encoding: 'utf-8',
})
.trim();
const accessToken = process.env.ACCESS_TOKEN;

module.exports = {
schema: 'github-schema.graphql',
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,20 @@ console.log(commits);

/*
[{
committedDate: '2021-12-20T14:20:16Z',
soureCommit: {
committedDate: '2021-12-20T14:20:16Z',
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
message: '[APM] Add note about synthtrace to APM docs (#121633)',
},
sourcePullRequest: {
number: 121633,
url: 'https://github.com/elastic/kibana/pull/121633'
mergeCommit: {
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
message: '[APM] Add note about synthtrace to APM docs (#121633)',
}
},
sourceBranch: 'main',
sha: 'd421ddcf6157150596581c7885afa3690cec6339',
originalMessage: '[APM] Add note about synthtrace to APM docs (#121633)',
pullNumber: 121633,
pullUrl: 'https://github.com/elastic/kibana/pull/121633',
expectedTargetPullRequests: [
{
url: 'https://github.com/elastic/kibana/pull/121643',
Expand Down
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"branches",
"branching"
],
"version": "6.2.1",
"version": "6.3.0-beta-10",
"main": "./dist/entrypoint.module.js",
"types": "dist/entrypoint.module.d.ts",
"bin": {
Expand All @@ -23,12 +23,12 @@
"license": "MIT",
"scripts": {
"postinstall": "test -f ./dist/scripts/runPostinstall.js && node ./dist/scripts/runPostinstall.js || echo 'Dist folder missing'",
"postversion": "yarn extractPackageVersion && yarn build",
"version": "echo \"Bumping version\" && yarn extractPackageVersion && git add src/utils/packageVersion.ts && yarn build",
"prepare": "husky install",
"prepublishOnly": "yarn build",
"prepublishOnly": "yarn lint",
"build": "tsc --project ./tsconfig.prod.json",
"extractPackageVersion": "node -p \"'export const PACKAGE_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" | prettier > src/utils/packageVersion.ts",
"lint": "tsc --project ./tsconfig.test.json && eslint './**/*.{ts,js}'",
"lint": "echo \"Running lint\" && tsc --project ./tsconfig.test.json && eslint './**/*.{ts,js}'",
"start": "ts-node --transpile-only ./src/entrypoint.cli.ts",
"test-all": "yarn lint && jest --config ./jest.config.all.js",
"test-mutation": "jest --config ./jest.config.mutation.js",
Expand Down Expand Up @@ -66,7 +66,9 @@
"axios": "^0.25.0",
"dedent": "^0.7.0",
"del": "^6.0.0",
"dotenv": "^16.0.0",
"find-up": "^5.0.0",
"graphql-tag": "^2.12.6",
"inquirer": "^8.2.0",
"lodash": "^4.17.21",
"make-dir": "^3.1.0",
Expand All @@ -76,7 +78,8 @@
"terminal-link": "^2.1.1",
"utility-types": "^3.10.0",
"winston": "^3.5.1",
"yargs": "^17.3.1"
"yargs": "^17.3.1",
"yargs-parser": "^21.0.0"
},
"devDependencies": {
"@types/core-js": "^2.5.5",
Expand All @@ -88,25 +91,24 @@
"@types/safe-json-stringify": "^1.1.2",
"@types/yargs": "^17.0.8",
"@types/yargs-parser": "^20.2.1",
"@typescript-eslint/eslint-plugin": "^5.10.2",
"@typescript-eslint/parser": "^5.10.2",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"eslint": "^8.8.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.0.0",
"eslint-plugin-jest": "^26.1.0",
"eslint-plugin-prettier": "^4.0.0",
"graphql": "^16.3.0",
"graphql-config": "^4.1.0",
"graphql-tag": "^2.12.6",
"husky": "^7.0.4",
"jest": "^27.4.7",
"jest": "^27.5.1",
"jest-snapshot-serializer-ansi": "^1.0.0",
"lint-staged": "^12.3.3",
"nock": "^13.2.4",
"prettier": "^2.5.1",
"strip-ansi": "^6.0.1",
"ts-jest": "^27.1.3",
"ts-node": "^10.4.0",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
}
}
18 changes: 13 additions & 5 deletions src/backportRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ export async function backportRun(

try {
options = await getOptions(processArgs, optionsFromModule);
logger.info('Backporting options', options);

spinner.stop();

commits = await getCommits(options);
logger.info('Commits', commits);

const targetBranches = await getTargetBranches(options, commits);
logger.info('Target branches', targetBranches);

const results = await runSequentially({ options, commits, targetBranches });
logger.info('Results', results);

const backportResponse: BackportResponse = {
status: 'success',
commits,
Expand Down Expand Up @@ -84,8 +93,7 @@ export async function backportRun(
// output
consoleLog('\n');
consoleLog(chalk.bold('⚠️ Ouch! An unhandled error occured 😿'));
consoleLog(`Error message: ${e.message}`);

consoleLog(e.stack ? e.stack : e.message);
consoleLog(
'Please open an issue in https://github.com/sqren/backport/issues or contact me directly on https://twitter.com/sorenlouv'
);
Expand All @@ -97,11 +105,11 @@ export async function backportRun(
})}`
)
);

// write to log
logger.info('Unknown error:', e);
}

logger.error('Unhandled exception', e);
process.exitCode = 1;

return backportResponse;
}
}
75 changes: 54 additions & 21 deletions src/entrypoint.cli.e2e.private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import stripAnsi from 'strip-ansi';
import { exec } from './services/child-process-promisified';
import { getDevAccessToken } from './test/private/getDevAccessToken';
import { getSandboxPath, resetSandbox } from './test/sandbox';
import * as packageVersion from './utils/packageVersion';

const TIMEOUT_IN_SECONDS = 10;

jest.setTimeout(15000);

describe('inquirer cli', () => {
let devAccessToken: string;

beforeAll(async () => {
devAccessToken = await getDevAccessToken();
});
const devAccessToken = getDevAccessToken();

describe('inquirer cli', () => {
it('--version', async () => {
const res = await runBackportAsync([`--version`]);
expect(res).toContain(process.env.npm_package_version);
Expand All @@ -26,6 +23,13 @@ describe('inquirer cli', () => {
expect(res).toContain(process.env.npm_package_version);
});

it('PACKAGE_VERSION should match', async () => {
// @ts-expect-error
expect(packageVersion.UNMOCKED_PACKAGE_VERSION).toBe(
process.env.npm_package_version
);
});

it('--help', async () => {
const res = await runBackportAsync([`--help`]);
expect(res).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -73,13 +77,16 @@ describe('inquirer cli', () => {
--reviewer Add reviewer to the target PR [array]
--repoOwner Repository owner [string]
--repoName Repository name [string]
--repo Repo owner and name [string]
--sha, --commit Commit sha to backport [string]
--sourceBranch Specify a non-default branch (normally \\"master\\") to backport
from [string]
--sourcePRLabel, --sourcePrLabel Add labels to the source (original) PR [array]
-b, --targetBranch, --branch Branch(es) to backport to [array]
--targetBranchChoice List branches to backport to [array]
-l, --targetPRLabel, --label Add labels to the target (backport) PR [array]
--username User repo that branch will be pushed to. Defaults to the
authenticated user [string]
--verbose Show additional debug information [boolean]
--verify Opposite of no-verify [boolean]
--help Show help [boolean]
Expand Down Expand Up @@ -126,9 +133,10 @@ describe('inquirer cli', () => {
4. Add family emoji (#2) 7.x
5. Add \`backport\` dep
6. Merge pull request #1 from backport-org/add-heart-emoji
7. Update .backportrc.json
8. Bump to 8.0.0
9. Add package.json"
7. Add ❤️ emoji
8. Update .backportrc.json
9. Bump to 8.0.0
10.Add package.json"
`);
});

Expand Down Expand Up @@ -197,7 +205,7 @@ describe('inquirer cli', () => {
`);
});

it(`should limit commits by since and until`, async () => {
it(`should filter commits by "since" and "until"`, async () => {
jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
const output = await runBackportAsync(
[
Expand All @@ -210,24 +218,19 @@ describe('inquirer cli', () => {
'--accessToken',
devAccessToken,
'--since',
'2020-08-15T00:00:00.000Z',
'2020-08-15T10:00:00.000Z',
'--until',
'2020-08-15T14:00:00.000Z',
'2020-08-15T10:30:00.000Z',
],
{ waitForString: 'Select commit' }
);

expect(output).toMatchInlineSnapshot(`
"? Select commit (Use arrow keys)
❯ 1. Add 🍏 emoji (#5) 7.x, 7.8
2. Add family emoji (#2) 7.x
3. Add \`backport\` dep
4. Merge pull request #1 from backport-org/add-heart-emoji
5. Update .backportrc.json
6. Bump to 8.0.0
7. Add package.json
8. Update .backportrc.json
9. Create .backportrc.json"
❯ 1. Bump to 8.0.0
2. Add package.json
3. Update .backportrc.json
4. Create .backportrc.json"
`);
});

Expand Down Expand Up @@ -262,6 +265,36 @@ describe('inquirer cli', () => {
6. Bump to 8.0.0"
`);
});

describe('repo: different-merge-strategies', () => {
it('list all commits regardless how they were merged', async () => {
jest.setTimeout(TIMEOUT_IN_SECONDS * 1000 * 1.1);
const output = await runBackportAsync(
[
'--branch',
'foo',
'--repo-owner',
'backport-org',
'--repo-name',
'different-merge-strategies',
'--accessToken',
devAccessToken,
],
{ waitForString: 'Select commit' }
);

expect(output).toMatchInlineSnapshot(`
"? Select commit (Use arrow keys)
❯ 1. Using squash to merge commits (#3) 7.x
2. Rebase strategy: Second commit 7.x
3. Rebase strategy: First commit
4. Merge pull request #1 from backport-org/merge-strategy
5. Merge strategy: Second commit
6. Merge strategy: First commit
7. Initial commit"
`);
});
});
});

function runBackportAsync(
Expand Down
30 changes: 20 additions & 10 deletions src/entrypoint.cli.private.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import { getCommits } from './entrypoint.module';
import { Commit, getCommits } from './entrypoint.module';
import { getDevAccessToken } from './test/private/getDevAccessToken';

describe('entrypoint.module', () => {
it('getCommits', async () => {
const accessToken = await getDevAccessToken();
const accessToken = getDevAccessToken();
const commits = await getCommits({
accessToken: accessToken,
repoName: 'backport-e2e',
repoOwner: 'backport-org',
pullNumber: 2,
});

expect(commits).toEqual([
const expectedCommits: Commit[] = [
{
committedDate: '2020-08-15T10:44:04Z',
sourceCommit: {
committedDate: '2020-08-15T10:44:04Z',
message: 'Add family emoji (#2)',
sha: '59d6ff1ca90a4ce210c0a4f0e159214875c19d60',
},
sourcePullRequest: {
number: 2,
url: 'https://github.com/backport-org/backport-e2e/pull/2',
mergeCommit: {
message: 'Add family emoji (#2)',
sha: '59d6ff1ca90a4ce210c0a4f0e159214875c19d60',
},
},
sourceBranch: 'master',
expectedTargetPullRequests: [
{
branch: '7.x',
Expand All @@ -26,12 +39,9 @@ describe('entrypoint.module', () => {
},
},
],
originalMessage: 'Add family emoji (#2)',
pullNumber: 2,
pullUrl: 'https://github.com/backport-org/backport-e2e/pull/2',
sha: '59d6ff1ca90a4ce210c0a4f0e159214875c19d60',
sourceBranch: 'master',
},
]);
];

expect(commits).toEqual(expectedCommits);
});
});
5 changes: 3 additions & 2 deletions src/options/ConfigOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from '../services/logger';
import winston from 'winston';

export interface TargetBranchChoice {
name: string;
Expand All @@ -14,7 +14,7 @@ type AutoFixConflictsHandler = ({
}: {
files: string[];
directory: string;
logger: Logger;
logger: winston.Logger;
targetBranch: string;
}) => boolean | Promise<boolean>;

Expand Down Expand Up @@ -60,6 +60,7 @@ type Options = Partial<{
targetBranchChoices: TargetBranchChoiceOrString[];
targetBranches: string[];
targetPRLabels: string[];
username: string;
verbose: boolean;
}>;

Expand Down
Loading