Skip to content

Commit

Permalink
feat: test title regex
Browse files Browse the repository at this point in the history
  • Loading branch information
MorrisonCole committed Nov 26, 2019
1 parent de28dfc commit 6f6cbdb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
13 changes: 9 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ branding:
icon: 'check'
color: 'green'
inputs:
myInput:
description: 'Input to use'
default: 'world'
title-regex:
description: 'Regex to ensure PR title matches. Allows anything by default.'
required: true
default: '.*'
on-failed-regex-comment:
description: 'Comment for the bot to post on PRs that fail the regex. Use %regex% to reference regex.'
required: true
default: 'PR title failed to match %regex%.'
runs:
using: 'docker'
image: 'Dockerfile'
image: 'Dockerfile'
28 changes: 23 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
import {GitHub} from '@actions/github/lib/github';

const core = require('@actions/core');
const github = require('@actions/github');

async function run() {
const githubContext = github.context;
const githubToken = core.getInput('github-token');
const githubClient: GitHub = new GitHub(githubToken);

const titleRegex = new RegExp(core.getInput('title-regex'));
const title = githubContext.payload.pull_request.title;

const onFailedRegexComment = core.getInput('on-failed-regex-comment')
.replace('%pattern%', titleRegex.source);

try {
const myInput = core.getInput('myInput');
core.debug(`Hello ${myInput} from inside a container`);
if (!titleRegex.test(title)) {
const pr = githubContext.issue;

// Get github context data
const context = github.context;
console.log(`We can even get context data, like the repo: ${context.repo.repo}`)
githubClient.pulls.createReview({
owner: pr.owner,
repo: pr.repo,
pull_number: pr.number,
body: onFailedRegexComment,
event: 'COMMENT'
});
}
} catch (error) {
core.setFailed(error.message);
}
}

// noinspection JSIgnoredPromiseFromCall
run();

0 comments on commit 6f6cbdb

Please sign in to comment.