Skip to content

Commit

Permalink
Upsteam merge (#10)
Browse files Browse the repository at this point in the history
* Add pagination to "List files in PR" api call (wayfair-incubator#174)

* Support pagination for "List files in PR" API call
+relevant test

* Update golangci/golangci-lint-action action to v6 (wayfair-incubator#170)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update GitHub Actions (wayfair-incubator#144)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update module github.com/google/go-github/v53 to v62 (wayfair-incubator#173)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update all non-major dependencies (wayfair-incubator#136)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* fix(automerge): implement exponential backoff (wayfair-incubator#181)

* fix(automerge): implement exponential backoff

* Update internal/pkg/githubapi/github.go

* Fix > 250 char Branch name issue (wayfair-incubator#188)

* Fix > 250 char Branch name issue

Move branch name generation to a function.
Limit original branch substing to 200 charts
Switch target paths substring to sha1 of the target paths.
Tests

* Address issues raised in PR review:

Rename a var
Used Repeat to avoid hardcoding long string
Made some test input **a bit** more realistic

* Cleanup some conflict marker and add comment

* Fix some merge bug

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Benas Taurosevičius <benas.taurosevicius@plumery.com>
  • Loading branch information
3 people authored Jun 12, 2024
1 parent ad47e29 commit 0fcbba5
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 66 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/docker-publish-on-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,20 @@ jobs:

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@edfb0fe6204400c56fbfd3feba3fe9ad1adfa345
uses: docker/setup-buildx-action@5138f76647652447004da686b2411557eaf65f33

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into GH registry (ghcr.io)
uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb
uses: docker/login-action@70fccc794acd729b2b22dd6a326895f286447728
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log into Docker Hub registry
if: env.DOCKERHUB_USERNAME != ''
uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb
uses: docker/login-action@70fccc794acd729b2b22dd6a326895f286447728
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -70,7 +70,7 @@ jobs:
# 2nd image name is for DockerHub image
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c
uses: docker/metadata-action@f7b4ed12385588c3f9bc252f0a2b520d83b52d48
with:
context: git
images: |
Expand All @@ -85,7 +85,7 @@ jobs:
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@9f6f8c940b91232557f8699b21341a08624a8dce
uses: docker/build-push-action@2a53c6ccda456d31fb62eedc658aae06e238b7bd
with:
context: .
push: true
Expand All @@ -96,7 +96,7 @@ jobs:

- name: Extract Docker metadata - alpine
id: meta-alpine
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c
uses: docker/metadata-action@f7b4ed12385588c3f9bc252f0a2b520d83b52d48
with:
context: git
images: |
Expand All @@ -108,7 +108,7 @@ jobs:
flavor: prefix=alpine-,onlatest=true
- name: Build and push Docker image - alpine
id: build-and-push-alpine
uses: docker/build-push-action@9f6f8c940b91232557f8699b21341a08624a8dce
uses: docker/build-push-action@2a53c6ccda456d31fb62eedc658aae06e238b7bd
with:
context: .
target: alpine-release
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ jobs:

# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@edfb0fe6204400c56fbfd3feba3fe9ad1adfa345
uses: docker/setup-buildx-action@5138f76647652447004da686b2411557eaf65f33

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into GH registry (ghcr.io)
if: github.event_name != 'pull_request'
uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb
uses: docker/login-action@70fccc794acd729b2b22dd6a326895f286447728
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log into Docker Hub registry
if: github.event_name != 'pull_request' && env.DOCKERHUB_USERNAME != ''
uses: docker/login-action@3d58c274f17dffee475a5520cbe67f0a882c4dbb
uses: docker/login-action@70fccc794acd729b2b22dd6a326895f286447728
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -72,7 +72,7 @@ jobs:
# 2nd image name is for DockerHub image
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c
uses: docker/metadata-action@f7b4ed12385588c3f9bc252f0a2b520d83b52d48
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
Expand All @@ -82,7 +82,7 @@ jobs:
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@9f6f8c940b91232557f8699b21341a08624a8dce
uses: docker/build-push-action@2a53c6ccda456d31fb62eedc658aae06e238b7bd
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
Expand All @@ -97,7 +97,7 @@ jobs:
# 2nd image name is for DockerHub image
- name: Extract Docker metadata - alpine
id: meta-alpine
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c
uses: docker/metadata-action@f7b4ed12385588c3f9bc252f0a2b520d83b52d48
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
Expand All @@ -107,7 +107,7 @@ jobs:
# https://github.com/docker/build-push-action
- name: Build and push Docker image - alpine
id: build-and-push-alpine
uses: docker/build-push-action@9f6f8c940b91232557f8699b21341a08624a8dce
uses: docker/build-push-action@2a53c6ccda456d31fb62eedc658aae06e238b7bd
with:
context: .
target: alpine-release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
go-version: 1.21
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.57.2
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

FROM golang:1.22.2 as test
FROM golang:1.22.3 as test
ARG GOPROXY
ENV GOPATH=/go
ENV PATH="$PATH:$GOPATH/bin"
Expand Down
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ require (
github.com/argoproj/argo-cd/v2 v2.11.0-rc1
github.com/argoproj/gitops-engine v0.7.1-0.20240411122334-1ade3a199867
github.com/bradleyfalzon/ghinstallation/v2 v2.10.0
github.com/cenkalti/backoff/v4 v4.2.1
github.com/go-test/deep v1.1.0
github.com/google/go-github/v52 v52.0.0
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v62 v62.0.0
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/hexops/gotextdiff v1.0.3
github.com/migueleliasweb/go-github-mock v0.0.22
github.com/mikefarah/yq/v4 v4.43.1
github.com/prometheus/client_golang v1.19.0
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3
github.com/shurcooL/githubv4 v0.0.0-20240120211514-18a1ae0e79dc
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8
golang.org/x/oauth2 v0.19.0
google.golang.org/grpc v1.63.2
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.26.11
k8s.io/apimachinery v0.26.11
)

Expand Down Expand Up @@ -81,7 +85,6 @@ require (
github.com/google/btree v1.1.2 // indirect
github.com/google/gnostic v0.7.0 // indirect
github.com/google/gnostic-models v0.6.9-0.20230804172637-c7be7c783f49 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-github/v56 v56.0.0 // indirect
github.com/google/go-github/v60 v60.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
Expand Down Expand Up @@ -134,6 +137,7 @@ require (
github.com/redis/go-redis/v9 v9.5.1 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/shurcooL/graphql v0.0.0-20230722043721-ed46e5a46466 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down Expand Up @@ -161,13 +165,11 @@ require (
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.26.11 // indirect
k8s.io/apiextensions-apiserver v0.26.10 // indirect
k8s.io/apiserver v0.26.11 // indirect
k8s.io/cli-runtime v0.26.11 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
Expand Down Expand Up @@ -922,12 +924,12 @@ github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v52 v52.0.0 h1:uyGWOY+jMQ8GVGSX8dkSwCzlehU3WfdxQ7GweO/JP7M=
github.com/google/go-github/v52 v52.0.0/go.mod h1:WJV6VEEUPuMo5pXqqa2ZCZEdbQqua4zAk2MZTIo+m+4=
github.com/google/go-github/v56 v56.0.0 h1:TysL7dMa/r7wsQi44BjqlwaHvwlFlqkK8CtBWCX3gb4=
github.com/google/go-github/v56 v56.0.0/go.mod h1:D8cdcX98YWJvi7TLo7zM4/h8ZTx6u6fwGEkCdisopo0=
github.com/google/go-github/v60 v60.0.0 h1:oLG98PsLauFvvu4D/YPxq374jhSxFYdzQGNCyONLfn8=
github.com/google/go-github/v60 v60.0.0/go.mod h1:ByhX2dP9XT9o/ll2yXAu2VD8l5eNVg8hD4Cr0S/LmQk=
github.com/google/go-github/v62 v62.0.0 h1:/6mGCaRywZz9MuHyw9gD1CwsbmBX8GWsbFkwMmHdhl4=
github.com/google/go-github/v62 v62.0.0/go.mod h1:EMxeUqGJq2xRu9DYBMwel/mr7kZrzUOfQmmpYrZn2a4=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down
39 changes: 15 additions & 24 deletions internal/pkg/githubapi/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package githubapi

import (
"context"
"fmt"
"net/http"
"os"
"strconv"
"time"

"github.com/bradleyfalzon/ghinstallation/v2"
"github.com/google/go-github/v52/github"
"github.com/google/go-github/v62/github"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/shurcooL/githubv4"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -41,25 +42,17 @@ func getAppInstallationId(githubAppPrivateKeyPath string, githubAppId int64, git
if err != nil {
panic(err)
}
var tempClient *github.Client
tempClient := github.NewClient(
&http.Client{
Transport: atr,
Timeout: time.Second * 30,
})

if githubRestAltURL != "" {
tempClient, err = github.NewEnterpriseClient(
githubRestAltURL,
githubRestAltURL,
&http.Client{
Transport: atr,
Timeout: time.Second * 30,
})
tempClient, err = tempClient.WithEnterpriseURLs(githubRestAltURL, githubRestAltURL)
if err != nil {
log.Fatalf("failed to create git client for app: %v\n", err)
}
} else {
tempClient = github.NewClient(
&http.Client{
Transport: atr,
Timeout: time.Second * 30,
})
}

installations, _, err := tempClient.Apps.ListInstallations(ctx, &github.ListOptions{})
Expand Down Expand Up @@ -88,7 +81,7 @@ func createGithubAppRestClient(githubAppPrivateKeyPath string, githubAppId int64

if githubRestAltURL != "" {
itr.BaseURL = githubRestAltURL
client, _ = github.NewEnterpriseClient(githubRestAltURL, githubRestAltURL, &http.Client{Transport: itr})
client, _ = github.NewClient(&http.Client{Transport: itr}).WithEnterpriseURLs(githubRestAltURL, githubRestAltURL)
} else {
client = github.NewClient(&http.Client{Transport: itr})
}
Expand All @@ -100,11 +93,9 @@ func createGithubRestClient(githubOauthToken string, githubRestAltURL string, ct
&oauth2.Token{AccessToken: githubOauthToken},
)
tc := oauth2.NewClient(ctx, ts)
var client *github.Client
client := github.NewClient(tc)
if githubRestAltURL != "" {
client, _ = github.NewEnterpriseClient(githubRestAltURL, githubRestAltURL, tc)
} else {
client = github.NewClient(tc)
client, _ = client.WithEnterpriseURLs(githubRestAltURL, githubRestAltURL)
}

return client
Expand Down Expand Up @@ -147,8 +138,8 @@ func createGhAppClientPair(ctx context.Context, githubAppId int64, owner string,
githubAppPrivateKeyPath := getCrucialEnv(ghAppPKeyPathEnvVarName)
githubHost := getEnv("GITHUB_HOST", "")
if githubHost != "" {
githubRestAltURL = "https://" + githubHost + "/api/v3"
githubGraphqlAltURL = "https://" + githubHost + "/api/graphql"
githubRestAltURL = fmt.Sprintf("https://%s/api/v3", githubHost)
githubGraphqlAltURL = fmt.Sprintf("https://%s/api/graphql", githubHost)
log.Infof("Github REST API endpoint is configured to %s", githubRestAltURL)
log.Infof("Github graphql API endpoint is configured to %s", githubGraphqlAltURL)
} else {
Expand All @@ -174,8 +165,8 @@ func createGhTokenClientPair(ctx context.Context, ghOauthToken string) GhClientP
var githubGraphqlAltURL string
githubHost := getEnv("GITHUB_HOST", "")
if githubHost != "" {
githubRestAltURL = "https://" + githubHost + "/api/v3"
githubGraphqlAltURL = "https://" + githubHost + "/api/graphql"
githubRestAltURL = fmt.Sprintf("https://%s/api/v3", githubHost)
githubGraphqlAltURL = fmt.Sprintf("https://%s/api/graphql", githubHost)
log.Infof("Github REST API endpoint is configured to %s", githubRestAltURL)
log.Infof("Github graphql API endpoint is configured to %s", githubGraphqlAltURL)
} else {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/githubapi/drift_detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

"github.com/google/go-github/v52/github"
"github.com/google/go-github/v62/github"
"github.com/hexops/gotextdiff"
"github.com/hexops/gotextdiff/myers"
"github.com/hexops/gotextdiff/span"
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/githubapi/drift_detection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"github.com/go-test/deep"
"github.com/google/go-github/v52/github"
"github.com/google/go-github/v62/github"
"github.com/hexops/gotextdiff"
"github.com/hexops/gotextdiff/myers"
"github.com/hexops/gotextdiff/span"
Expand Down
Loading

0 comments on commit 0fcbba5

Please sign in to comment.