Skip to content

Commit

Permalink
Added support for pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
poldz123 committed Jan 22, 2021
1 parent 1779673 commit 9d96a17
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 35 deletions.
42 changes: 30 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

54 changes: 32 additions & 22 deletions src/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,44 @@ import * as core from '@actions/core'
import * as github from '@actions/github'
import {IDENTIFIER} from './comment'

/* eslint-disable @typescript-eslint/no-explicit-any*/
// /* eslint-disable @typescript-eslint/no-explicit-any*/
export async function findPullRequest(githubToken: string): Promise<any> {
/* eslint-enable */
const octokit = github.getOctokit(githubToken)

const {
sha: commitSha,
repo: {repo: repoName, owner: repoOwner}
payload: {pull_request: pullRequest}
} = github.context

const defaultParameter = {
repo: repoName,
owner: repoOwner
}

const {
data: pullRequests
} = await octokit.repos.listPullRequestsAssociatedWithCommit({
...defaultParameter,
commit_sha: commitSha
})
if (pullRequests.length === 0) {
core.info(
`WARNING: Unable to find pull request for commit sha: ${commitSha}`
)
if (pullRequest == null) {
core.info(`WARNING: Unable to find pull request`)
return null
} else {
return pullRequest
}
return pullRequests[0]
// /* eslint-enable */
// const octokit = github.getOctokit(githubToken)

// const {
// sha: commitSha,
// repo: {repo: repoName, owner: repoOwner}
// } = github.context

// const defaultParameter = {
// repo: repoName,
// owner: repoOwner
// }

// const {
// data: pullRequests
// } = await octokit.repos.listPullRequestsAssociatedWithCommit({
// ...defaultParameter,
// commit_sha: commitSha
// })
// if (pullRequests.length === 0) {
// core.info(
// `WARNING: Unable to find pull request for commit sha: ${commitSha}`
// )
// return null
// }
// return pullRequests[0]
}

export async function pushCommentOnPullRequest(
Expand Down

0 comments on commit 9d96a17

Please sign in to comment.