feat: Allow reading an access token
This commit is contained in:
@@ -38,6 +38,8 @@ type Repository struct {
|
||||
}
|
||||
|
||||
type GiteaClient struct {
|
||||
Token string
|
||||
|
||||
GetRepository GetRepositoryMethod
|
||||
HasBranch HasBranchMethod
|
||||
HasUser HasUserMethod
|
||||
@@ -46,8 +48,9 @@ type GiteaClient struct {
|
||||
LookupRepoTXT LookupRepoTXTMethod
|
||||
}
|
||||
|
||||
func NewGiteaClient(giteaUrl string, giteaClient *gitea.Client) GiteaClient {
|
||||
func NewGiteaClient(giteaUrl string, token string, giteaClient *gitea.Client) GiteaClient {
|
||||
return GiteaClient{
|
||||
Token: token,
|
||||
GetRepository: func(username, repositoryName string) (Repository, error) {
|
||||
repo, _, err := giteaClient.GetRepo(username, repositoryName)
|
||||
if err != nil {
|
||||
@@ -91,6 +94,11 @@ func NewGiteaClient(giteaUrl string, giteaClient *gitea.Client) GiteaClient {
|
||||
if since != nil {
|
||||
sinceFormat := since.Format(time.RFC1123)
|
||||
req.Header.Add("If-Modified-Since", sinceFormat)
|
||||
|
||||
// Add authentication, if we have a token
|
||||
if token != "" {
|
||||
req.Header.Add("Authorization", "token "+token)
|
||||
}
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user