Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions githubbot/githubbot/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/bradleyfalzon/ghinstallation/v2"

"github.com/google/go-github/v31/github"
"github.com/google/go-github/v89/github"
"github.com/keybase/go-keybase-chat-bot/kbchat"
"github.com/keybase/go-keybase-chat-bot/kbchat/types/chat1"
"github.com/keybase/managed-bots/base"
Expand Down Expand Up @@ -72,7 +72,10 @@ func (h *Handler) HandleCommand(ctx context.Context, msg chat1.MsgSummary) error
return h.handleMentionPref(ctx, cmd, msg)
}

client := github.NewClient(&http.Client{Transport: h.atr})
client, err := github.NewClient(github.WithHTTPClient(&http.Client{Transport: h.atr}))
if err != nil {
return fmt.Errorf("error creating github client: %s", err)
}
switch {
case strings.HasPrefix(cmd, "!github subscribe"):
h.stats.Count("subscribe")
Expand Down Expand Up @@ -202,15 +205,15 @@ func (h *Handler) handleListSubscriptions(ctx context.Context, msg chat1.MsgSumm

var res strings.Builder
for repo, f := range features {
res.WriteString(fmt.Sprintf("- *%s* (%s)\n", repo, &f))
fmt.Fprintf(&res, "- *%s* (%s)\n", repo, &f)
if f.Commits {
branches, err := h.db.GetAllBranchesForRepo(ctx, msg.ConvID, repo)
if err != nil {
return fmt.Errorf("error getting branches for repo: %s", err)
}

for _, branch := range branches {
res.WriteString(fmt.Sprintf(" - %s\n", branch))
fmt.Fprintf(&res, " - %s\n", branch)
}
}
}
Expand All @@ -224,7 +227,7 @@ func (h *Handler) handleNewSubscription(ctx context.Context, repo string, msg ch
h.ChatEcho(msg.ConvID, "`%s` doesn't look like a repository to me! Try sending `!github subscribe <owner/repo>`", repo)
return false, nil
}
repoInstallation, res, err := client.Apps.FindRepositoryInstallation(context.TODO(), parsedRepo[0], parsedRepo[1])
repoInstallation, res, err := client.Apps.GetRepositoryInstallation(context.TODO(), parsedRepo[0], parsedRepo[1])
if err != nil {
switch res.StatusCode {
case http.StatusNotFound:
Expand All @@ -243,7 +246,10 @@ func (h *Handler) handleNewSubscription(ctx context.Context, repo string, msg ch
if err != nil || tc == nil {
return false, err
}
userClient := github.NewClient(tc)
userClient, err := github.NewClient(github.WithHTTPClient(tc))
if err != nil {
return false, fmt.Errorf("error creating github client: %s", err)
}
installations, _, err := userClient.Apps.ListUserInstallations(context.TODO(), nil)
if err != nil {
return false, fmt.Errorf("Error getting installations for current user: %s", err)
Expand Down
20 changes: 11 additions & 9 deletions githubbot/githubbot/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/bradleyfalzon/ghinstallation/v2"

"github.com/google/go-github/v31/github"
"github.com/google/go-github/v89/github"
"github.com/keybase/go-keybase-chat-bot/kbchat"
"github.com/keybase/managed-bots/base"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -85,7 +85,11 @@ func (h *HTTPSrv) handleWebhook(_ http.ResponseWriter, r *http.Request) {
}

itr := ghinstallation.NewFromAppsTransport(h.atr, installationID)
client := github.NewClient(&http.Client{Transport: itr})
client, err := github.NewClient(github.WithHTTPClient(&http.Client{Transport: itr}))
if err != nil {
h.Errorf("error creating github client: %s", err)
return
}

if repo == "" {
return
Expand Down Expand Up @@ -189,7 +193,9 @@ func (h *HTTPSrv) formatMessage(ctx context.Context, convID chat1.ConvIDStr, eve
event.GetRepo().GetName(),
), ""
case *github.PushEvent:
if len(event.Commits) == 0 {
// event.Commits is deprecated for the Events API polling endpoint, but webhook
// payloads still include it. See: https://docs.github.com/en/webhooks/webhook-events-and-payloads#push
if len(event.Commits) == 0 { //nolint:staticcheck
break
}

Expand All @@ -200,7 +206,7 @@ func (h *HTTPSrv) formatMessage(ctx context.Context, convID chat1.ConvIDStr, eve
event.GetSender().GetLogin(),
event.GetRepo().GetName(),
branch,
len(event.Commits),
len(event.Commits), //nolint:staticcheck
commitMsgs,
event.GetCompare(),
), branch
Expand Down Expand Up @@ -243,11 +249,7 @@ func (h *HTTPSrv) formatMessage(ctx context.Context, convID chat1.ConvIDStr, eve
event.GetRepo().GetOwner().GetLogin(),
event.GetRepo().GetName(),
event.GetSHA(),
&github.PullRequestListOptions{
State: "open",
Sort: "updated",
Direction: "desc",
},
nil,
)
if err != nil && !strings.Contains(err.Error(), "401 Bad credentials") {
h.Errorf("error getting pull requests from commit: %s", err)
Expand Down
6 changes: 4 additions & 2 deletions githubbot/githubbot/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import (
"github.com/keybase/go-keybase-chat-bot/kbchat"
"github.com/keybase/managed-bots/base"

"github.com/google/go-github/v31/github"
"github.com/google/go-github/v89/github"
)

func getCommitMessages(event *github.PushEvent) []string {
commitMsgs := make([]string, 0)
for _, commit := range event.Commits {
// event.Commits is deprecated for the Events API polling endpoint, but webhook
// payloads still include it. See: https://docs.github.com/en/webhooks/webhook-events-and-payloads#push
for _, commit := range event.Commits { //nolint:staticcheck
commitMsgs = append(commitMsgs, commit.GetMessage())
}
return commitMsgs
Expand Down
8 changes: 6 additions & 2 deletions githubbot/migrations/default_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/bradleyfalzon/ghinstallation/v2"
_ "github.com/go-sql-driver/mysql"
"github.com/google/go-github/v31/github"
"github.com/google/go-github/v89/github"

"github.com/keybase/managed-bots/githubbot/githubbot"
)
Expand Down Expand Up @@ -89,7 +89,11 @@ func mainInner() int {
fmt.Printf("Found %d subscriptions to migrate\n", len(subs))
for i, subscription := range subs {
itr := ghinstallation.NewFromAppsTransport(atr, subscription.InstallationID)
client := github.NewClient(&http.Client{Transport: itr})
client, err := github.NewClient(github.WithHTTPClient(&http.Client{Transport: itr}))
if err != nil {
fmt.Printf("Error creating github client for subscription %d/%d: %s\n", i, len(subs), err)
continue
}

defaultBranch, err := githubbot.GetDefaultBranch(subscription.Repo, client)
if err != nil {
Expand Down
27 changes: 13 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module github.com/keybase/managed-bots

go 1.24.0
go 1.25.0

toolchain go1.25.5

require (
github.com/aws/aws-sdk-go-v2 v1.41.0
github.com/aws/aws-sdk-go-v2 v1.42.1
github.com/aws/aws-sdk-go-v2/config v1.32.5
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.62.2
github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.79.0
github.com/aws/aws-sdk-go-v2/service/ses v1.34.17
github.com/bradleyfalzon/ghinstallation/v2 v2.17.0
github.com/go-sql-driver/mysql v1.9.3
github.com/google/go-github/v31 v31.0.0
github.com/go-sql-driver/mysql v1.10.0
github.com/google/go-github/v89 v89.0.0
github.com/gorilla/mux v1.7.3
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/keybase/go-codec v0.0.0-20180928230036-164397562123
Expand All @@ -26,20 +26,20 @@ require (
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 // indirect
filippo.io/edwards25519 v1.2.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.14 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.19.5 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.16 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.16 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.13 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.30 // indirect
github.com/aws/aws-sdk-go-v2/service/signin v1.0.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.30.7 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.12 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.41.5 // indirect
github.com/aws/smithy-go v1.24.0 // indirect
github.com/aws/smithy-go v1.27.3 // indirect
github.com/go-pkgz/expirable-cache v0.1.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/google/go-github/v75 v75.0.0 // indirect
Expand All @@ -51,15 +51,14 @@ require (
github.com/didip/tollbooth/v7 v7.0.1
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect
github.com/golang/protobuf v1.3.5 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/go-querystring v1.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-retryablehttp v0.6.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opencensus.io v0.22.1 // indirect
golang.org/x/crypto v0.46.0 // indirect
golang.org/x/net v0.48.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.32.0 // indirect
Expand Down
Loading
Loading