-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from delivered/MM-first-pr
test
- Loading branch information
Showing
3 changed files
with
51 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |