Skip to content

Commit

Permalink
feat: support push event
Browse files Browse the repository at this point in the history
  • Loading branch information
tockn committed Jan 16, 2024
1 parent 27b787d commit a7da9c2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
34 changes: 28 additions & 6 deletions dist/post/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/post/index.js.map

Large diffs are not rendered by default.

41 changes: 31 additions & 10 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,44 @@ async function reportAll(
}

const commentOnPR: string = core.getInput('comment_on_pr')
if (pull_request && 'true' === commentOnPR) {
if (logger.isDebugEnabled()) {
logger.debug(`Found Pull Request: ${JSON.stringify(pull_request)}`)
}
if ('true' === commentOnPR) {
const prNumbers = await getPrNumbers();
if (prNumbers) {
if (logger.isDebugEnabled()) {
logger.debug(`Found Pull Request: ${JSON.stringify(prNumbers)}`)
}

await octokit.rest.issues.createComment({
...github.context.repo,
issue_number: Number(github.context.payload.pull_request?.number),
body: postContent
})
for (let prNumber of prNumbers) {
await octokit.rest.issues.createComment({
...github.context.repo,
issue_number: prNumber,
body: postContent
})
}
} else {
logger.debug(`Couldn't find Pull Request`)
}
} else {
logger.debug(`Couldn't find Pull Request`)
logger.debug(`commentOnPR is false`)
}

logger.info(`Reporting all content completed`)
}

export async function getPrNumbers(): Promise<number[] | undefined> {
if (pull_request) {
return [pull_request.number]
}

const { data: pullRequests } = await octokit.repos.listPullRequestsAssociatedWithCommit({
owner: repo.owner,
repo: repo.repo,
commit_sha: sha,
});

return pullRequests.filter((pr) => pr.state === "open").map((pr) => pr.number).slice(0, 10);
}

async function run(): Promise<void> {
try {
logger.info(`Finishing ...`)
Expand Down

0 comments on commit a7da9c2

Please sign in to comment.