(resp *v1pb.CheckReleaseResponse, ghe *githubEnv)
| 63 | } |
| 64 | |
| 65 | func upsertComment(resp *v1pb.CheckReleaseResponse, ghe *githubEnv) error { |
| 66 | if ghe.EventName != "pull_request" { |
| 67 | fmt.Println("::warning not a pull request event, will not create a comment.") |
| 68 | return nil |
| 69 | } |
| 70 | pr, err := getPRNumberFromEventFile(ghe.EventPath) |
| 71 | if err != nil { |
| 72 | fmt.Printf("::warning failed to get pull request number from event file, will not create a comment. error: %v", err.Error()) |
| 73 | return nil |
| 74 | } |
| 75 | if pr == "" { |
| 76 | fmt.Println("::warning no pull request number found in the environment variables, will not create a comment.") |
| 77 | return nil |
| 78 | } |
| 79 | // upsert the comment |
| 80 | c := newClient(ghe.APIUrl, ghe.Token) |
| 81 | comments, err := c.listComments(ghe.Repo, pr) |
| 82 | if err != nil { |
| 83 | return errors.Wrapf(err, "failed to list comments") |
| 84 | } |
| 85 | for _, comment := range comments { |
| 86 | if comment.User.ID == githubActionUserID && strings.HasPrefix(comment.Body, commentHeader) { |
| 87 | // update the comment |
| 88 | if err := c.updateComment(ghe.Repo, comment.ID, buildCommentMessage(resp)); err != nil { |
| 89 | return errors.Wrapf(err, "failed to update comment") |
| 90 | } |
| 91 | return nil |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // create a new comment |
| 96 | if err := c.createComment(ghe.Repo, pr, buildCommentMessage(resp)); err != nil { |
| 97 | return errors.Wrapf(err, "failed to create comment") |
| 98 | } |
| 99 | return nil |
| 100 | } |
| 101 | |
| 102 | func buildCommentMessage(resp *v1pb.CheckReleaseResponse) string { |
| 103 | var errorCount, warningCount int |
no test coverage detected