Skip to content

Commit

Permalink
Switch from prettier to dprint for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaseizinger committed Jun 16, 2021
1 parent b9c9e2b commit 2a6ef64
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 94 deletions.
28 changes: 14 additions & 14 deletions .eslintrc.json
@@ -1,16 +1,16 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/es6"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/es6"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
1 change: 1 addition & 0 deletions .github/workflows/PR-CI.yml
Expand Up @@ -7,6 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: dprint/check@v1.5
- uses: actions/setup-node@v1
- run: yarn install
- run: yarn test
1 change: 1 addition & 0 deletions .github/workflows/master-CI.yml
Expand Up @@ -10,6 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: dprint/check@v1.5
- uses: actions/setup-node@v1
- run: yarn install
- run: yarn test
Expand Down
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

11 changes: 5 additions & 6 deletions CHANGELOG.md
Expand Up @@ -9,20 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Git hook to make sure we always run `yarn build` before committing any Typescript changes. This should prevent dist/index.js from getting out of date.
- Support for setting a proxy using the `HTTPS_PROXY` environment variable
- Support for GitHub Enterprise by reading `process.env.GITHUB_REPOSITORY`
- Git hook to make sure we always run `yarn build` before committing any Typescript changes. This should prevent dist/index.js from getting out of date.
- Support for setting a proxy using the `HTTPS_PROXY` environment variable
- Support for GitHub Enterprise by reading `process.env.GITHUB_REPOSITORY`

### Fixed

- action.yml suggested to use `github-token` as the input where as in reality, we are looking for an input `github_token` (note the underscore!)
- action.yml suggested to use `github-token` as the input where as in reality, we are looking for an input `github_token` (note the underscore!)

## [1.0.0] - 2020-02-15

### Added

- Initial release!
- Initial release!

[Unreleased]: https://github.com/thomaseizinger/create-pull-request/compare/1.0.0...HEAD

[1.0.0]: https://github.com/thomaseizinger/create-pull-request/compare/92284b92aff90f2100e022ed93d6e485240e8a36...1.0.0
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -29,8 +29,8 @@ To get an idea of all inputs that are supported, have a look at [this file](./sr

For self-hosted runners behind a corporate proxy, set the https_proxy environment variable.

```yaml
- name: Create pull request
```yaml
- name: Create pull request
uses: thomaseizinger/create-pull-request@master
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
56 changes: 28 additions & 28 deletions __tests__/getInputs.test.ts
@@ -1,78 +1,78 @@
import { morph } from "mock-env";
import { getInputs } from "../src/getInputs";
import { morph } from 'mock-env';
import { getInputs } from '../src/getInputs';

const MANDATORY_INPUTS = {
INPUT_HEAD: "refs/heads/feature/test",
INPUT_TITLE: "My test pull request",
GITHUB_REPOSITORY: "foo/bar"
INPUT_HEAD: 'refs/heads/feature/test',
INPUT_TITLE: 'My test pull request',
GITHUB_REPOSITORY: 'foo/bar',
};

it("should default base to master", function() {
it('should default base to master', function() {
const inputs = morph(getInputs, {
...MANDATORY_INPUTS
...MANDATORY_INPUTS,
});

expect(inputs).toHaveProperty("base", "master");
expect(inputs).toHaveProperty('base', 'master');
});

it('should parse "false" for draft as false', function() {
const inputs = morph(getInputs, {
...MANDATORY_INPUTS,
INPUT_DRAFT: "false"
INPUT_DRAFT: 'false',
});

expect(inputs).toHaveProperty("draft", false);
expect(inputs).toHaveProperty('draft', false);
});

it('should parse "true" for draft as true', function() {
const inputs = morph(getInputs, {
...MANDATORY_INPUTS,
INPUT_DRAFT: "true"
INPUT_DRAFT: 'true',
});

expect(inputs).toHaveProperty("draft", true);
expect(inputs).toHaveProperty('draft', true);
});

it("should include body if given", function() {
it('should include body if given', function() {
const inputs = morph(getInputs, {
...MANDATORY_INPUTS,
INPUT_BODY: "Fixes #42"
INPUT_BODY: 'Fixes #42',
});

expect(inputs).toHaveProperty("body", "Fixes #42");
expect(inputs).toHaveProperty('body', 'Fixes #42');
});

it("should parse owner and repo", function() {
it('should parse owner and repo', function() {
const inputs = morph(getInputs, {
...MANDATORY_INPUTS
...MANDATORY_INPUTS,
});

expect(inputs).toHaveProperty("owner", "foo");
expect(inputs).toHaveProperty("repo", "bar");
expect(inputs).toHaveProperty('owner', 'foo');
expect(inputs).toHaveProperty('repo', 'bar');
});

it("should default to empty list of reviewers", function() {
it('should default to empty list of reviewers', function() {
const inputs = morph(getInputs, {
...MANDATORY_INPUTS
...MANDATORY_INPUTS,
});

expect(inputs).toHaveProperty("reviewers", []);
expect(inputs).toHaveProperty('reviewers', []);
});

it("should split reviewers by comma", function() {
it('should split reviewers by comma', function() {
const inputs = morph(getInputs, {
...MANDATORY_INPUTS,
INPUT_REVIEWERS: "thomaseizinger,bonomat"
INPUT_REVIEWERS: 'thomaseizinger,bonomat',
});

expect(inputs).toHaveProperty("reviewers", ["thomaseizinger", "bonomat"]);
expect(inputs).toHaveProperty('reviewers', ['thomaseizinger', 'bonomat']);
});

it("should trim reviewer names", function() {
it('should trim reviewer names', function() {
const inputs = morph(getInputs, {
...MANDATORY_INPUTS,
INPUT_REVIEWERS: "d4nte, bonomat, luckysori"
INPUT_REVIEWERS: 'd4nte, bonomat, luckysori',
});

expect(inputs).toHaveProperty("reviewers", ["d4nte", "bonomat", "luckysori"]);
expect(inputs).toHaveProperty('reviewers', ['d4nte', 'bonomat', 'luckysori']);
});
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions dprint.json
@@ -0,0 +1,23 @@
{
"$schema": "https://dprint.dev/schemas/v0.json",
"incremental": true,
"typescript": {
"quoteStyle": "preferSingle",
"indentWidth": 2
},
"json": {
},
"markdown": {
},
"includes": ["**/*.{ts,tsx,js,jsx,cjs,mjs,json,md}"],
"excludes": [
"**/node_modules",
"**/*-lock.json",
"dist/**"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.46.0.wasm",
"https://plugins.dprint.dev/json-0.12.0.wasm",
"https://plugins.dprint.dev/markdown-0.8.0.wasm"
]
}
6 changes: 3 additions & 3 deletions jest.config.js
Expand Up @@ -5,7 +5,7 @@ module.exports = {
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
'^.+\\.ts$': 'ts-jest',
},
verbose: true
}
verbose: true,
};
3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -8,8 +8,6 @@
"postinstall": "git config core.hooksPath .githooks",
"build": "webpack --mode production",
"compile": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"test": "jest"
},
Expand All @@ -33,7 +31,6 @@
"jest": "^24.9.0",
"jest-circus": "^25.1.0",
"mock-env": "^0.2.0",
"prettier": "^1.19.1",
"ts-jest": "^24.2.0",
"ts-loader": "^6.2.1",
"typescript": "^3.7.3",
Expand Down
33 changes: 17 additions & 16 deletions src/getInputs.ts
@@ -1,29 +1,30 @@
import { getInput } from "@actions/core/lib/core";
import { getInput } from '@actions/core/lib/core';
import {
PullsCreateParams,
PullsCreateReviewRequestParams,
PullsCreateParams
} from "@octokit/plugin-rest-endpoint-methods/dist-types/generated/rest-endpoint-methods-types";
} from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/rest-endpoint-methods-types';

type Inputs = PullsCreateParams &
Required<
Omit<PullsCreateReviewRequestParams, "pull_number" | "team_reviewers">
type Inputs =
& PullsCreateParams
& Required<
Omit<PullsCreateReviewRequestParams, 'pull_number' | 'team_reviewers'>
>;

export function getInputs(): Inputs {
const head = getInput("head", { required: true });
const title = getInput("title", { required: true });
const base = getInput("base") || "master";
const draft = getInput("draft") ? JSON.parse(getInput("draft")) : undefined;
const body = getInput("body") || undefined;
const reviewers = getInput("reviewers");
const head = getInput('head', { required: true });
const title = getInput('title', { required: true });
const base = getInput('base') || 'master';
const draft = getInput('draft') ? JSON.parse(getInput('draft')) : undefined;
const body = getInput('body') || undefined;
const reviewers = getInput('reviewers');

const githubRepository = process.env.GITHUB_REPOSITORY;

if (!githubRepository) {
throw new Error("GITHUB_REPOSITORY is not set");
throw new Error('GITHUB_REPOSITORY is not set');
}

const [owner, repo] = githubRepository.split("/");
const [owner, repo] = githubRepository.split('/');

return {
head,
Expand All @@ -34,7 +35,7 @@ export function getInputs(): Inputs {
owner,
repo,
reviewers: reviewers
? reviewers.split(",").map(reviewer => reviewer.trim())
: []
? reviewers.split(',').map(reviewer => reviewer.trim())
: [],
};
}
18 changes: 9 additions & 9 deletions src/index.ts
@@ -1,8 +1,8 @@
import { setFailed, setOutput } from "@actions/core";
import { Octokit } from "@octokit/action";
import { OctokitOptions } from "@octokit/core/dist-types/types";
import { getInputs } from "./getInputs";
import { HttpsProxyAgent } from "https-proxy-agent";
import { setFailed, setOutput } from '@actions/core';
import { OctokitOptions } from '@octokit/core/dist-types/types';
import { Octokit } from '@octokit/action';
import { HttpsProxyAgent } from 'https-proxy-agent';
import { getInputs } from './getInputs';

async function run(): Promise<void> {
try {
Expand All @@ -14,7 +14,7 @@ async function run(): Promise<void> {
const proxy = process.env.https_proxy || process.env.HTTPS_PROXY;
if (proxy) {
options.request = {
agent: new HttpsProxyAgent(proxy)
agent: new HttpsProxyAgent(proxy),
};
}

Expand All @@ -28,12 +28,12 @@ async function run(): Promise<void> {
owner: pullParams.owner,
repo: pullParams.repo,
pull_number: pullNumber,
reviewers
reviewers,
});
}

setOutput("number", pullNumber.toString());
setOutput("html_url", htmlUrl);
setOutput('number', pullNumber.toString());
setOutput('html_url', htmlUrl);
} catch (error) {
setFailed(error.message);
}
Expand Down
2 changes: 1 addition & 1 deletion types/mock-env/index.d.ts
@@ -1,3 +1,3 @@
declare module "mock-env" {
declare module 'mock-env' {
function morph<T>(callback: () => T, vars: object, toRemove?: string[]): void;
}
14 changes: 7 additions & 7 deletions webpack.config.js
Expand Up @@ -2,7 +2,7 @@ const path = require('path');

module.exports = {
entry: './src/index.ts',
target: "node",
target: 'node',
module: {
rules: [
{
Expand All @@ -11,20 +11,20 @@ module.exports = {
loader: 'ts-loader',
options: {
compilerOptions: {
noEmit: false
}
}
noEmit: false,
},
},
},
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
extensions: ['.tsx', '.ts', '.js'],
// see https://stackoverflow.com/a/59267337/2489334
alias: {
'universal-user-agent': path.resolve(__dirname, 'node_modules/universal-user-agent/dist-node/index.js')
}
'universal-user-agent': path.resolve(__dirname, 'node_modules/universal-user-agent/dist-node/index.js'),
},
},
output: {
filename: 'index.js',
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -5162,7 +5162,7 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"

prettier@>=1.12.0, prettier@^1.19.1:
prettier@>=1.12.0:
version "1.19.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==
Expand Down

0 comments on commit 2a6ef64

Please sign in to comment.