This also fixes an issue with the taskwarrior filters to not overwrite existing other tasks from other repositories.
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package gitea
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type Repository struct {
|
|
Id uint `json:"id"`
|
|
Name string `json:"name"`
|
|
Owner string `json:"owner"`
|
|
Full_name string `json:"full_name"`
|
|
}
|
|
|
|
func NewRepository(name, owner string) (repo Repository) {
|
|
repo.Name = name
|
|
repo.Owner = owner
|
|
repo.Full_name = fmt.Sprintf("%s/%s", owner, name)
|
|
return
|
|
}
|
|
|
|
func (gitea *Gitea) VerifyRepository(repository Repository) (Repository, error) {
|
|
url := fmt.Sprintf("%s/repos/%s", gitea.Url(), repository.Full_name)
|
|
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 {
|
|
return repository, err
|
|
}
|
|
// extract the id value to the current repository
|
|
// NOTE: there may be other informations we also want to capture here as well
|
|
repository.Id = uint(data["id"].(float64))
|
|
return repository, nil
|
|
}
|