Skip to content

Commit

Permalink
fix: the query is incorrect if either 'branch' or 'base' is not speci…
Browse files Browse the repository at this point in the history
…fied (#10)
  • Loading branch information
RoKish authored Sep 9, 2020
1 parent de7b576 commit a5949d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`)
Expand Down

0 comments on commit a5949d8

Please sign in to comment.