From c852047b4c2a55b86f0041a4d99e37578619d918 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 3 Feb 2020 12:10:21 -0600 Subject: [PATCH 1/7] allow for trello links in pr body this pr body is not a comment - this allows for pasting urls into the pr description (to use other trello action) --- index.js | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 693ae93..518f1d7 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,12 @@ const github = require('@actions/github'); async function run() { try { - // `who-to-greet` input defined in action metadata file const linkRegExInput = core.getInput('link-regex'); const linkRegExp = new RegExp(linkRegExInput) + //matching in pr comments OR body of pr + let matchedStrings = []; + console.log(`Checking for links: ${linkRegExInput}!`); const time = (new Date()).toTimeString(); @@ -14,29 +16,45 @@ async function run() { const octokit = new github.GitHub(token); const payload = github.context.payload; - const prComments = await octokit.issues.listComments({ + const issuesArgs = { 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]) + }; + + const pull = await octokit.issues.get(issuesArgs); + console.log(`pr body: ${pull.body}`); + + const bodyMatches = linkRegExp.exec(pull.body); + if(bodyMatches) matchedStrings.push(bodyMatches[0]); + + if(matchedStrings.length < 1) { + const prComments = await octokit.issues.listComments(issuesArgs); + + const commentsWithLinks = prComments.data.reduce((acc, curr) => { + const matches = linkRegExp.exec(curr.body); + if(matches) acc.push(matches[0]); + return acc; + }, []); + + matchedStrings = matchedStrings.concat(commentsWithLinks); + + console.log('all prComments:') + console.log(prComments.data.map(i => i.body)); + } - console.log('all prComments:') - console.log(prComments.data.map(i => i.body)); console.log('matches:') - console.log(commentsWithLinks); + console.log(matchedStrings); - core.setOutput('msg', `Found ${commentsWithLinks.length} with matching links`) + core.setOutput('msg', `Found ${matchedStrings.length} with matching links`) - if(commentsWithLinks.length === 0) - core.setFailed(`unable to find any comments matching link ${linkRegExInput}`) + if(matchedStrings.length === 0) core.setFailed(`unable to find any comments matching link ${linkRegExInput}`) } catch (error) { console.log(error); core.setFailed(error.message); - } + } } run(); From 25d85ae9ba3f0d75cd6b901a6f6ff638e6a55c44 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 3 Feb 2020 12:15:42 -0600 Subject: [PATCH 2/7] remove unused var, and allow for use in non-team repos --- index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/index.js b/index.js index 518f1d7..04f9aa1 100644 --- a/index.js +++ b/index.js @@ -11,13 +11,12 @@ async function run() { 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 issuesArgs = { - owner: payload.organization.login, + owner: (payload.organization || payload.owner).login, repo: payload.repository.name, issue_number: payload.pull_request.number }; From 62a4604c6914d3354ce6ff52b253a4af516fab3c Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Mon, 3 Feb 2020 17:18:02 -0600 Subject: [PATCH 3/7] fix missing json intermediate bit --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 04f9aa1..331f210 100644 --- a/index.js +++ b/index.js @@ -22,9 +22,9 @@ async function run() { }; const pull = await octokit.issues.get(issuesArgs); - console.log(`pr body: ${pull.body}`); + console.log(`pr body: ${pull.data.body}`); - const bodyMatches = linkRegExp.exec(pull.body); + const bodyMatches = linkRegExp.exec(pull.data.body); if(bodyMatches) matchedStrings.push(bodyMatches[0]); if(matchedStrings.length < 1) { From 3072fb7459532bcfc9787fd212c6e4aa36735a26 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sat, 8 Feb 2020 10:20:12 -0600 Subject: [PATCH 4/7] fix non-org repo owner reference --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 331f210..2b2206d 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ async function run() { const payload = github.context.payload; const issuesArgs = { - owner: (payload.organization || payload.owner).login, + owner: (payload.organization || payload.repository.owner).login, repo: payload.repository.name, issue_number: payload.pull_request.number }; From cefab2c1e43f8c89f2bc50ee7e12fdd2a901eb48 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sat, 8 Feb 2020 10:48:09 -0600 Subject: [PATCH 5/7] fix to handle comment creation events --- index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 2b2206d..a1e4bc6 100644 --- a/index.js +++ b/index.js @@ -15,11 +15,14 @@ async function run() { const octokit = new github.GitHub(token); const payload = github.context.payload; - const issuesArgs = { - owner: (payload.organization || payload.repository.owner).login, - repo: payload.repository.name, - issue_number: payload.pull_request.number - }; + // personal repos have no org + const owner = (payload.organization || payload.repository.owner).login; + const repo = payload.repository.name; + + // issue events (like create comment) supply #issue instead od #pull_request + const issue_number = (payload.pull_request || payload.issue).number; + + const issuesArgs = { owner, repo, issue_number }; const pull = await octokit.issues.get(issuesArgs); console.log(`pr body: ${pull.data.body}`); From 31eb8e0ea0650e7e679ff3feee42b5bdfc762cda Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Sat, 8 Feb 2020 11:13:54 -0600 Subject: [PATCH 6/7] tidy up comments & whitespace --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a1e4bc6..d5d26f1 100644 --- a/index.js +++ b/index.js @@ -15,11 +15,11 @@ async function run() { const octokit = new github.GitHub(token); const payload = github.context.payload; - // personal repos have no org + // personal repos have no org - allow for those as well as team ones const owner = (payload.organization || payload.repository.owner).login; const repo = payload.repository.name; - // issue events (like create comment) supply #issue instead od #pull_request + // issue events (like create comment) supply #issue instead of #pull_request - handle both const issue_number = (payload.pull_request || payload.issue).number; const issuesArgs = { owner, repo, issue_number }; @@ -45,14 +45,12 @@ async function run() { console.log(prComments.data.map(i => i.body)); } - console.log('matches:') console.log(matchedStrings); core.setOutput('msg', `Found ${matchedStrings.length} with matching links`) if(matchedStrings.length === 0) core.setFailed(`unable to find any comments matching link ${linkRegExInput}`) - } catch (error) { console.log(error); core.setFailed(error.message); From 751269a3452592755719b0234dc75b677bd9b1c6 Mon Sep 17 00:00:00 2001 From: Brian Henry Date: Wed, 12 Feb 2020 15:13:10 -0600 Subject: [PATCH 7/7] fix commitish ref in workflow file --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90fd063..9ea4a21 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: steps: - name: Confirm Link id: confirm - uses: delivered/trello-github-action/@MM-first-pr + uses: delivered/trello-github-action/@master with: link-regex: '(https:\/\/trello.com[^\)]*)' - repo-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + repo-token: ${{ secrets.GITHUB_TOKEN }}