diff --git a/main.go b/main.go index a8bc590..8913ca3 100644 --- a/main.go +++ b/main.go @@ -179,7 +179,7 @@ func commentOnGitHubPullRequest(o *options, prNodeID string) func(map[string][]s return err } - id, err := existingCommentId(prNodeID) + id, err := existingCommentId(prNodeID, o.filename) if err != nil { return err } @@ -261,7 +261,7 @@ func commitCount(prNodeID string) (int, error) { return data.Node.Commits.TotalCount, err } -func existingCommentId(prNodeID string) (string, error) { +func existingCommentId(prNodeID string, filename string) (string, error) { data := struct { Node struct { Comments struct { @@ -301,7 +301,7 @@ func existingCommentId(prNodeID string) (string, error) { } for _, comment := range data.Node.Comments.Nodes { - if strings.HasPrefix(comment.Body, markdownCommentTitle) { + if strings.HasPrefix(comment.Body, markdownCommentTitle(filename)) { return comment.Id, nil } } @@ -379,7 +379,9 @@ type options struct { print func(notifs map[string][]string) error } -const markdownCommentTitle = "\n" +func markdownCommentTitle(filename string) string { + return fmt.Sprintf("\n", filename) +} func (o *options) writeNotifications(w io.Writer, notifs map[string][]string) error { subs := []string{} @@ -401,7 +403,7 @@ func (o *options) writeNotifications(w io.Writer, notifs map[string][]string) er } return nil case "markdown": - fmt.Fprint(w, markdownCommentTitle) + fmt.Fprint(w, markdownCommentTitle(o.filename)) fmt.Fprintf(w, "[Codenotify](https://github.com/sourcegraph/codenotify): Notifying subscribers in %s files for diff %s...%s.\n\n", o.filename, o.baseRef, o.headRef) if len(notifs) == 0 { fmt.Fprintln(w, "No notifications.") diff --git a/main_test.go b/main_test.go index 20808a0..1aa8585 100644 --- a/main_test.go +++ b/main_test.go @@ -146,7 +146,7 @@ func TestWriteNotifications(t *testing.T) { }, notifs: nil, output: []string{ - "", + "", "[Codenotify](https://github.com/sourcegraph/codenotify): Notifying subscribers in CODENOTIFY files for diff a...b.", "", "No notifications.", @@ -179,7 +179,7 @@ func TestWriteNotifications(t *testing.T) { "@js": {"file.js", "dir/file.js"}, }, output: []string{ - "", + "", "[Codenotify](https://github.com/sourcegraph/codenotify): Notifying subscribers in CODENOTIFY files for diff a...b.", "", "| Notify | File(s) |",