From bbd530afa38bc26c3fb97b7784eff072d7fb193c Mon Sep 17 00:00:00 2001 From: Patrick Dubroy Date: Mon, 31 Jan 2022 11:57:33 +0100 Subject: [PATCH] =?UTF-8?q?Ensure=20there=E2=80=99s=20a=20separate=20PR=20?= =?UTF-8?q?comment=20when=20filename=20is=20different=20(#16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 12 +++++++----- main_test.go | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) 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) |",