Skip to content

Commit

Permalink
Allow post the report to job summary
Browse files Browse the repository at this point in the history
  • Loading branch information
06393993 committed Jul 29, 2023
1 parent 4cf015a commit 0f29c5a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ inputs:
description: Set working directory if project is not in root folder
required: false
default: "./"
post-to:
description: Post the coverage report to either "comment" or "job-summary"
required: false
default: "comment"
title:
description: Title to add to the comment
required: false
Expand Down
38 changes: 24 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async function main() {
core.getInput("filter-changed-files").toLowerCase() === "true"
const shouldDeleteOldComments =
core.getInput("delete-old-comments").toLowerCase() === "true"
const postTo = core.getInput("post-to").toLowerCase()
const title = core.getInput("title")

const raw = await fs.readFile(lcovFile, "utf-8").catch(err => null)
Expand Down Expand Up @@ -67,20 +68,29 @@ async function main() {
await deleteOldComments(githubClient, options, context)
}

if (context.eventName === "pull_request") {
await githubClient.issues.createComment({
repo: context.repo.repo,
owner: context.repo.owner,
issue_number: context.payload.pull_request.number,
body: body,
})
} else if (context.eventName === "push") {
await githubClient.repos.createCommitComment({
repo: context.repo.repo,
owner: context.repo.owner,
commit_sha: options.commit,
body: body,
})
switch (postTo) {
case "comment":
if (context.eventName === "pull_request") {
await githubClient.issues.createComment({
repo: context.repo.repo,
owner: context.repo.owner,
issue_number: context.payload.pull_request.number,
body: body,
})
} else if (context.eventName === "push") {
await githubClient.repos.createCommitComment({
repo: context.repo.repo,
owner: context.repo.owner,
commit_sha: options.commit,
body: body,
})
}
break
case "job-summary":
await core.summary.addRaw(body).write()
break
default:
console.warn(`Unknown post-to value: '${postTo}'`)
}
}

Expand Down

0 comments on commit 0f29c5a

Please sign in to comment.