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:
2023-10-18 22:49:25 +02:00
parent 5ab0dd6da6
commit 0e6efacd13
3 changed files with 80 additions and 0 deletions

View File

@@ -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
}