Skip to content

Commit

Permalink
fix: use global git config because of go mod tidy limitation
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlJi committed Dec 2, 2024
1 parent e89f1c7 commit 2b9c618
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions deploy/reviewbot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions internal/linters/go/golangci_lint/golangci_lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/linters/providergithub.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,9 +692,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", config.GitHub, key, exp.Format(time.RFC3339))
return token, nil
}

Expand Down

0 comments on commit 2b9c618

Please sign in to comment.