Skip to content

Commit 21f792e

Browse files
akerlbluekeyes
authored andcommitted
Fix example functionality (#19)
This fixes the example API call, cleans up the logging, and adds a check to ensure it doesn’t loop forever on its own comments
1 parent 9f02316 commit 21f792e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

example/issue_comment.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"encoding/json"
2020
"fmt"
21+
"strings"
2122

2223
"github.com/google/go-github/github"
2324
"github.com/pkg/errors"
@@ -65,16 +66,21 @@ func (h *PRCommentHandler) Handle(ctx context.Context, eventType, deliveryID str
6566

6667
repoOwner := repo.GetOwner().GetLogin()
6768
repoName := repo.GetName()
68-
author := event.GetComment().GetUser()
69+
author := event.GetComment().GetUser().GetLogin()
6970
body := event.GetComment().GetBody()
7071

72+
if strings.HasSuffix(author, "[bot]") {
73+
logger.Debug().Msg("Issue comment was created by a bot")
74+
return nil
75+
}
76+
7177
logger.Debug().Msgf("Echoing comment on %s/%s#%d by %s", repoOwner, repoName, prNum, author)
72-
msg := fmt.Sprintf("%s\n%s said\n```%s\n```\n", h.preamble, author, body)
73-
prComment := github.PullRequestComment{
78+
msg := fmt.Sprintf("%s\n%s said\n```\n%s\n```\n", h.preamble, author, body)
79+
prComment := github.IssueComment{
7480
Body: &msg,
7581
}
7682

77-
if _, _, err := client.PullRequests.CreateComment(ctx, repoOwner, repoName, prNum, &prComment); err != nil {
83+
if _, _, err := client.Issues.CreateComment(ctx, repoOwner, repoName, prNum, &prComment); err != nil {
7884
logger.Error().Err(err).Msg("Failed to comment on pull request")
7985
}
8086

0 commit comments

Comments
 (0)