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

40 lines
991 B
Go

package gitea
import (
"encoding/json"
"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)
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
}