Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support clear bot history on new build #390

Merged
merged 5 commits into from
Sep 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions build/ci/github-bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
tokenSecretName = "gh-token"
owner = "googleforgames"
repo = "quilkin"
quilkinBotId = 84364394
)

func main() {
Expand Down Expand Up @@ -118,6 +119,8 @@ func (g *githubNotifier) SendNotification(ctx context.Context, build *cloudbuild
}
}

g.clearBotComments(ctx, pr)

commentBody := body.String()
comment := &github.IssueComment{
Body: &commentBody,
Expand All @@ -129,6 +132,22 @@ func (g *githubNotifier) SendNotification(ctx context.Context, build *cloudbuild
return nil
}

func (g *githubNotifier) clearBotComments(ctx context.Context, pr int) error {
comments, _, err := g.client.Issues.ListComments(ctx, owner, repo, pr, &github.IssueListCommentsOptions{})
if err != nil {
log.Errorf("Error retrieving comment history: %v on PR with id: %s", err, pr)
return nil
}

for _, comment := range comments {
if *comment.User.ID == quilkinBotId {
g.client.Issues.DeleteComment(ctx, owner, repo, *comment.ID)
}
}

return nil
}

const successTemplate = `
{{ $pr := .Substitutions._PR_NUMBER }}
**Build Succeeded :partying_face:**
Expand Down