forked from fastify/github-action-merge-dependabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getPullRequest.js
39 lines (29 loc) · 1007 Bytes
/
getPullRequest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict'
const github = require('@actions/github')
const { getInputs } = require('./util')
const { logError } = require('./log')
const { GITHUB_TOKEN, PR_NUMBER } = getInputs()
const getPullRequest = async () => {
const payload = github.context.payload
// Checks for "workflow" context to set the pull request, otherwise defaults to checking "pull request" context
if (payload.workflow) {
if (!PR_NUMBER || (PR_NUMBER && isNaN(PR_NUMBER))) {
return logError(
'Missing or invalid pull request number. Please make sure you are using a valid pull request number'
)
}
const octokit = github.getOctokit(GITHUB_TOKEN)
const repo = payload.repository
const owner = repo.owner.login
const repoName = repo.name
const { data: pullRequest } = await octokit.rest.pulls.get({
owner,
repo: repoName,
pull_number: PR_NUMBER,
})
return pullRequest
} else {
return payload.pull_request
}
}
module.exports = getPullRequest