|
| 1 | +<h1 align="center">PR Keeper</h1> |
| 2 | + |
| 3 | +<!-- PROJECT SHIELDS --> |
1 | 4 | <p align="center"> |
| 5 | + <!-- <a href="package_link_here"> |
| 6 | + <img src="https://img.shields.io/badge/node-18.x.x-brightgreen.svg" alt="version" /> |
| 7 | + </a> |
| 8 | + --> |
2 | 9 | <a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a> |
| 10 | + <!-- |
| 11 | + <a href="package_link_here"> |
| 12 | + <img src="https://img.shields.io/npm/dm/prompts.svg" alt="downloads" /> |
| 13 | + </a> --> |
3 | 14 | </p> |
4 | 15 |
|
5 | | -# Create a JavaScript Action using TypeScript |
| 16 | +<p align="center"> |
| 17 | + A GitHub action to validate Pull Request's title and description consistent convention |
| 18 | +</p> |
6 | 19 |
|
7 | | -Use this template to bootstrap the creation of a TypeScript action.:rocket: |
| 20 | +<br /> |
8 | 21 |
|
9 | | -This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance. |
| 22 | +- **Pull Request Title**: Validate Pull Request's title convention against the regular expression. |
| 23 | +- **Pull Request Description**: Validate Pull Request's description convention against the regular expression. |
| 24 | +- **Valid Pull Request Label**: If the Pull Request's title and description convention is valid then a label will be attached on the Pull Request. |
| 25 | +- **Custom Regular Expression & Label name**: User can add custom regex to validate the Pull Request's title and description and can also add custom label name for valid Pull Request status. |
10 | 26 |
|
11 | | -If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action) |
| 27 | +##### Valid Pull Request |
12 | 28 |
|
13 | | -## Create an action from this template |
| 29 | +<img src="./assets/images/check-list-passed.png" /> |
14 | 30 |
|
15 | | -Click the `Use this Template` and provide the new repo details for your action |
| 31 | +##### Invalid Pull Request |
16 | 32 |
|
17 | | -## Code in Main |
| 33 | +<img src="./assets/images/check-list-failed.png" /> |
18 | 34 |
|
19 | | -> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance. |
| 35 | + |
20 | 36 |
|
21 | | -Install the dependencies |
22 | | -```bash |
23 | | -$ npm install |
24 | | -``` |
| 37 | +## Usage |
25 | 38 |
|
26 | | -Build the typescript and package it for distribution |
27 | | -```bash |
28 | | -$ npm run build && npm run package |
29 | | -``` |
| 39 | +Create a `.github/workflows/${YOUR_WORKFLOW_NAME}.yml` file in your GitHub repo and add the following code. |
30 | 40 |
|
31 | | -Run the tests :heavy_check_mark: |
32 | | -```bash |
33 | | -$ npm test |
34 | | - |
35 | | - PASS ./index.test.js |
36 | | - ✓ throws invalid number (3ms) |
37 | | - ✓ wait 500 ms (504ms) |
38 | | - ✓ test runs (95ms) |
39 | | - |
40 | | -... |
| 41 | +``` |
| 42 | +on: |
| 43 | + pull_request: |
| 44 | + types: [opened, edited, synchronize, reopened] |
| 45 | +
|
| 46 | +jobs: |
| 47 | + validate_pr: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + name: Validate Pull Request |
| 50 | + steps: |
| 51 | + - name: validate PR |
| 52 | + id: validatePR |
| 53 | + uses: Techwards/pr-keeper@1.0 |
| 54 | + with: |
| 55 | + token: ${{ secrets.GITHUB_TOKEN }} |
41 | 56 | ``` |
42 | 57 |
|
43 | | -## Change action.yml |
44 | | - |
45 | | -The action.yml defines the inputs and output for your action. |
46 | | - |
47 | | -Update the action.yml with your name, description, inputs and outputs for your action. |
48 | | - |
49 | | -See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions) |
| 58 | +This GitHub action uses default regular expression for title and description convention validation and default label name if the pull request is valid. |
50 | 59 |
|
51 | | -## Change the Code |
| 60 | +**Custom Action Values:** Users can also add their custom regular expression and custom label name. Follow the examples section. |
52 | 61 |
|
53 | | -Most toolkit and CI/CD operations involve async operations so the action is run in an async function. |
| 62 | + |
54 | 63 |
|
55 | | -```javascript |
56 | | -import * as core from '@actions/core'; |
57 | | -... |
| 64 | +## Examples |
58 | 65 |
|
59 | | -async function run() { |
60 | | - try { |
61 | | - ... |
62 | | - } |
63 | | - catch (error) { |
64 | | - core.setFailed(error.message); |
65 | | - } |
66 | | -} |
| 66 | +**Example 1:** Using custom title regular expression and default description regular expression and default label name |
67 | 67 |
|
68 | | -run() |
| 68 | +``` |
| 69 | +on: |
| 70 | + pull_request: |
| 71 | + types: [opened, edited, synchronize, reopened] |
| 72 | +
|
| 73 | +jobs: |
| 74 | + validate_pr: |
| 75 | + runs-on: ubuntu-latest |
| 76 | + name: Validate Pull Request |
| 77 | + steps: |
| 78 | + - name: validate PR |
| 79 | + id: validatePR |
| 80 | + uses: Techwards/pr-keeper@1.0 |
| 81 | + with: |
| 82 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + title-regex: > |
| 84 | + ^Ticket\s\#[1-9]{1,}$ |
69 | 85 | ``` |
70 | 86 |
|
71 | | -See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages. |
| 87 | +**Example 2:** Using custom description and default title regular expression and default label name |
72 | 88 |
|
73 | | -## Publish to a distribution branch |
| 89 | +``` |
| 90 | +on: |
| 91 | + pull_request: |
| 92 | + types: [opened, edited, synchronize, reopened] |
| 93 | +
|
| 94 | +jobs: |
| 95 | + validate_pr: |
| 96 | + runs-on: ubuntu-latest |
| 97 | + name: Validate Pull Request |
| 98 | + steps: |
| 99 | + - name: validate PR |
| 100 | + id: validatePR |
| 101 | + uses: Techwards/pr-keeper@1.0 |
| 102 | + with: |
| 103 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + description-regex: > |
| 105 | + This\sPull Request\s(closes|fixes)\s\[\#[0-9]{1,}\] |
| 106 | +``` |
74 | 107 |
|
75 | | -Actions are run from GitHub repos so we will checkin the packed dist folder. |
| 108 | +**Example 3:** Using default title and description regular expression and custom label name |
76 | 109 |
|
77 | | -Then run [ncc](https://github.com/zeit/ncc) and push the results: |
78 | | -```bash |
79 | | -$ npm run package |
80 | | -$ git add dist |
81 | | -$ git commit -a -m "prod dependencies" |
82 | | -$ git push origin releases/v1 |
| 110 | +``` |
| 111 | +on: |
| 112 | + pull_request: |
| 113 | + types: [opened, edited, synchronize, reopened] |
| 114 | +
|
| 115 | +jobs: |
| 116 | + validate_pr: |
| 117 | + runs-on: ubuntu-latest |
| 118 | + name: Validate Pull Request |
| 119 | + steps: |
| 120 | + - name: validate PR |
| 121 | + id: validatePR |
| 122 | + uses: Techwards/pr-keeper@1.0 |
| 123 | + with: |
| 124 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 125 | + validation-label: Valid Pull Request Convention |
83 | 126 | ``` |
84 | 127 |
|
85 | | -Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project. |
| 128 | +**Example 4:** Using custom title and description regular expression and custom label name |
86 | 129 |
|
87 | | -Your action is now published! :rocket: |
| 130 | +``` |
| 131 | +on: |
| 132 | + pull_request: |
| 133 | + types: [opened, edited, synchronize, reopened] |
| 134 | +
|
| 135 | +jobs: |
| 136 | + validate_pr: |
| 137 | + runs-on: ubuntu-latest |
| 138 | + name: Validate Pull Request |
| 139 | + steps: |
| 140 | + - name: validate PR |
| 141 | + id: validatePR |
| 142 | + uses: Techwards/pr-keeper@1.0 |
| 143 | + with: |
| 144 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + title-regex: > |
| 146 | + ^Ticket\s\#[1-9]{1,}$ |
| 147 | + description-regex: > |
| 148 | + This\sPull Request\s(closes|fixes)\s\[\#[0-9]{1,}\] |
| 149 | + validation-label: Valid Pull Request Convention |
| 150 | +``` |
88 | 151 |
|
89 | | -See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) |
| 152 | + |
90 | 153 |
|
91 | | -## Validate |
| 154 | +## Inputs table |
92 | 155 |
|
93 | | -You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml)) |
| 156 | +| Name | Required | Default | Description | |
| 157 | +| ---- | -------- | ------- | ----------- | |
| 158 | +| `token` | `true` | `none` | A GitHub authentication token | |
| 159 | +| `title-regex` | `false` | ```^(Feature\|Fix\|Task)\s\|\sIssue\s\#[1-9]{1,}\s\|\s[\w\s\']\*$``` | A regular expression to validate the PR's title convention. Can also provide custom regular expression | |
| 160 | +| `description-regex` | `false` | ```This\sPR\scloses\s\[\#[0-9]{1,}\]\((https?:\/\/)?(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~\#\?\&\/\=]*)\)``` | A regular expression to validate the PR's description convention. Can also provide custom regular expression | |
| 161 | +| `validation-label` | `false` | Ready for Review | A label will be attached on the PR if the PR is valid. Can also provide custom label name | |
94 | 162 |
|
95 | | -```yaml |
96 | | -uses: ./ |
97 | | -with: |
98 | | - milliseconds: 1000 |
99 | | -``` |
| 163 | +## Credits |
100 | 164 |
|
101 | | -See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket: |
| 165 | +[TypeScript GitHub Action Template](https://github.com/actions/typescript-action) by [GitHub Actions](https://github.com/actions). |
102 | 166 |
|
103 | | -## Usage: |
| 167 | +## License |
104 | 168 |
|
105 | | -After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action |
| 169 | +Distributed under the MIT License. See `LICENSE` for more information. |
0 commit comments