Skip to content

Commit

Permalink
fix: don't comment when there are no argo changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vrivellino committed Jan 25, 2024
1 parent c106180 commit d5b5437
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
36 changes: 36 additions & 0 deletions internal/github/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,42 @@ func TestCommentExistingMulti(t *testing.T) {
}
}

func TestCommentExistingMultiNoComment(t *testing.T) {
server := newHttpTestServer(t)
defer server.Close()
httpBaseUrl, _ := url.Parse(server.URL + "/")
commentClient = github.NewClient(nil).WithAuthToken("test1234")
commentClient.BaseURL = httpBaseUrl
commentClient.UploadURL = httpBaseUrl

c, err := getExistingComments(context.Background(), "vince-riv", "argo-diff", 4)
if err != nil {
t.Errorf("getExistingComments() failed: %s", err)
}
if len(c) != 2 {
t.Error("Could not find existing comment")
} else if *c[0].ID != 4444444222 && *c[1].ID != 4444444333 {
t.Error("Unexpected issue commit IDs")
}

comments, err := Comment(context.Background(), "vince-riv", "argo-diff", 4, prHeadSha, []string{})
if err != nil {
t.Errorf("Comment() failed: %s", err)
}
if *comments[0].ID != 4444444222 {
t.Errorf("1st Comment ID doesn't match 4444444222: %d", *comments[0].ID)
}
if !strings.Contains(*comments[0].Body, "[Outdated argo-diff content]") {
t.Errorf("1st Comment body doesn't match '[Outdated argo-diff content]': %s", *comments[1].Body)
}
if *comments[1].ID != 4444444333 {
t.Errorf("2nd Comment ID doesn't match 4444444333: %d", *comments[1].ID)
}
if !strings.Contains(*comments[1].Body, "[Outdated argo-diff content]") {
t.Errorf("2nd Comment body doesn't match '[Outdated argo-diff content]': %s", *comments[1].Body)
}
}

func TestCommentNotHead(t *testing.T) {
server := newHttpTestServer(t)
defer server.Close()
Expand Down
14 changes: 6 additions & 8 deletions internal/process_event/code_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,13 @@ func ProcessCodeChange(eventInfo webhook.EventInfo, devMode bool, wg *sync.WaitG
tStr := t.Format("3:04PM MST, 2 Jan 2006")
markdownStart += " compared to live state\n"
markdownStart += "\n" + tStr + "\n"
// markdownStart += fmt.Sprintf(" as compared to live state in [%s](https://github.com/%s/%s/tree/%s) as of _%s_", eventInfo.BaseRef, eventInfo.RepoOwner, eventInfo.RepoName, eventInfo.BaseRef, tStr)
//_, _ = github.Comment(ctx, eventInfo.RepoOwner, eventInfo.RepoName, eventInfo.PrNum, markdownStart+"\n\n"+markdown)
cMarkdown.Preamble = markdownStart
//println(".............")
//fmt.Print(markdown)
//println("+++++++++++++")
//fmt.Print(cMarkdown.String()[0])
//println(".............")
_, _ = github.Comment(ctx, eventInfo.RepoOwner, eventInfo.RepoName, eventInfo.PrNum, eventInfo.Sha, cMarkdown.String())
if changeCount == 0 {
// if there are no change, don't comment (but clear out any existing comments)
_, _ = github.Comment(ctx, eventInfo.RepoOwner, eventInfo.RepoName, eventInfo.PrNum, eventInfo.Sha, []string{})
} else {
_, _ = github.Comment(ctx, eventInfo.RepoOwner, eventInfo.RepoName, eventInfo.PrNum, eventInfo.Sha, cMarkdown.String())
}
return
}
}

0 comments on commit d5b5437

Please sign in to comment.