From a5949d861d3b2d83c0ac8a3fbcb946c152a71215 Mon Sep 17 00:00:00 2001 From: Roman Kishchenko Date: Wed, 9 Sep 2020 11:17:28 +0300 Subject: [PATCH] fix: the query is incorrect if either 'branch' or 'base' is not specified (#10) --- action.yml | 2 +- index.js | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 42495f72..b6e6a748 100644 --- a/action.yml +++ b/action.yml @@ -10,7 +10,7 @@ inputs: required: true branch: description: 'Branch name' - required: true + required: false base: description: 'The base branch name of the Pull Request' required: false diff --git a/index.js b/index.js index c08c7b1d..980cd6e2 100644 --- a/index.js +++ b/index.js @@ -6,17 +6,22 @@ const { GitHub, context } = require('@actions/github') const main = async () => { const token = core.getInput('github-token') const branch = core.getInput('branch') - const base = core.getInput('base', { required: false }) + const base = core.getInput('base') + + const query = { + ...context.repo, + state: 'open' + } + if (branch) { + query.head = `${context.repo.owner}:${branch}` + } + if (base) { + query.base = base + } const octokit = new GitHub(token) - const res = await octokit.pulls.list({ - ...context.repo, - state: 'open', - head: `${context.repo.owner}:${branch}`, - base - }) - + const res = await octokit.pulls.list(query) const pr = res.data.length && res.data[0] core.debug(`pr: ${JSON.stringify(pr, null, 2)}`)