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
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.25.7
require (
github.com/akedrou/textdiff v0.1.0
github.com/bradleyfalzon/ghinstallation/v2 v2.19.0
github.com/google/go-github/v85 v85.0.0
github.com/google/go-github/v88 v88.0.0
github.com/rs/zerolog v1.35.1
github.com/spf13/pflag v1.0.10
k8s.io/apimachinery v0.35.4
Expand All @@ -18,7 +18,6 @@ require (
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/google/go-github/v88 v88.0.0 // indirect
github.com/google/go-querystring v1.2.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/text v0.2.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/go-github/v85 v85.0.0 h1:1+TLFX/akTFXK7o9Z9uAloQGufOn4ySa5DItUM1VWT4=
github.com/google/go-github/v85 v85.0.0/go.mod h1:jYkBnqN+SzR2A2fGKYfbt6DEEQAyxeK0Q2XpPV9ZFsU=
github.com/google/go-github/v88 v88.0.0 h1:dZA9IKkPK1eXZj4ypngnpRj5FwdpTv4whix2PrQMP7M=
github.com/google/go-github/v88 v88.0.0/go.mod h1:rufTDgn2N45wjhukLTyxmvc9nilSp3mr3Rgtt6b1MPw=
github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0=
Expand Down
28 changes: 23 additions & 5 deletions internal/github/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"time"

ghinstallation "github.com/bradleyfalzon/ghinstallation/v2"
"github.com/google/go-github/v85/github"
"github.com/google/go-github/v88/github"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -45,9 +45,19 @@ func init() {
}
// Create Github API client
if githubPAT := os.Getenv("GITHUB_PERSONAL_ACCESS_TOKEN"); githubPAT != "" {
commentClient = github.NewClient(nil).WithAuthToken(githubPAT)
var err error
commentClient, err = github.NewClient(github.WithAuthToken(githubPAT))
if err != nil {
log.Error().Err(err).Msg("Failed to create github client")
return
}
} else if githubToken := os.Getenv("GITHUB_TOKEN"); githubToken != "" {
commentClient = github.NewClient(nil).WithAuthToken(githubToken)
var err error
commentClient, err = github.NewClient(github.WithAuthToken(githubToken))
if err != nil {
log.Error().Err(err).Msg("Failed to create github client")
return
}
} else {
tr := http.DefaultTransport
appId, err := strconv.ParseInt(os.Getenv("GITHUB_APP_ID"), 10, 64)
Expand All @@ -67,8 +77,16 @@ func init() {
return
}
itr := ghinstallation.NewFromAppsTransport(atr, installId)
commentClient = github.NewClient(&http.Client{Transport: itr})
appsClient = github.NewClient(&http.Client{Transport: atr}) // /app endpoints need separate client
commentClient, err = github.NewClient(github.WithHTTPClient(&http.Client{Transport: itr}))
if err != nil {
log.Error().Err(err).Msg("Failed to create github comment client")
return
}
appsClient, err = github.NewClient(github.WithHTTPClient(&http.Client{Transport: atr}))
if err != nil {
log.Error().Err(err).Msg("Failed to create github apps client")
return
}
commentClientIsApp = true
}
}
Expand Down
63 changes: 37 additions & 26 deletions internal/github/comment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
"io"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path/filepath"
"strings"
"testing"

"github.com/google/go-github/v85/github"
"github.com/google/go-github/v88/github"
)

const testDataDir = "github_testdata"
Expand Down Expand Up @@ -174,10 +173,12 @@ func newHttpTestServer(t *testing.T) *httptest.Server {
func TestCommentNoExistingComments(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
baseURL := server.URL + "/"
var err error
commentClient, err = github.NewClient(github.WithAuthToken("test1234"), github.WithURLs(&baseURL, &baseURL))
if err != nil {
t.Fatalf("Failed to create github client: %s", err)
}

c, err := getExistingComments(context.Background(), "vince-riv", "argo-diff", 1)
if err != nil {
Expand All @@ -199,10 +200,12 @@ func TestCommentNoExistingComments(t *testing.T) {
func TestCommentExistingDifferentUser(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
baseURL := server.URL + "/"
var err error
commentClient, err = github.NewClient(github.WithAuthToken("test1234"), github.WithURLs(&baseURL, &baseURL))
if err != nil {
t.Fatalf("Failed to create github client: %s", err)
}

c, err := getExistingComments(context.Background(), "vince-riv", "argo-diff", 2)
if err != nil {
Expand All @@ -224,10 +227,12 @@ func TestCommentExistingDifferentUser(t *testing.T) {
func TestCommentExisting(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
baseURL := server.URL + "/"
var err error
commentClient, err = github.NewClient(github.WithAuthToken("test1234"), github.WithURLs(&baseURL, &baseURL))
if err != nil {
t.Fatalf("Failed to create github client: %s", err)
}

c, err := getExistingComments(context.Background(), "vince-riv", "argo-diff", 3)
if err != nil {
Expand All @@ -251,10 +256,12 @@ func TestCommentExisting(t *testing.T) {
func TestCommentExistingMulti(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
baseURL := server.URL + "/"
var err error
commentClient, err = github.NewClient(github.WithAuthToken("test1234"), github.WithURLs(&baseURL, &baseURL))
if err != nil {
t.Fatalf("Failed to create github client: %s", err)
}

c, err := getExistingComments(context.Background(), "vince-riv", "argo-diff", 4)
if err != nil {
Expand Down Expand Up @@ -287,10 +294,12 @@ 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
baseURL := server.URL + "/"
var err error
commentClient, err = github.NewClient(github.WithAuthToken("test1234"), github.WithURLs(&baseURL, &baseURL))
if err != nil {
t.Fatalf("Failed to create github client: %s", err)
}

c, err := getExistingComments(context.Background(), "vince-riv", "argo-diff", 4)
if err != nil {
Expand Down Expand Up @@ -323,10 +332,12 @@ func TestCommentExistingMultiNoComment(t *testing.T) {
func TestCommentNotHead(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
baseURL := server.URL + "/"
var err error
commentClient, err = github.NewClient(github.WithAuthToken("test1234"), github.WithURLs(&baseURL, &baseURL))
if err != nil {
t.Fatalf("Failed to create github client: %s", err)
}

prHeadShaOld := "1111111111111111111111111111111111111111"

Expand Down
19 changes: 15 additions & 4 deletions internal/github/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"

ghinstallation "github.com/bradleyfalzon/ghinstallation/v2"
"github.com/google/go-github/v85/github"
"github.com/google/go-github/v88/github"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -37,11 +37,19 @@ func init() {
}
// Create Github API client
if githubPAT := os.Getenv("GITHUB_PERSONAL_ACCESS_TOKEN"); githubPAT != "" {
statusClient = github.NewClient(nil).WithAuthToken(githubPAT)
var err error
statusClient, err = github.NewClient(github.WithAuthToken(githubPAT))
if err != nil {
log.Error().Err(err).Msg("Failed to create github status client")
}
return
}
if githubToken := os.Getenv("GITHUB_TOKEN"); githubToken != "" {
statusClient = github.NewClient(nil).WithAuthToken(githubToken)
var err error
statusClient, err = github.NewClient(github.WithAuthToken(githubToken))
if err != nil {
log.Error().Err(err).Msg("Failed to create github status client")
}
return
}
tr := http.DefaultTransport
Expand All @@ -61,7 +69,10 @@ func init() {
log.Error().Err(err).Msgf("Failed to create github client: appId %d, installId %d, privKey %s...", appId, installId, privKey[:15])
return
}
statusClient = github.NewClient(&http.Client{Transport: itr})
statusClient, err = github.NewClient(github.WithHTTPClient(&http.Client{Transport: itr}))
if err != nil {
log.Error().Err(err).Msg("Failed to create github status client")
}
}

// Helper that sets commit status for the request commit sha
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"

"github.com/google/go-github/v85/github"
"github.com/google/go-github/v88/github"
"github.com/rs/zerolog/log"

argoDiffGh "github.com/vince-riv/argo-diff/internal/github"
Expand Down