Skip to content

Commit

Permalink
fix: Cloud Build reporter issue comment (#278)
Browse files Browse the repository at this point in the history
* fix: Cloud Build reporter issue comment

* bracket
  • Loading branch information
duwenxin99 authored Nov 15, 2024
1 parent 72045d2 commit a24109b
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions .github/workflows/cloud_build_failure_reporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
creator: 'github-actions[bot]',
labels: [periodicLabel]
});
// createOrCommentIssue creates a new issue or comments on an existing issue.
const createOrCommentIssue = async function (title, txt) {
if (prevIssues.length < 1) {
Expand All @@ -69,34 +70,39 @@ jobs:
});
return;
}
if (prevIssues.length > 1) {
console.warn(
`found ${prevIssues.length} issues but only adding comment to ${prevIssues[0].html_url}`
);
// only comment on issue related to the current test
for (const prevIssue of prevIssues) {
if (prevIssue.title.includes(title)){
console.log(
`found previous issue ${prevIssue.html_url}, adding comment`
);
await github.rest.issues.createComment({
...context.repo,
issue_number: prevIssue.number,
body: txt
});
return;
}
}
console.log(
`found previous issue ${prevIssues[0].html_url}, adding comment`
);
await github.rest.issues.createComment({
...context.repo,
issue_number: prevIssues[0].number,
body: txt
});
};
// updateIssues comments on any existing issues. No-op if no issue exists.
const updateIssues = async function (txt) {
const updateIssues = async function (checkName, txt) {
if (prevIssues.length < 1) {
console.log('no previous issues found.');
return;
}
// only comment on issue related to the current test
for (const prevIssue of prevIssues) {
console.log(`found previous issue ${prevIssue.html_url}, adding comment`);
await github.rest.issues.createComment({
...context.repo,
issue_number: prevIssue.number,
body: txt
});
if (prevIssue.title.includes(checkName)){
console.log(`found previous issue ${prevIssue.html_url}, adding comment`);
await github.rest.issues.createComment({
...context.repo,
issue_number: prevIssue.number,
body: txt
});
}
}
};
Expand Down Expand Up @@ -146,6 +152,7 @@ jobs:
check.conclusion === 'success'
) {
updateIssues(
check.name,
`[Tests are passing](${check.html_url}) for commit [${commit.sha}](${commit.html_url}).`
);
} else if (check.status === 'in_progress') {
Expand Down

0 comments on commit a24109b

Please sign in to comment.