Skip to content

Commit

Permalink
Expose Auth.Username for other forges
Browse files Browse the repository at this point in the history
Fixes #38
  • Loading branch information
nlewo committed May 5, 2024
1 parent d3658c4 commit 5efc0fd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
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

0 comments on commit 5efc0fd

Please sign in to comment.