Skip to content

Commit 8dc473a

Browse files
author
Scott Schulthess
committed
disable access token when using github app
remove logger
1 parent a76e2d3 commit 8dc473a

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

git.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ func NewGitClient(source *Source, dir string, output io.Writer) (*GitClient, err
3636
os.Setenv("GIT_LFS_SKIP_SMUDGE", "true")
3737
}
3838
return &GitClient{
39-
AccessToken: source.AccessToken,
40-
PrivateKey: source.PrivateKey,
41-
UseGithubApp: source.UseGitHubApp,
42-
ApplicationID: source.ApplicationID,
39+
AccessToken: source.AccessToken,
40+
PrivateKey: source.PrivateKey,
41+
UseGithubApp: source.UseGitHubApp,
42+
ApplicationID: source.ApplicationID,
4343
GithubOrganziation: source.GithubOrganziation,
44-
Directory: dir,
45-
Output: output,
44+
Directory: dir,
45+
Output: output,
4646
}, nil
4747
}
4848

@@ -63,8 +63,12 @@ func (g *GitClient) command(name string, arg ...string) *exec.Cmd {
6363
cmd.Stdout = g.Output
6464
cmd.Stderr = g.Output
6565
cmd.Env = os.Environ()
66+
if !g.UseGithubApp {
67+
cmd.Env = append(cmd.Env,
68+
"X_OAUTH_BASIC_TOKEN="+g.AccessToken)
69+
}
70+
6671
cmd.Env = append(cmd.Env,
67-
"X_OAUTH_BASIC_TOKEN="+g.AccessToken,
6872
"GIT_ASKPASS=/usr/local/bin/askpass.sh")
6973
fmt.Fprint(os.Stderr, fmt.Sprintf("\n%s %v", name, arg))
7074

@@ -95,7 +99,6 @@ func (g *GitClient) Init(branch string) error {
9599
}
96100

97101
helperStr := fmt.Sprintf("!git-credential-github-app --appId %d -organization %s -username x-access-token -privateKeyFile /tmp/git-resource-private-key", g.ApplicationID, g.GithubOrganziation)
98-
fmt.Fprint(os.Stderr, "\nsds helperStr", helperStr)
99102
if err := g.command("git", "config", "credential.https://github.com.helper", helperStr).Run(); err != nil {
100103
return fmt.Errorf("failed to configure github url: %s", err)
101104
}
@@ -254,6 +257,9 @@ func (g *GitClient) Endpoint(uri string) (string, error) {
254257
if err != nil {
255258
return "", fmt.Errorf("failed to parse commit url: %s", err)
256259
}
257-
//endpoint.User = url.UserPassword("x-oauth-basic", g.AccessToken)
260+
if !g.UseGithubApp {
261+
endpoint.User = url.UserPassword("x-oauth-basic", g.AccessToken)
262+
}
263+
258264
return endpoint.String(), nil
259265
}

0 commit comments

Comments
 (0)