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

Misc #52

Merged
merged 3 commits into from Jun 16, 2021
Merged

Misc #52

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}
}
13 changes: 13 additions & 0 deletions .github/workflows/PR-CI.yml
@@ -0,0 +1,13 @@
name: Continuous integration

on: pull_request

jobs:
test:
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
6 changes: 5 additions & 1 deletion .github/workflows/CI.yml → .github/workflows/master-CI.yml
@@ -1,12 +1,16 @@
name: Continuous integration

on: pull_request
on:
push:
branches:
- master

jobs:
test:
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: 6 additions & 5 deletions CHANGELOG.md
Expand Up @@ -5,22 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.1.0] - 2021-06-16

### 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.
- 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;
}