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

@@ -70,3 +70,26 @@ func (gitea *Gitea) UpdateComment(repo Repository, comment Comment) error {
}
return nil
}
func (gitea *Gitea) NewComment(repo Repository, issue Issue, comment Comment) (Comment, error) {
url := fmt.Sprintf("%s/repos/%s/issues/%d/comments", gitea.Url(), repo.Full_name, issue.Id)
payload, err := json.Marshal(&map[string]interface{}{
"body": comment.Body,
})
var res Comment
if err != nil {
return res, err
}
response, err := http.Post(url, "application/json", bytes.NewBuffer(payload))
if err != nil {
return res, nil
}
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(&res); err != nil {
return res, err
}
return res, nil
}