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

Expose Auth.Username for other forges #42

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func Read(path string) (config types.Configuration, err error) {
}
config.Remotes[i].Auth.AccessToken = string(content)
}
// On GitLab and GitHub, any non blank username is working
if remote.Auth.Username == "" {
config.Remotes[i].Auth.Username = "comin"
}
if remote.Timeout == 0 {
config.Remotes[i].Timeout = 300
}
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestConfig(t *testing.T) {
Auth: types.Auth{
AccessToken: "my-secret",
AccessTokenPath: "./secret",
Username: "comin",
},
Timeout: 300,
},
Expand All @@ -28,6 +29,7 @@ func TestConfig(t *testing.T) {
Auth: types.Auth{
AccessToken: "",
AccessTokenPath: "",
Username: "comin",
},
Timeout: 300,
},
Expand Down
4 changes: 1 addition & 3 deletions internal/repository/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ func fetch(r repository, remote types.Remote) (err error) {
// TODO: support several authentication methods
if remote.Auth.AccessToken != "" {
fetchOptions.Auth = &http.BasicAuth{
// On GitLab, any non blank username is
// working.
Username: "comin",
Username: remote.Auth.Username,
Password: remote.Auth.AccessToken,
}
}
Expand Down
1 change: 1 addition & 0 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type GitConfig struct {
type Auth struct {
AccessToken string
AccessTokenPath string `yaml:"access_token_path"`
Username string
}

type Branch struct {
Expand Down
9 changes: 9 additions & 0 deletions nix/module-options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@
The path of the auth file.
'';
};
username = mkOption {
type = str;
default = "comin";
description = ''
The username used to authenticate to the Git
remote repository. Note that any non empty
username is valid on GitLab and GitHub.
'';
};
};
};
};
Expand Down
Loading