Skip to content

Commit

Permalink
Bump to Node.js 12 (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Jul 24, 2021
1 parent 2dba5e5 commit ede4124
Show file tree
Hide file tree
Showing 28 changed files with 2,443 additions and 2,830 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
},
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
'plugin:jest/recommended',
'eslint:recommended',
Expand Down
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.22.3
12 changes: 3 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
os:
- linux
- osx
addons:
apt:
sources:
- ppa:git-core/ppa
packages:
- git
language: node_js
node_js:
- '10'
- '12'
- '14'
cache: yarn
before_script:
- yarn
Expand All @@ -19,8 +13,8 @@ before_script:
script:
- yarn tsc
- yarn eslint './**/*.{ts,js}'
- 'if [ -n "$accessToken" ]; then yarn jest --config ./jest.config.all.js --coverage; fi'
- 'if [ -z "$accessToken" ]; then yarn jest --config ./jest.config.js; fi'
- 'if [ -n "$accessToken" ]; then echo "Running public and private tests" && yarn jest --config ./jest.config.all.js --coverage; fi'
- 'if [ -z "$accessToken" ]; then echo "Running only public tests (excluding private ones) " && yarn jest --config ./jest.config.js; fi'
after_success:
- npm install -g coveralls
- cat coverage/lcov.info | coveralls
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A simple CLI tool that automates the process of backporting commits on a GitHub

## Requirements

- Node 10 or higher
- Node 12 or higher
- git

## Install
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
setupFiles: ['./src/test/setupFiles/automatic-mocks.ts'],
preset: 'ts-jest',
testRegex: 'src/.*test.ts$',
testEnvironment: 'node',

// exclude private tests that requires credentials and can therefore not run on CI for external contributors
modulePathIgnorePatterns: ['.*.private.test.ts$'],
Expand Down
63 changes: 29 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@
"bin": {
"backport": "./dist/entrypoint.cli.js"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "yarn lint"
}
},
"license": "MIT",
"scripts": {
"lint": "tsc --project ./tsconfig.test.json && eslint './**/*.{ts,js}'",
"prepare": "husky install",
"postinstall": "test -f ./dist/scripts/runPostinstall.js && node ./dist/scripts/runPostinstall.js || echo 'Dist folder missing'",
"prepublishOnly": "tsc --project ./tsconfig.prod.json",
"test": "jest",
Expand Down Expand Up @@ -60,25 +55,25 @@
]
},
"engines": {
"node": ">=10.0.0"
"node": ">=12.0.0"
},
"dependencies": {
"@octokit/rest": "^18.0.12",
"@octokit/rest": "^18.7.1",
"@types/lodash.difference": "^4.5.6",
"@types/lodash.intersection": "^4.4.6",
"axios": "^0.21.1",
"dedent": "^0.7.0",
"del": "^6.0.0",
"find-up": "^5.0.0",
"inquirer": "^7.3.3",
"inquirer": "^8.1.2",
"lodash.difference": "^4.5.0",
"lodash.flatmap": "^4.5.0",
"lodash.intersection": "^4.4.0",
"lodash.isempty": "^4.4.0",
"lodash.isstring": "^4.0.1",
"lodash.uniq": "^4.5.0",
"make-dir": "^3.1.0",
"ora": "^5.3.0",
"ora": "^5.4.1",
"safe-json-stringify": "^1.2.0",
"strip-json-comments": "^3.1.1",
"winston": "^3.3.3",
Expand All @@ -87,36 +82,36 @@
"devDependencies": {
"@types/core-js": "^2.5.4",
"@types/dedent": "^0.7.0",
"@types/inquirer": "^7.3.1",
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.168",
"@types/inquirer": "^7.3.3",
"@types/jest": "^26.0.24",
"@types/lodash": "^4.14.171",
"@types/lodash.flatmap": "^4.5.6",
"@types/lodash.isempty": "^4.4.6",
"@types/lodash.isstring": "^4.0.6",
"@types/lodash.uniq": "^4.5.6",
"@types/node": "^14.14.22",
"@types/node": "^16.4.1",
"@types/safe-json-stringify": "^1.1.2",
"@types/yargs": "^15.0.12",
"@types/yargs-parser": "^20.2.0",
"@typescript-eslint/eslint-plugin": "^4.14.0",
"@typescript-eslint/parser": "^4.14.0",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-prettier": "^3.3.1",
"graphql": "^15.4.0",
"graphql-tag": "^2.11.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
"@types/yargs": "^16.0.4",
"@types/yargs-parser": "^20.2.1",
"@typescript-eslint/eslint-plugin": "^4.28.4",
"@typescript-eslint/parser": "^4.28.4",
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-prettier": "^3.4.0",
"graphql": "^15.5.1",
"graphql-tag": "^2.12.5",
"husky": "^7.0.1",
"jest": "^27.0.6",
"jest-snapshot-serializer-ansi": "^1.0.0",
"lint-staged": "^10.5.3",
"lodash": "^4.17.20",
"nock": "^13.0.6",
"prettier": "^2.2.0",
"lint-staged": "^11.1.1",
"lodash": "^4.17.21",
"nock": "^13.1.1",
"prettier": "^2.3.2",
"strip-ansi": "^6.0.0",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"ts-jest": "^27.0.4",
"ts-node": "^10.1.0",
"typescript": "^4.3.5"
}
}
8 changes: 4 additions & 4 deletions src/options/ConfigOptions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Logger } from '../services/logger';

export interface BranchChoice {
export interface TargetBranchChoice {
name: string;
checked?: boolean;
}
export type BranchChoiceRaw = string | BranchChoice;
export type TargetBranchChoiceOrString = string | TargetBranchChoice;

type AutoFixConflictsHandler = ({
files,
Expand Down Expand Up @@ -49,15 +49,15 @@ export type ConfigOptions = Partial<{
sha: string;
sourceBranch: string;
sourcePRLabels: string[];
targetBranchChoices: BranchChoiceRaw[];
targetBranchChoices: TargetBranchChoiceOrString[];
targetBranches: string[];
targetPRLabels: string[];
upstream: string;
username: string;
verbose: boolean;

// deprecated: renamed to `targetBranchChoices`
branches: BranchChoiceRaw[];
branches: TargetBranchChoiceOrString[];

// deprecated: renamed to `targetPRLabels`
labels: string[];
Expand Down
4 changes: 1 addition & 3 deletions src/options/config/globalConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ describe('config', () => {
});

it("should create config if it doesn't exist", () => {
expect(
fs.writeFile
).toHaveBeenCalledWith(
expect(fs.writeFile).toHaveBeenCalledWith(
'/myHomeDir/.backport/config.json',
expect.any(String),
{ flag: 'wx', mode: 384 }
Expand Down
2 changes: 1 addition & 1 deletion src/options/config/projectConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('getProjectConfig', () => {

describe('when projectConfig is missing', () => {
it('should return empty config', async () => {
((findUp as any) as jest.SpyInstance).mockReturnValueOnce(undefined);
(findUp as any as jest.SpyInstance).mockReturnValueOnce(undefined);
const projectConfig = await getProjectConfig();
expect(projectConfig).toEqual(undefined);
});
Expand Down
15 changes: 9 additions & 6 deletions src/options/parseRequiredOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import isString from 'lodash.isstring';
import { HandledError } from '../services/HandledError';
import { getGlobalConfigPath } from '../services/env';
import { OptionsFromGithub } from '../services/github/v4/getOptionsFromGithub';
import { BranchChoiceRaw, BranchChoice, ConfigOptions } from './ConfigOptions';
import {
TargetBranchChoiceOrString,
TargetBranchChoice,
ConfigOptions,
} from './ConfigOptions';
import { OptionsFromCliArgs } from './cliArgs';
import { OptionsFromConfigFiles } from './config/config';

Expand Down Expand Up @@ -42,9 +46,8 @@ export function parseRequiredOptions(
);
}

const { accessToken, username, repoName, repoOwner } = getRequiredOptions(
options
);
const { accessToken, username, repoName, repoOwner } =
getRequiredOptions(options);

return {
...options,
Expand Down Expand Up @@ -73,8 +76,8 @@ export function parseRequiredOptions(
// `branches` can either be a string or an object.
// It must be transformed so it is always treated as an object troughout the application
function getTargetBranchChoicesAsObject(
targetBranchChoices: BranchChoiceRaw[]
): BranchChoice[] {
targetBranchChoices: TargetBranchChoiceOrString[]
): TargetBranchChoice[] {
return targetBranchChoices.map((choice) => {
if (isString(choice)) {
return {
Expand Down
3 changes: 1 addition & 2 deletions src/runWithOptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ describe('runWithOptions', () => {
expect(createPullRequestCalls).toEqual([
{
base: '6.x',
body:
'Backports the following commits to 6.x:\n - Add 👻 (2e63475c)\n\nmyPrDescription',
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)',
},
Expand Down
12 changes: 3 additions & 9 deletions src/services/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,7 @@ describe('addRemote', () => {
.mockResolvedValueOnce({ stderr: '', stdout: '' });
await addRemote(options, 'elastic');

return expect(
spy
).toHaveBeenCalledWith(
return expect(spy).toHaveBeenCalledWith(
'git remote add elastic https://x-access-token:myAccessToken@github.com/elastic/kibana.git',
{ cwd: '/myHomeDir/.backport/repositories/elastic/kibana' }
);
Expand All @@ -605,9 +603,7 @@ describe('addRemote', () => {
.mockResolvedValueOnce({ stderr: '', stdout: '' });
await addRemote(options, 'sqren');

return expect(
spy
).toHaveBeenCalledWith(
return expect(spy).toHaveBeenCalledWith(
'git remote add sqren https://x-access-token:myAccessToken@github.com/sqren/kibana.git',
{ cwd: '/myHomeDir/.backport/repositories/elastic/kibana' }
);
Expand All @@ -622,9 +618,7 @@ describe('addRemote', () => {
'sqren'
);

return expect(
spy
).toHaveBeenCalledWith(
return expect(spy).toHaveBeenCalledWith(
'git remote add sqren https://x-access-token:myAccessToken@github.my-company.com/sqren/kibana.git',
{ cwd: '/myHomeDir/.backport/repositories/elastic/kibana' }
);
Expand Down
14 changes: 4 additions & 10 deletions src/services/github/v4/fetchCommitByPullNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ import { getTargetBranchesFromLabels } from './getTargetBranchesFromLabels';
export async function fetchCommitByPullNumber(
options: ValidConfigOptions & { pullNumber: number }
): Promise<Commit> {
const {
accessToken,
githubApiBaseUrlV4,
pullNumber,
repoName,
repoOwner,
} = options;
const { accessToken, githubApiBaseUrlV4, pullNumber, repoName, repoOwner } =
options;
const query = /* GraphQL */ `
query CommitByPullNumber(
$repoOwner: String!
Expand Down Expand Up @@ -85,9 +80,8 @@ export async function fetchCommitByPullNumber(
)}`,
});

const existingTargetPullRequests = getExistingTargetPullRequests(
pullRequestNode
);
const existingTargetPullRequests =
getExistingTargetPullRequests(pullRequestNode);

const targetBranchesFromLabels = getTargetBranchesFromLabels({
sourceBranch: pullRequestNode.baseRefName,
Expand Down
5 changes: 2 additions & 3 deletions src/services/github/v4/fetchCommitBySha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ export async function fetchCommitBySha(
text: `${chalk.bold('Select commit')} ${chalk.cyan(formattedMessage)}`,
});

const existingTargetPullRequests = getExistingTargetPullRequests(
pullRequestNode
);
const existingTargetPullRequests =
getExistingTargetPullRequests(pullRequestNode);

const targetBranchesFromLabels = pullRequestNode
? getTargetBranchesFromLabels({
Expand Down
5 changes: 2 additions & 3 deletions src/services/github/v4/fetchCommitsByAuthor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ export async function fetchCommitsByAuthor(
sha,
});

const existingTargetPullRequests = getExistingTargetPullRequests(
pullRequestNode
);
const existingTargetPullRequests =
getExistingTargetPullRequests(pullRequestNode);

const targetBranchesFromLabels = getTargetBranchesFromLabels({
sourceBranch: pullRequestNode.baseRefName,
Expand Down
5 changes: 2 additions & 3 deletions src/services/github/v4/fetchMergedPullRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ export async function fetchMergedPullRequests(
const pullRequestNode =
commitEdge.node.associatedPullRequests.edges[0].node;

const existingTargetPullRequests = getExistingTargetPullRequests(
pullRequestNode
);
const existingTargetPullRequests =
getExistingTargetPullRequests(pullRequestNode);

const expectedTargetBranches = getTargetBranchesFromLabels({
sourceBranch: pullRequestNode.baseRefName,
Expand Down
5 changes: 2 additions & 3 deletions src/services/github/v4/fetchPullRequestBySearchQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ export async function fetchPullRequestBySearchQuery(
pullNumber,
});

const existingTargetPullRequests = getExistingTargetPullRequests(
pullRequestNode
);
const existingTargetPullRequests =
getExistingTargetPullRequests(pullRequestNode);

const targetBranchesFromLabels = getTargetBranchesFromLabels({
sourceBranch: pullRequestNode.baseRefName,
Expand Down
Loading

0 comments on commit ede4124

Please sign in to comment.