Skip to content

Commit

Permalink
Migrate GitHub Actions from v1 to v2 (#4)
Browse files Browse the repository at this point in the history
* Migrate GitHub Actions from v1 to v2

* Add a workflow for build, lint and test

* Fix comment format to see a referenced issue

* Change the format of branch-prefix

* Update document on how to use the action
  • Loading branch information
kentaro-m authored Mar 22, 2020
1 parent eb69bba commit 9c1782c
Show file tree
Hide file tree
Showing 23 changed files with 31,523 additions and 2,913 deletions.
23 changes: 0 additions & 23 deletions .circleci/config.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dist/
lib/
node_modules/
entrypoint.js
index.js
56 changes: 56 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"plugins": ["jest", "@typescript-eslint"],
"extends": ["plugin:github/es6"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.json"
},
"rules": {
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
}
}
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Test
on:
push

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: npm install, build, lint and test
run: |
npm install
npm run all
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
coverage
coverage
lib/
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
lib/
node_modules/
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
# add-an-issue-reference-action
# Add an issue reference
A GitHub Action for adding a related issue reference to a pull request.

## :arrow_forward: Usage
A workflow adds a comment included a link for a related issue based on the branch name to a pull request when a pull request is opened.
A workflow adds a comment contained a link for a related issue based on the branch name to a pull request when a pull request is opened.

![](./add-an-issue-reference.png)
![Adds a comment contained a link for a related issue](usage.png)

Add `.github/main.workflow` with the following:
### Create a workflow

```hcl
workflow "Add an issue reference to a pull request" {
on = "pull_request"
resolves = "Add an issue reference"
}
Add `.github/workflows/issue-reference.yml` with the following:

action "Add an issue reference" {
uses = "kentaro-m/add-an-issue-reference-action@master"
secrets = ["GITHUB_TOKEN"]
# branch name prefix
args = "{\"branch\":\"issue\"}"
}
```yml
name: 'Issue Reference'
on:
pull_request:
types: [opened]

jobs:
issue-reference:
runs-on: ubuntu-latest
steps:
- uses: kentaro-m/[email protected]
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
branch-prefix: "TICKET-"
```
When you use this action, create a branch based on the pattern of the branch name (`[branch name prefix]-[issue number]`) set up on `main.workflow`. For example, if `args` is `"{\"branch\":\"issue\"}"`, create a branch like `issue-8`.
### Set up required parameters
Need to contain the required parameters on the workflow file.
- `repo-token` A token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`
- `branch-prefix` A prefix of the branch name for finding a related issue (e.g `TICKET-`).

### Add a comment contained a link for a related issue
Create a branch based on the pattern of the branch name (`[branch prefix][issue number]`) set up on `.github/workflows/issue-reference.yml`.

For example, if `branch-prefix` is `TICKET-`, create a branch like `TICKET-8`.

When pushing your changes to the repository and creating a pull request, a workflow runs automatically.

## :memo: Licence
MIT
21 changes: 21 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {getIssueNumber} from '../src/utils'

describe('getIssueNumber', () => {
it('Gets the issue number based on branch name', () => {
const branchName = 'issue-29'
const pattern = /issue-([0-9]+)/

const issueNumber = getIssueNumber(branchName, pattern)

expect(issueNumber).toBe(29)
})

it('Gets number 0 if the branch name is a pattern not match', () => {
const branchName = 'patch1'
const pattern = /issue-([0-9]+)/

const issueNumber = getIssueNumber(branchName, pattern)

expect(issueNumber).toBe(0)
})
})
16 changes: 16 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: 'Add an issue reference'
description: 'A GitHub Action for adding a related issue reference to a pull request.'
author: 'kentaro-m'
inputs:
branch-prefix:
description: 'The prefix of branch name.'
required: true
repo-token:
description: 'Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
required: true
runs:
using: 'node12'
main: 'dist/index.js'
branding:
icon: 'image'
color: 'gray-dark'
Binary file removed add-an-issue-reference.png
Binary file not shown.
Loading

0 comments on commit 9c1782c

Please sign in to comment.