fix(gitea-api): authorize for issues in private repositories / organizations

This also fixes an issue with the taskwarrior filters to not overwrite
existing other tasks from other repositories.
This commit is contained in:
2023-10-27 16:42:33 +02:00
parent 489faae58b
commit aae91aa4e7
6 changed files with 48 additions and 28 deletions

View File

@@ -2,6 +2,7 @@ package gitea
import (
"encoding/json"
"errors"
"fmt"
"net/http"
)
@@ -22,11 +23,20 @@ func NewRepository(name, owner string) (repo Repository) {
func (gitea *Gitea) VerifyRepository(repository Repository) (Repository, error) {
url := fmt.Sprintf("%s/repos/%s", gitea.Url(), repository.Full_name)
response, err := http.Get(url)
client := &http.Client{}
request, err := http.NewRequest(http.MethodGet, url, nil)
request.SetBasicAuth(gitea.User_name, gitea.Access_code)
if err != nil {
return repository, err
}
response, err := client.Do(request)
if err != nil {
return repository, err
}
defer response.Body.Close()
if response.StatusCode != 200 {
return repository, errors.New(fmt.Sprintf("\tCould not verify repository with returned status: %s\n", response.Status))
}
var data map[string]interface{}
decoder := json.NewDecoder(response.Body)
if err = decoder.Decode(&data); err != nil {