add(gitea-api): creation for issues, milestones and comments
This implements the post api functions for issues, milestones and comments which are added to the gitea repository.
This commit is contained in:
@@ -72,3 +72,29 @@ func (gitea *Gitea) UpdateMilestone(repo Repository, milestone Milestone) error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gitea *Gitea) NewMilestone(repo Repository, milestone Milestone) (Milestone, error) {
|
||||
url := fmt.Sprintf("%s/repos/%s/milestones", gitea.Url(), repo.Full_name)
|
||||
payload, err := json.Marshal(&map[string]interface{}{
|
||||
"description": milestone.Description,
|
||||
"due_on": milestone.Due_on,
|
||||
"state": milestone.State,
|
||||
"title": milestone.Title,
|
||||
})
|
||||
var res Milestone
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
response, err := http.Post(url, "application/json", bytes.NewBuffer(payload))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
decoder := json.NewDecoder(response.Body)
|
||||
// NOTE: remove this if I do not want to stare everything from the json result in the struct
|
||||
decoder.DisallowUnknownFields() // remain if every field shall be extracted
|
||||
if err = decoder.Decode(&res); err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user