add: push changes to gitea server after merging local changes

This implementation has no configuration yet to authorize accordingly.
WIP for #3 and #4.
This commit is contained in:
2023-10-24 22:17:37 +02:00
parent d2aeb7ffe4
commit 0cb4190540
6 changed files with 217 additions and 43 deletions

View File

@@ -3,6 +3,7 @@ package gitea
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"strings"
@@ -61,6 +62,7 @@ func (gitea *Gitea) GetComment(repo Repository, id uint) (Comment, error) {
return comment, err
}
// FIXME: how to do basic authorization?
func (gitea *Gitea) UpdateComment(repo Repository, comment Comment) error {
url := fmt.Sprintf("%s/repos/%s/issues/comments/%d", gitea.Url(), repo.Full_name, comment.Id)
json, err := json.Marshal(&map[string]interface{}{
@@ -69,10 +71,20 @@ func (gitea *Gitea) UpdateComment(repo Repository, comment Comment) error {
if err != nil {
return err
}
_, err = http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(json))
client := &http.Client{}
request, err := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(json))
request.Header.Set("content-type", "application/json")
if err != nil {
return err
}
result, err := client.Do(request)
if err != nil {
return err
}
defer result.Body.Close()
if result.StatusCode != 201 {
return errors.New(fmt.Sprintf("\tRequest returned status: %s\n", result.Status))
}
return nil
}