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:
@@ -3,6 +3,7 @@ package gitea
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -113,9 +114,10 @@ func (gitea *Gitea) GetMilestone(repo Repository, id uint) (Milestone, error) {
|
||||
return milestone, nil
|
||||
}
|
||||
|
||||
// FIXME: how to do basic authorization?
|
||||
func (gitea *Gitea) UpdateMilestone(repo Repository, milestone Milestone) error {
|
||||
url := fmt.Sprintf("%s/repos/%s/milestones/%d", gitea.Url(), repo.Full_name, milestone.Id)
|
||||
var payload map[string]interface{}
|
||||
payload := make(map[string]interface{})
|
||||
payload["description"] = milestone.Description
|
||||
payload["due_on"] = milestone.Due_on
|
||||
payload["state"] = milestone.State
|
||||
@@ -124,10 +126,20 @@ func (gitea *Gitea) UpdateMilestone(repo Repository, milestone Milestone) 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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user