MCPcopy Index your code
hub / github.com/bytebase/bytebase / upsertComment

Function upsertComment

action/github/github.go:65–100  ·  view source on GitHub ↗
(resp *v1pb.CheckReleaseResponse, ghe *githubEnv)

Source from the content-addressed store, hash-verified

63}
64
65func 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
102func buildCommentMessage(resp *v1pb.CheckReleaseResponse) string {
103 var errorCount, warningCount int

Callers 1

Calls 7

getPRNumberFromEventFileFunction · 0.85
buildCommentMessageFunction · 0.85
listCommentsMethod · 0.80
updateCommentMethod · 0.80
createCommentMethod · 0.80
newClientFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected