Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use global git config because of go mod tidy limitation #473

Merged
merged 1 commit into from
Dec 3, 2024
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
8 changes: 1 addition & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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."[email protected]:".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" ]
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
5 changes: 2 additions & 3 deletions internal/linters/providergithub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions internal/linters/providergitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
Loading