mod(taskwarrior): complete push implementation
Currently the merging process is not working entirely as I would expect. There are no checks for actual changes between the local version and the server version. WIP for #3. Configuration file created with corresponding values like, user name and access code, which are - for obvious reasons - not commited.
This commit is contained in:
@@ -35,7 +35,7 @@ func (milestone *Milestone) IntoTask(repository Repository) (task taskwarrior.Ta
|
||||
task.Due = taskwarrior.GoTimeToTaskTime(milestone.Due_on)
|
||||
task.Entry = taskwarrior.GoTimeToTaskTime(milestone.Created_at)
|
||||
task.Modified = taskwarrior.GoTimeToTaskTime(milestone.Updated_at)
|
||||
task.AppendComment(milestone.Description, milestone.Updated_at)
|
||||
task.AppendComment(0, milestone.Description, milestone.Updated_at)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func (milestone *Milestone) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
||||
}
|
||||
}
|
||||
if len(task.Annotations) < 1 {
|
||||
task.AppendComment(milestone.Description, milestone.Created_at)
|
||||
task.AppendComment(0, milestone.Description, milestone.Created_at)
|
||||
} else {
|
||||
task.Annotations[0].Description = diff.Prompt(task.Annotations[0].Description, milestone.Description, task.Annotations[0].Description)
|
||||
task.Annotations[0].Entry = taskwarrior.GoTimeToTaskTime(time.Now().In(time.Local))
|
||||
@@ -63,7 +63,7 @@ func (milestone *Milestone) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
||||
} else {
|
||||
// NOTE: there are no modifications between the last received update and the current version, hence we just accept theirs fully
|
||||
task.Description = milestone.Title
|
||||
if milestone.State == "closed" {
|
||||
if milestone.State == string(CLOSED) {
|
||||
// otherwise do not update the value
|
||||
task.Status = "completed"
|
||||
task.End = taskwarrior.GoTimeToTaskTime(milestone.Closed_at)
|
||||
@@ -72,7 +72,7 @@ func (milestone *Milestone) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
||||
task.Annotations[0].Description = milestone.Description
|
||||
task.Annotations[0].Entry = taskwarrior.GoTimeToTaskTime(milestone.Updated_at)
|
||||
} else {
|
||||
task.AppendComment(milestone.Description, milestone.Updated_at)
|
||||
task.AppendComment(0, milestone.Description, milestone.Updated_at)
|
||||
}
|
||||
}
|
||||
task.Last_gitw_update = taskwarrior.GoTimeToTaskTime(time.Now().In(time.Local))
|
||||
@@ -114,7 +114,6 @@ 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)
|
||||
payload := make(map[string]interface{})
|
||||
@@ -128,6 +127,7 @@ func (gitea *Gitea) UpdateMilestone(repo Repository, milestone Milestone) error
|
||||
}
|
||||
client := &http.Client{}
|
||||
request, err := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(json))
|
||||
request.SetBasicAuth(gitea.User_name, gitea.Access_code)
|
||||
request.Header.Set("content-type", "application/json")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -137,7 +137,7 @@ func (gitea *Gitea) UpdateMilestone(repo Repository, milestone Milestone) error
|
||||
return err
|
||||
}
|
||||
defer result.Body.Close()
|
||||
if result.StatusCode != 201 {
|
||||
if result.StatusCode != 200 {
|
||||
return errors.New(fmt.Sprintf("\tRequest returned status: %s\n", result.Status))
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user