This implements the api getters for extracting a single issue and single milestone for a given gitea repository and id. WIP for #1.
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package gitea
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type PullRequest struct {
|
|
Merged bool
|
|
Merged_at time.Time
|
|
}
|
|
|
|
type Issue struct {
|
|
Id uint
|
|
Url string
|
|
Html_url string
|
|
Number uint
|
|
User User
|
|
Original_author string
|
|
Original_author_id uint
|
|
Title string
|
|
Body string
|
|
Ref string
|
|
Assets []string
|
|
Labels []string
|
|
Milestone Milestone
|
|
Assignee User
|
|
Assignees []User
|
|
State string
|
|
Is_locked bool
|
|
Comments uint
|
|
Created_at time.Time
|
|
Updated_at time.Time
|
|
Closed_at time.Time
|
|
Due_date time.Time
|
|
Pull_request PullRequest
|
|
Repository Repository
|
|
Pin_order uint
|
|
}
|
|
|
|
func (gitea *Gitea) GetIssues(repo Repository) ([]Issue, error) {
|
|
url := fmt.Sprintf("%s/repos/%s/issues?state=all", gitea.Url(), repo.Full_name)
|
|
response, err := http.Get(url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer response.Body.Close()
|
|
var data []Issue
|
|
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
|
|
}
|
|
|
|
func (gitea *Gitea) GetIssue(repo Repository, id uint) (Issue, error) {
|
|
var issue Issue
|
|
url := fmt.Sprintf("%s/repos/%s/issues/%d", gitea.Url(), repo.Full_name, id)
|
|
response, err := http.Get(url)
|
|
if err != nil {
|
|
return issue, err
|
|
}
|
|
defer response.Body.Close()
|
|
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(&issue); err != nil {
|
|
return issue, err
|
|
}
|
|
return issue, nil
|
|
}
|