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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user