From 6610cdb3ab4f1c30d3a1407d0e9f033aef705703 Mon Sep 17 00:00:00 2001 From: Mark Patterson <35724907+markpatterson27@users.noreply.github.com> Date: Sat, 30 Oct 2021 20:36:14 +0100 Subject: [PATCH 1/2] add input for title search --- action.yml | 3 +++ index.js | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/action.yml b/action.yml index 024ac86..1528995 100644 --- a/action.yml +++ b/action.yml @@ -36,6 +36,9 @@ inputs: description: 'The direction of the sort. Can be either `asc` or `desc`.' default: 'desc' required: false + title: + description: 'Title of the Pull Request to search for.' + required: false outputs: number: diff --git a/index.js b/index.js index 817172b..a14a751 100644 --- a/index.js +++ b/index.js @@ -11,6 +11,7 @@ const main = async () => { const state = core.getInput('state') const sort = core.getInput('sort') const direction = core.getInput('direction') + const title = core.getInput('title') const repoString = core.getInput('repo') let repoObject @@ -44,9 +45,9 @@ const main = async () => { const octokit = github.getOctokit(token) const res = await octokit.rest.pulls.list(query) - const pr = author - ? res.data.length && res.data.filter(pr => pr.user.login === author)[0] - : res.data.length && res.data[0] + const pr = res.data.length && res.data.filter(pr => + (!author || pr.user.login === author) && (!title || pr.title.match(new RegExp(title))) + )[0] core.debug(`pr: ${JSON.stringify(pr, null, 2)}`) core.setOutput('number', pr ? pr.number : '') From 5cb9ad85207c253cd69773969b460a6404463fde Mon Sep 17 00:00:00 2001 From: Mark Patterson <35724907+markpatterson27@users.noreply.github.com> Date: Sat, 30 Oct 2021 21:04:52 +0100 Subject: [PATCH 2/2] prettier format filter argument --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a14a751..4ee52b2 100644 --- a/index.js +++ b/index.js @@ -45,8 +45,12 @@ const main = async () => { const octokit = github.getOctokit(token) const res = await octokit.rest.pulls.list(query) - const pr = res.data.length && res.data.filter(pr => - (!author || pr.user.login === author) && (!title || pr.title.match(new RegExp(title))) + const pr = + res.data.length && + res.data.filter( + pr => + (!author || pr.user.login === author) && + (!title || pr.title.match(new RegExp(title))) )[0] core.debug(`pr: ${JSON.stringify(pr, null, 2)}`)