Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Sep 8, 2020
0 parents commit 0230f30
Show file tree
Hide file tree
Showing 365 changed files with 87,695 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Pull Request

on:
pull_request:
types: [created]

jobs:
auto-approve:
name: Label PRs
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: PR Labeler
uses: ./
with:
token: "${{ secrets.GITHUB_TOKEN }}"
fix: 'Fix'
feature: 'Feature'
pref: 'Performance Improvement'
preformance: 'Performance Improvement'
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: 'PR Labels'
description: 'Automatically label PRs based on the branch prefix'
inputs:
token:
description: 'GitHub Token for the user to perform label additions. Use `secrets.GITHUB_TOKEN` for the actions bot'
required: true
runs:
using: 'node12'
main: 'index.js'
64 changes: 64 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const core = require('@actions/core'),
github = require('@actions/github');

async function run() {
try {
const token = core.getInput('token');
const labels = Object.keys(process.env).filter(e => e !== 'INPUT_TOKEN' && e.startsWith('INPUT_')).map(e => e.replace('INPUT_', '').toLowerCase());
console.log(`Checking for labels: ` + labels.join(', '));

const prNumber = getPrNumber();
if (!prNumber) {
console.log('Could not get pull request number from context, exiting');
return;
}

const client = github.getOctokit(token);

const repo = github.context.payload.repository;

const data = await client.pulls.get({
owner: repo.owner.login,
repo: repo.name,
pull_number: prNumber,
});

const branch = data.data.head.ref;

for (let prefix of labels) {
let tmp = prefix;
if (!prefix.endsWith('/'))
prefix += '/';

console.log(`If ${branch} startsWith ${prefix}`)
if (branch.startsWith(prefix)) {
const label = process.env['INPUT_' + tmp.toUpperCase()];
console.log(`Adding ${label} to #${prNumber}`);
await addLabels(client, prNumber, [label]);
}
}
} catch (error) {
console.error(error);
core.setFailed(error.message);
}
}

async function addLabels(client, prNumber, labels) {
await client.issues.addLabels({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: prNumber,
labels: labels
});
}

function getPrNumber() {
const pullRequest = github.context.payload.pull_request;
if (!pullRequest) {
return undefined;
}

return pullRequest.number;
}

run();
9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

147 changes: 147 additions & 0 deletions node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions node_modules/@actions/core/lib/command.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions node_modules/@actions/core/lib/command.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions node_modules/@actions/core/lib/command.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0230f30

Please sign in to comment.