This repository has been archived on 2025-10-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
gitwarrior/internal/gitea/repository.go
Yves Biener 3a04085d3a add(repository): discover repository informations
This implemtation determines the git remote origin url and extracts the
information for the owner and repo names for the api url's. WIP for #2.
2023-10-19 22:29:29 +02:00

40 lines
929 B
Go

package gitea
import (
"encoding/json"
"fmt"
"net/http"
)
type Repository struct {
Id uint
Name string
Owner string
Full_name string
}
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)
response, err := http.Get(url)
if err != nil {
return repository, err
}
defer response.Body.Close()
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
}