Skip to content

Commit

Permalink
Merge pull request #1 from delivered/MM-first-pr
Browse files Browse the repository at this point in the history
test
  • Loading branch information
MartyIce authored Jan 18, 2020
2 parents b10b642 + b0a9c57 commit ca081c5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 30 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
on: [pull_request]

on:
issue_comment:
types: [created, edited]
pull_request:
types: [edited, opened, synchronize, reopened]
jobs:
confirm-link:
runs-on: ubuntu-latest
name: This action will look for a link matching a regEx (eg, http://trello.com) in PR.
name: Ensure Trello link present as attachment.
steps:
- name: Confirm Link
id: confirm
uses: delivered/trello-github-action/@7e9cf84
uses: delivered/trello-github-action/@MM-first-pr
with:
link-regex: 'https://trello.com'
- name: Get the output time
run: echo "The time was ${{ steps.confirm.outputs.time }}. Link ${{steps.confirm.outputs.link}}"
link-regex: '(https:\/\/trello.com[^\)]*)'
repo-token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 3 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ description: 'Confirm Trello link included on Pull Request'
inputs:
link-regex:
description: 'URL to use reg ex search for'
default: 'https://trello.com'
default: '(https:\/\/trello.com[^\)]*)'
outputs:
link:
description: 'Link that was found'
found:
description: 'Whether a link was found'
time: # id of output
description: 'The time we greeted you'
msg:
description: 'output of action'
runs:
using: 'node12'
main: 'index.js'
55 changes: 39 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
const core = require('@actions/core');
const github = require('@actions/github');

try {
// `who-to-greet` input defined in action metadata file
const linkRegEx = core.getInput('link-regex');
console.log(`Checking for links: ${linkRegEx}!`);
const time = (new Date()).toTimeString();

core.setOutput("time", time);
core.setOutput("link", linkRegEx);
core.setOutput("time", false);

// Get the JSON webhook payload for the event that triggered the workflow
const payload = JSON.stringify(github.context.payload, undefined, 2)
console.log(`The event payload: ${payload}`);
} catch (error) {
core.setFailed(error.message);
}
async function run() {
try {
// `who-to-greet` input defined in action metadata file
const linkRegExInput = core.getInput('link-regex');
const linkRegExp = new RegExp(linkRegExInput)

console.log(`Checking for links: ${linkRegExInput}!`);

const time = (new Date()).toTimeString();
const token = core.getInput('repo-token');
const octokit = new github.GitHub(token);
const payload = github.context.payload;

const prComments = await octokit.issues.listComments({
owner: payload.organization.login,
repo: payload.repository.name,
issue_number: payload.pull_request.number
});

const commentsWithLinks = prComments.data.filter(d => linkRegExp.exec(d.body) && linkRegExp.exec(d.body).length > 0).map(i => linkRegExp.exec(i.body)[0])

console.log('all prComments:')
console.log(prComments.data.map(i => i.body));

console.log('matches:')
console.log(commentsWithLinks);

core.setOutput('msg', `Found ${commentsWithLinks.length} with matching links`)

if(commentsWithLinks.length === 0)
core.setFailed(`unable to find any comments matching link ${linkRegExInput}`)

} catch (error) {
console.log(error);
core.setFailed(error.message);
}
}

run();

0 comments on commit ca081c5

Please sign in to comment.