From 2a8d0491ad29e7978e567f57dde1c047017381ba Mon Sep 17 00:00:00 2001 From: jichangjun Date: Mon, 2 Dec 2024 19:08:53 +0800 Subject: [PATCH] fix: use global git config because of go mod tidy limitation --- Dockerfile | 8 +------- deploy/reviewbot.yaml | 4 ++-- internal/linters/go/golangci_lint/golangci_lint.go | 7 +++++-- internal/linters/providergithub.go | 5 ++--- internal/linters/providergitlab.go | 3 +-- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index a9ed4027..ac1a1b93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,16 +52,10 @@ RUN curl -fsSL -o kubectl https://dl.k8s.io/release/v1.28.3/bin/linux/amd64/kube && mv kubectl /usr/local/bin/ # SSH config -RUN mkdir -p /root/.ssh && chown -R root /root/.ssh/ && chgrp -R root /root/.ssh/ \ - && git config --global url."git@github.com:".insteadOf https://github.com/ \ - && git config --global url."git://".insteadOf https:// +RUN mkdir -p /root/.ssh && chown -R root /root/.ssh/ && chgrp -R root /root/.ssh/ COPY deploy/config /root/.ssh/config COPY deploy/github-known-hosts /github_known_hosts -# set go proxy and private repo -RUN go env -w GOPROXY=https://goproxy.cn,direct \ - && go env -w GOPRIVATE=github.com/qbox,qiniu.com - EXPOSE 8888 ENTRYPOINT [ "/reviewbot" ] \ No newline at end of file diff --git a/deploy/reviewbot.yaml b/deploy/reviewbot.yaml index f1952fe8..3bf55254 100644 --- a/deploy/reviewbot.yaml +++ b/deploy/reviewbot.yaml @@ -24,8 +24,8 @@ spec: - -log-level=0 - -webhook-secret=$(GITHUB_WEBHOOK_SECRET) - -config=/etc/config/config.yaml - - -app-id=$(GITHUB_APP_ID) - - -app-private-key=/secrets/github_app_key + - -github.app-id=$(GITHUB_APP_ID) + - -github.app-private-key=/secrets/github_app_key - -debug=true - -s3-credentials-file=/root/.aws/credentials.json - -server-addr=http://qiniu-x.jfcs-k8s-qa1.qiniu.io # this is an intranet domain of qiniu. diff --git a/internal/linters/go/golangci_lint/golangci_lint.go b/internal/linters/go/golangci_lint/golangci_lint.go index 2a9113ab..fd8060be 100644 --- a/internal/linters/go/golangci_lint/golangci_lint.go +++ b/internal/linters/go/golangci_lint/golangci_lint.go @@ -103,8 +103,11 @@ func (g *gitConfigModifier) Modify(cfg *config.Linter) (*config.Linter, error) { } newCfg := base - args := []string{fmt.Sprintf("git config --local \"url.https://%s:${ACCESS_TOKEN}@%s/.insteadOf\" \"git@%s:\" \n", gitUsername, info.Host, info.Host)} - args = append(args, fmt.Sprintf("git config --local \"url.https://%s:${ACCESS_TOKEN}@%s/.insteadOf\" \"https://%s/\" \n", gitUsername, info.Host, info.Host)) + + // must use global git config, otherwise it will be ignored by go mod tidy. + // see https://github.com/golang/go/issues/65041 + args := []string{fmt.Sprintf("git config --global \"url.https://%s:${ACCESS_TOKEN}@%s/.insteadOf\" \"git@%s:\" \n", gitUsername, info.Host, info.Host)} + args = append(args, fmt.Sprintf("git config --global \"url.https://%s:${ACCESS_TOKEN}@%s/.insteadOf\" \"https://%s/\" \n", gitUsername, info.Host, info.Host)) newCfg.Args = append(args, base.Args...) // set ACCESS_TOKEN in the environment variables diff --git a/internal/linters/providergithub.go b/internal/linters/providergithub.go index c0225967..a9173638 100644 --- a/internal/linters/providergithub.go +++ b/internal/linters/providergithub.go @@ -679,7 +679,6 @@ func (g *GithubProvider) ProcessComments(ctx context.Context, a Agent, lintResul func (g *GithubProvider) GetToken() (string, error) { // with platform and org for uniqueness key := fmt.Sprintf("%s:%s", config.GitHub, g.PullRequestEvent.Repo.GetOwner().GetLogin()) - log.Infof("get token for %s, key: %s", config.GitHub, key) token, ok := cache.DefaultTokenCache.GetToken(key) if ok { return token, nil @@ -692,9 +691,9 @@ func (g *GithubProvider) GetToken() (string, error) { // set the token with a little less than 1 hour expiration since github app token will expire in 1 hours // see https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation#about-installation-access-tokens - exp := time.Now().Add(time.Hour*1 - time.Minute) + exp := time.Now().Add(time.Hour - time.Minute*5) cache.DefaultTokenCache.SetToken(key, token, exp) - + log.Infof("set refreshed token for %s, key: %s, exp: %s", token, key, exp.Format(time.RFC3339)) return token, nil } diff --git a/internal/linters/providergitlab.go b/internal/linters/providergitlab.go index 894a7ced..cf4bc3e5 100644 --- a/internal/linters/providergitlab.go +++ b/internal/linters/providergitlab.go @@ -182,7 +182,6 @@ func (g *GitlabProvider) GetCodeReviewInfo() CodeReview { func (g *GitlabProvider) GetToken() (string, error) { // with platform and org for uniqueness key := fmt.Sprintf("%s:%s", config.GitLab, g.MergeRequestEvent.Project.Namespace) - log.Infof("get token for %s", key) token, ok := cache.DefaultTokenCache.GetToken(key) if ok { return token, nil @@ -196,7 +195,7 @@ func (g *GitlabProvider) GetToken() (string, error) { // set the token with a little less than 6 hour expiration exp := time.Now().Add(time.Hour*6 - time.Minute) cache.DefaultTokenCache.SetToken(key, token, exp) - + log.Infof("set refreshed token for %s, key: %s, exp: %s", token, key, exp.Format(time.RFC3339)) return token, nil }