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 5, 2024
1 parent 6ad1ae8 commit 7a5192d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 28 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
41 changes: 27 additions & 14 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -110983,6 +110983,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 require$$0$1.promises.readFile(lcovFile, "utf-8").catch(err => null);
Expand Down Expand Up @@ -111029,20 +111030,32 @@ async function main() {
await deleteOldComments(githubClient, options, context);
}

if (context.eventName === "pull_request" || context.eventName === "pull_request_target") {
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" ||
context.eventName === "pull_request_target"
) {
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:
core.warning(`Unknown post-to value: '${postTo}'`);
}
}

Expand Down
41 changes: 27 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,32 @@ async function main() {
await deleteOldComments(githubClient, options, context)
}

if (context.eventName === "pull_request" || context.eventName === "pull_request_target") {
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" ||
context.eventName === "pull_request_target"
) {
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:
core.warning(`Unknown post-to value: '${postTo}'`)
}
}

Expand Down

0 comments on commit 7a5192d

Please sign in to comment.