Initial commit 🌎
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
.DS_Store
|
||||
node_modules/
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 GitHub Actions
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,48 @@
|
||||
# Pull Request Title Checker
|
||||
|
||||
This action checks if PR titles conform to the Contribution Guidelines :ballot_box_with_check: <br/><br/>
|
||||
Consistent title names help maintainers organise their projects better :books: <br/><br/>
|
||||
Shows if the author has _reaaaaally_ read the Contribution Guidelines :wink:
|
||||
|
||||
## Usage
|
||||
|
||||
Create a `.github/pr-title-styles.json` like this one below:
|
||||
|
||||
```json
|
||||
{
|
||||
"LABEL": {
|
||||
"name": "title needs formatting",
|
||||
"color": "EEEEEE"
|
||||
},
|
||||
"CHECKS": {
|
||||
"prefixes": ["fix: ", "feat: "],
|
||||
"regexp": "docs\\(v[0-9]\\): "
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If none of the checks pass, a label will be added to that pull request. \
|
||||
If at least one of them passes, the label will be removed.
|
||||
|
||||
## Create Workflow
|
||||
|
||||
Create a workflow (eg: `.github/workflows/pr-title-cheker.yml` see [Creating a Workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file)) to utilize the pr-title-checker action with content:
|
||||
|
||||
```
|
||||
name: "PR Title Checker"
|
||||
on:
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- edited
|
||||
- synchronize
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/[email protected]
|
||||
- uses: thehanimo/[email protected]
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
```
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
name: "PR Title Checker"
|
||||
description: "Checks if the PR Title follows contribution guidelines."
|
||||
branding:
|
||||
icon: 'tag'
|
||||
color: 'purple'
|
||||
on: [pull_request]
|
||||
inputs:
|
||||
GITHUB_TOKEN:
|
||||
required: true
|
||||
configuration-path:
|
||||
description: "The path for the label configurations"
|
||||
default: ".github/pr-title-styles.json"
|
||||
runs:
|
||||
using: "node12"
|
||||
main: "dist/index.js"
|
||||
Vendored
+6144
File diff suppressed because it is too large
Load Diff
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+3912
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,95 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as github from "@actions/github";
|
||||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
|
||||
const issue_number = process.env.GITHUB_REF.split("/")[2];
|
||||
const configPath = core.getInput("configuration-path");
|
||||
const { Octokit } = require("@octokit/action");
|
||||
|
||||
const octokit = new Octokit();
|
||||
|
||||
// most @actions toolkit packages have async methods
|
||||
async function run() {
|
||||
try {
|
||||
const title = github.context.payload.pull_request.title;
|
||||
|
||||
let a = await getJSON(configPath);
|
||||
let { CHECKS, LABEL } = JSON.parse(a);
|
||||
LABEL.name = LABEL.name || "title needs formatting";
|
||||
LABEL.color = LABEL.color || "eee";
|
||||
|
||||
try {
|
||||
let createResponse = await octokit.issues.createLabel({
|
||||
owner,
|
||||
repo,
|
||||
name: LABEL.name,
|
||||
color: LABEL.color,
|
||||
});
|
||||
core.info(`Creating label (${LABEL.name}) - ` + createResponse.status);
|
||||
} catch (error) {
|
||||
core.info(`Label (${LABEL.name}) exists.`);
|
||||
}
|
||||
if (CHECKS.prefixes && CHECKS.prefixes.length) {
|
||||
for (let i = 0; i < CHECKS.prefixes.length; i++) {
|
||||
if (title.startsWith(CHECKS.prefixes[i])) {
|
||||
removeLabel(LABEL.name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (CHECKS.regexp) {
|
||||
let re = new RegExp(CHECKS.regexp);
|
||||
if (re.test(title)) {
|
||||
removeLabel(LABEL.name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
addLabel(LABEL.name);
|
||||
} catch (error) {
|
||||
core.info(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function addLabel(name) {
|
||||
try {
|
||||
let addLabelResponse = await octokit.issues.addLabels({
|
||||
owner,
|
||||
repo,
|
||||
issue_number,
|
||||
labels: [name],
|
||||
});
|
||||
core.info(`Adding label (${name}) - ` + addLabelResponse.status);
|
||||
} catch (error) {
|
||||
core.info("All OK");
|
||||
}
|
||||
}
|
||||
|
||||
async function removeLabel(name) {
|
||||
try {
|
||||
let removeLabelResponse = await octokit.issues.removeLabel({
|
||||
owner,
|
||||
repo,
|
||||
issue_number,
|
||||
name: name,
|
||||
});
|
||||
core.info(
|
||||
"No mismatches found. Deleting label - " + removeLabelResponse.status
|
||||
);
|
||||
} catch (error) {
|
||||
core.info("All OK");
|
||||
}
|
||||
}
|
||||
|
||||
async function getJSON(repoPath) {
|
||||
const response = await octokit.repos.getContent({
|
||||
owner,
|
||||
repo,
|
||||
path: repoPath,
|
||||
ref: github.context.sha,
|
||||
});
|
||||
|
||||
return Buffer.from(response.data.content, response.data.encoding).toString();
|
||||
}
|
||||
|
||||
run();
|
||||
Generated
+5447
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "javascript-action",
|
||||
"version": "1.0.0",
|
||||
"description": "JavaScript Action Template",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"prepare": "ncc build index.js -o dist --source-map",
|
||||
"test": "jest",
|
||||
"all": "npm run lint && npm run prepare && npm run test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/actions/javascript-action.git"
|
||||
},
|
||||
"keywords": [
|
||||
"GitHub",
|
||||
"Actions",
|
||||
"JavaScript"
|
||||
],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/actions/javascript-action/issues"
|
||||
},
|
||||
"homepage": "https://github.com/actions/javascript-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.1.1",
|
||||
"@actions/github": "^4.0.0",
|
||||
"@octokit/action": "^3.0.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@zeit/ncc": "^0.22.3",
|
||||
"eslint": "^7.4.0",
|
||||
"jest": "^26.1.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user