This implements the api getters for extracting the issues and milestones for a given gitea repository. WIP for #1.
39 lines
905 B
Go
39 lines
905 B
Go
package gitea
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type Milestone struct {
|
|
Id uint
|
|
Title string
|
|
Description string
|
|
State string
|
|
Open_issues uint
|
|
Closed_issues uint
|
|
Created_at time.Time
|
|
Updated_at time.Time
|
|
Due_on time.Time
|
|
Closed_at time.Time
|
|
}
|
|
|
|
func (gitea *Gitea) GetMilestones(repo Repository) ([]Milestone, error) {
|
|
url := fmt.Sprintf("%s/repos/%s/milestones?state=all", gitea.Url(), repo.Full_name)
|
|
response, err := http.Get(url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer response.Body.Close()
|
|
var data []Milestone
|
|
decoder := json.NewDecoder(response.Body)
|
|
// NOTE: remove this if I do not want to store everything from the json result in the struct
|
|
decoder.DisallowUnknownFields() // remain if every field shall be extracted
|
|
if err = decoder.Decode(&data); err != nil {
|
|
return nil, err
|
|
}
|
|
return data, nil
|
|
}
|