Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
d379c1c
feat(PRK-16): added commented github action code
Sheraz064-ai Dec 30, 2022
655eb24
feat(PRK-16): added github action code
Sheraz064-ai Dec 30, 2022
218ae6e
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
ef22141
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
749326c
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
8d8c075
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
46ad225
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
960c151
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
512771a
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
031f6b5
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
3dc3a6d
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
6e8c65e
feat(PRK-16): commented code to check the error
Sheraz064-ai Jan 2, 2023
9434e6d
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
4d56cc3
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
4fcebad
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
e1710d9
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
d105690
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
ff6a983
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
1e98a55
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
9f010f0
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
ce7df3f
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
6d8baff
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
c308231
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
e769ea7
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
bb22843
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
373b697
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
b17c3e8
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
243b169
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
0d03db7
feat(PRK-16): called the running function to handle async function
Sheraz064-ai Jan 2, 2023
bb89bb0
feat(PRK-16): testing token input
Sheraz064-ai Jan 2, 2023
2abf518
feat(PRK-16): testing token input
Sheraz064-ai Jan 2, 2023
91c7725
feat(PRK-16): add functionality to add label to issue
Sheraz064-ai Jan 2, 2023
ef1ea87
feat(PRK-16): added reusable methods
Sheraz064-ai Jan 2, 2023
01b7889
feat(PRK-16): added method to remove ready for review label if the pr…
Sheraz064-ai Jan 2, 2023
8ce6747
feat(PRK-16): refactor some code
Sheraz064-ai Jan 2, 2023
260f2dc
feat(PRK-16): logged pr description
Sheraz064-ai Jan 3, 2023
ea0fd36
feat(PRK-16): added regex to lint pr description
Sheraz064-ai Jan 3, 2023
b4ee722
feat(PRK-16): refactored some code
Sheraz064-ai Jan 3, 2023
9aaa2e2
feat(PRK-16): updated regex for pr description
Sheraz064-ai Jan 3, 2023
b3071cf
feat(PRK-16): checking pr issue
Sheraz064-ai Jan 3, 2023
5988f75
feat(PRK-16): removed log
Sheraz064-ai Jan 3, 2023
c50137f
feat(PRK-16): added README file
Sheraz064-ai Jan 15, 2023
1b8953d
feat(PRK-16): fixed a regex in the README file
Sheraz064-ai Jan 15, 2023
bc675f5
feat(PRK-16): fixed a regex in the README file
Sheraz064-ai Jan 15, 2023
faab87c
feat(PRK-16): fixed test.yml
Sheraz064-ai Jan 15, 2023
2263535
feat(PRK-16): updated test.yml
Sheraz064-ai Jan 15, 2023
6277fb6
feat(PRK-16): add description log
Sheraz064-ai Jan 15, 2023
161e636
feat(PRK-16): rebuild the action
Sheraz064-ai Jan 15, 2023
b90049f
feat(PRK-16): rebuild the action
Sheraz064-ai Jan 15, 2023
e16ca74
feat(PRK-16): updated package
Sheraz064-ai Jan 15, 2023
8f152ed
feat(PRK-16): testing table
Sheraz064-ai Jan 15, 2023
1c41cab
feat(PRK-16): updated the README
Sheraz064-ai Jan 15, 2023
9c0c983
feat(PRK-16): updated the README
Sheraz064-ai Jan 15, 2023
a5899af
feat(PRK-16): updated the checkout version to 3 in test.yml
Sheraz064-ai Jan 16, 2023
28aacb5
chore(PRK-16): updated babel core version
Sheraz064-ai Jan 16, 2023
0511ce9
chore(PRK-16): updated tsconfig
Sheraz064-ai Jan 16, 2023
0e55ba5
chore(PRK-16): removed @babel/core package
Sheraz064-ai Jan 16, 2023
098bf46
chore(PRK-16): removed node modules folder
Sheraz064-ai Jan 16, 2023
20c9553
feat(PRK-16): updated gitignore file
Sheraz064-ai Jan 16, 2023
5a24c28
feat(PRK-16): updated tsconfig
Sheraz064-ai Jan 16, 2023
4c28854
feat(PRK-16): updated README
Sheraz064-ai Jan 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: 'build-test'
on: # rebuild any PRs and main branch changes
pull_request:
types: [opened, edited, synchronize, reopened]
push:
branches:
- main
Expand All @@ -10,15 +11,15 @@ jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: |
npm install
- run: |
npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./
with:
milliseconds: 1000
token: ${{ secrets.GITHUB_TOKEN }}
202 changes: 133 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,169 @@
<h1 align="center">PR Keeper</h1>

<!-- PROJECT SHIELDS -->
<p align="center">
<!-- <a href="package_link_here">
<img src="https://img.shields.io/badge/node-18.x.x-brightgreen.svg" alt="version" />
</a>
&nbsp; -->
<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>
<!-- &nbsp;
<a href="package_link_here">
<img src="https://img.shields.io/npm/dm/prompts.svg" alt="downloads" />
</a> -->
</p>

# Create a JavaScript Action using TypeScript
<p align="center">
A GitHub action to validate Pull Request's title and description consistent convention
</p>

Use this template to bootstrap the creation of a TypeScript action.:rocket:
<br />

This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance.
- **Pull Request Title**: Validate Pull Request's title convention against the regular expression.
- **Pull Request Description**: Validate Pull Request's description convention against the regular expression.
- **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.
- **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.

If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
##### Valid Pull Request

## Create an action from this template
<img src="./assets/images/check-list-passed.png" />

Click the `Use this Template` and provide the new repo details for your action
##### Invalid Pull Request

## Code in Main
<img src="./assets/images/check-list-failed.png" />

> First, you'll need to have a reasonably modern version of `node` handy. This won't work with versions older than 9, for instance.
![split](https://github.com/terkelg/prompts/raw/master/media/split.png)

Install the dependencies
```bash
$ npm install
```
## Usage

Build the typescript and package it for distribution
```bash
$ npm run build && npm run package
```
Create a `.github/workflows/${YOUR_WORKFLOW_NAME}.yml` file in your GitHub repo and add the following code.

Run the tests :heavy_check_mark:
```bash
$ npm test

PASS ./index.test.js
✓ throws invalid number (3ms)
✓ wait 500 ms (504ms)
✓ test runs (95ms)

...
```
on:
pull_request:
types: [opened, edited, synchronize, reopened]

jobs:
validate_pr:
runs-on: ubuntu-latest
name: Validate Pull Request
steps:
- name: validate PR
id: validatePR
uses: Techwards/pr-keeper@1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
```

## Change action.yml

The action.yml defines the inputs and output for your action.

Update the action.yml with your name, description, inputs and outputs for your action.

See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
This GitHub action uses default regular expression for title and description convention validation and default label name if the pull request is valid.

## Change the Code
**Custom Action Values:** Users can also add their custom regular expression and custom label name. Follow the examples section.

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
![split](https://github.com/terkelg/prompts/raw/master/media/split.png)

```javascript
import * as core from '@actions/core';
...
## Examples

async function run() {
try {
...
}
catch (error) {
core.setFailed(error.message);
}
}
**Example 1:** Using custom title regular expression and default description regular expression and default label name

run()
```
on:
pull_request:
types: [opened, edited, synchronize, reopened]

jobs:
validate_pr:
runs-on: ubuntu-latest
name: Validate Pull Request
steps:
- name: validate PR
id: validatePR
uses: Techwards/pr-keeper@1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
title-regex: >
^Ticket\s\#[1-9]{1,}$
```

See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
**Example 2:** Using custom description and default title regular expression and default label name

## Publish to a distribution branch
```
on:
pull_request:
types: [opened, edited, synchronize, reopened]

jobs:
validate_pr:
runs-on: ubuntu-latest
name: Validate Pull Request
steps:
- name: validate PR
id: validatePR
uses: Techwards/pr-keeper@1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
description-regex: >
This\sPull Request\s(closes|fixes)\s\[\#[0-9]{1,}\]
```

Actions are run from GitHub repos so we will checkin the packed dist folder.
**Example 3:** Using default title and description regular expression and custom label name

Then run [ncc](https://github.com/zeit/ncc) and push the results:
```bash
$ npm run package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
```
on:
pull_request:
types: [opened, edited, synchronize, reopened]

jobs:
validate_pr:
runs-on: ubuntu-latest
name: Validate Pull Request
steps:
- name: validate PR
id: validatePR
uses: Techwards/pr-keeper@1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
validation-label: Valid Pull Request Convention
```

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.
**Example 4:** Using custom title and description regular expression and custom label name

Your action is now published! :rocket:
```
on:
pull_request:
types: [opened, edited, synchronize, reopened]

jobs:
validate_pr:
runs-on: ubuntu-latest
name: Validate Pull Request
steps:
- name: validate PR
id: validatePR
uses: Techwards/pr-keeper@1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
title-regex: >
^Ticket\s\#[1-9]{1,}$
description-regex: >
This\sPull Request\s(closes|fixes)\s\[\#[0-9]{1,}\]
validation-label: Valid Pull Request Convention
```

See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
![split](https://github.com/terkelg/prompts/raw/master/media/split.png)

## Validate
## Inputs table

You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))
| Name | Required | Default | Description |
| ---- | -------- | ------- | ----------- |
| `token` | `true` | `none` | A GitHub authentication token |
| `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 |
| `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 |
| `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 |

```yaml
uses: ./
with:
milliseconds: 1000
```
## Credits

See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket:
[TypeScript GitHub Action Template](https://github.com/actions/typescript-action) by [GitHub Actions](https://github.com/actions).

## Usage:
## License

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
Distributed under the MIT License. See `LICENSE` for more information.
29 changes: 3 additions & 26 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
import {wait} from '../src/wait'
import * as process from 'process'
import * as cp from 'child_process'
import * as path from 'path'
import {expect, test} from '@jest/globals'

test('throws invalid number', async () => {
const input = parseInt('foo', 10)
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
})

test('wait 500 ms', async () => {
const start = new Date()
await wait(500)
const end = new Date()
var delta = Math.abs(end.getTime() - start.getTime())
expect(delta).toBeGreaterThan(450)
})

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['INPUT_MILLISECONDS'] = '500'
const np = process.execPath
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecFileSyncOptions = {
env: process.env
}
console.log(cp.execFileSync(np, [ip], options).toString())
test('dummy test', () => {
const input = true
expect(input).toBe(true)
})
22 changes: 16 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
name: 'Your name here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: 'PR Keeper'
description: 'A GitHub action that will validate the pull request'
on: [pull_request]
inputs:
milliseconds: # change this
token:
description: 'GitHub secret'
required: true
description: 'input description here'
default: 'default value if applicable'
title-regex:
description: 'Regex for pull request title validation'
default: >
^(Feature|Fix|Task)\s\|\sIssue\s\#[1-9]{1,}\s\|\s[\w\s\']*$
description-regex:
description: 'Regex for pull request description validation'
default: >
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()@:%_\+.~\#\?\&\/\=]*)\)
validation-label:
description: 'Label to add when the pull request format is valid'
default: Ready for Review
runs:
using: 'node16'
main: 'dist/index.js'
Binary file added assets/images/check-list-failed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/check-list-passed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading