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:
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// TODO: server url may be also be derived from the git configuration?
|
// TODO: server url may be also be derived from the git configuration?
|
||||||
server := gitea.NewGitea("https://gitea.yves-biener.de")
|
server := gitea.NewGitea()
|
||||||
repository, err := gitw.Discover()
|
repository, err := gitw.Discover()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ func (gitea *Gitea) GetComment(repo Repository, id uint) (Comment, error) {
|
|||||||
return comment, err
|
return comment, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: how to do basic authorization?
|
|
||||||
func (gitea *Gitea) UpdateComment(repo Repository, comment Comment) error {
|
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)
|
url := fmt.Sprintf("%s/repos/%s/issues/comments/%d", gitea.Url(), repo.Full_name, comment.Id)
|
||||||
json, err := json.Marshal(&map[string]interface{}{
|
json, err := json.Marshal(&map[string]interface{}{
|
||||||
@@ -73,6 +72,7 @@ func (gitea *Gitea) UpdateComment(repo Repository, comment Comment) error {
|
|||||||
}
|
}
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
request, err := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(json))
|
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")
|
request.Header.Set("content-type", "application/json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -82,14 +82,14 @@ func (gitea *Gitea) UpdateComment(repo Repository, comment Comment) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer result.Body.Close()
|
defer result.Body.Close()
|
||||||
if result.StatusCode != 201 {
|
if result.StatusCode != 200 && result.StatusCode != 204 {
|
||||||
return errors.New(fmt.Sprintf("\tRequest returned status: %s\n", result.Status))
|
return errors.New(fmt.Sprintf("\tRequest returned status: %s\n", result.Status))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gitea *Gitea) NewComment(repo Repository, issue Issue, comment Comment) (Comment, error) {
|
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)
|
url := fmt.Sprintf("%s/repos/%s/issues/%d/comments", gitea.Url(), repo.Full_name, issue.Number)
|
||||||
payload, err := json.Marshal(&map[string]interface{}{
|
payload, err := json.Marshal(&map[string]interface{}{
|
||||||
"body": comment.Body,
|
"body": comment.Body,
|
||||||
})
|
})
|
||||||
@@ -97,12 +97,22 @@ func (gitea *Gitea) NewComment(repo Repository, issue Issue, comment Comment) (C
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
response, err := http.Post(url, "application/json", bytes.NewBuffer(payload))
|
client := &http.Client{}
|
||||||
|
request, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payload))
|
||||||
|
request.SetBasicAuth(gitea.User_name, gitea.Access_code)
|
||||||
|
request.Header.Set("content-type", "application/json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
result, err := client.Do(request)
|
||||||
decoder := json.NewDecoder(response.Body)
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
defer result.Body.Close()
|
||||||
|
if result.StatusCode != 201 {
|
||||||
|
return res, errors.New(fmt.Sprintf("\tRequest returned status: %s\n", result.Status))
|
||||||
|
}
|
||||||
|
decoder := json.NewDecoder(result.Body)
|
||||||
// NOTE: remove this if I do not want to store everything from the json result in the struct
|
// 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
|
decoder.DisallowUnknownFields() // remain if every field shall be extracted
|
||||||
if err = decoder.Decode(&res); err != nil {
|
if err = decoder.Decode(&res); err != nil {
|
||||||
@@ -110,3 +120,23 @@ func (gitea *Gitea) NewComment(repo Repository, issue Issue, comment Comment) (C
|
|||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gitea *Gitea) DeleteComment(repo Repository, comment_id uint) error {
|
||||||
|
url := fmt.Sprintf("%s/repos/%s/issues/comments/%d", gitea.Url(), repo.Full_name, comment_id)
|
||||||
|
client := &http.Client{}
|
||||||
|
request, err := http.NewRequest(http.MethodDelete, url, nil)
|
||||||
|
request.SetBasicAuth(gitea.User_name, gitea.Access_code)
|
||||||
|
request.Header.Set("content-type", "application/json")
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
result, err := client.Do(request)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer result.Body.Close()
|
||||||
|
if result.StatusCode != 204 {
|
||||||
|
return errors.New(fmt.Sprintf("\tRequest returned status: %s\n", result.Status))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,16 +1,33 @@
|
|||||||
package gitea
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
var API_PATH = "/api/v1"
|
var API_PATH = "/api/v1"
|
||||||
|
|
||||||
type Gitea struct {
|
type Gitea struct {
|
||||||
base_url string
|
Base_url string `json:"base_url"`
|
||||||
|
User_name string `json:"user_name"`
|
||||||
|
Access_code string `json:"access_code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGitea(base_url string) (gitea Gitea) {
|
func NewGitea() (gitea Gitea) {
|
||||||
gitea.base_url = base_url
|
configJson, err := os.ReadFile("./configs/gitw.json")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(configJson, &gitea)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gitea *Gitea) Url() string {
|
func (gitea *Gitea) Url() string {
|
||||||
return gitea.base_url + API_PATH
|
return gitea.Base_url + API_PATH
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,9 +81,8 @@ func (gitea *Gitea) GetIssue(repo Repository, id uint) (Issue, error) {
|
|||||||
return issue, nil
|
return issue, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: how to do basic authorization?
|
|
||||||
func (gitea *Gitea) UpdateIssue(repo Repository, issue Issue) error {
|
func (gitea *Gitea) UpdateIssue(repo Repository, issue Issue) error {
|
||||||
url := fmt.Sprintf("%s/repos/%s/issues/%d", gitea.Url(), repo.Full_name, issue.Id)
|
url := fmt.Sprintf("%s/repos/%s/issues/%d", gitea.Url(), repo.Full_name, issue.Number)
|
||||||
payload := make(map[string]interface{})
|
payload := make(map[string]interface{})
|
||||||
// payload["assignee"] = issue.Assignee
|
// payload["assignee"] = issue.Assignee
|
||||||
// payload["assignees"] = issue.Assignees
|
// payload["assignees"] = issue.Assignees
|
||||||
@@ -100,6 +99,7 @@ func (gitea *Gitea) UpdateIssue(repo Repository, issue Issue) error {
|
|||||||
}
|
}
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
request, err := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(json))
|
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")
|
request.Header.Set("content-type", "application/json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func (milestone *Milestone) IntoTask(repository Repository) (task taskwarrior.Ta
|
|||||||
task.Due = taskwarrior.GoTimeToTaskTime(milestone.Due_on)
|
task.Due = taskwarrior.GoTimeToTaskTime(milestone.Due_on)
|
||||||
task.Entry = taskwarrior.GoTimeToTaskTime(milestone.Created_at)
|
task.Entry = taskwarrior.GoTimeToTaskTime(milestone.Created_at)
|
||||||
task.Modified = taskwarrior.GoTimeToTaskTime(milestone.Updated_at)
|
task.Modified = taskwarrior.GoTimeToTaskTime(milestone.Updated_at)
|
||||||
task.AppendComment(milestone.Description, milestone.Updated_at)
|
task.AppendComment(0, milestone.Description, milestone.Updated_at)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ func (milestone *Milestone) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(task.Annotations) < 1 {
|
if len(task.Annotations) < 1 {
|
||||||
task.AppendComment(milestone.Description, milestone.Created_at)
|
task.AppendComment(0, milestone.Description, milestone.Created_at)
|
||||||
} else {
|
} else {
|
||||||
task.Annotations[0].Description = diff.Prompt(task.Annotations[0].Description, milestone.Description, task.Annotations[0].Description)
|
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))
|
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 {
|
} else {
|
||||||
// NOTE: there are no modifications between the last received update and the current version, hence we just accept theirs fully
|
// NOTE: there are no modifications between the last received update and the current version, hence we just accept theirs fully
|
||||||
task.Description = milestone.Title
|
task.Description = milestone.Title
|
||||||
if milestone.State == "closed" {
|
if milestone.State == string(CLOSED) {
|
||||||
// otherwise do not update the value
|
// otherwise do not update the value
|
||||||
task.Status = "completed"
|
task.Status = "completed"
|
||||||
task.End = taskwarrior.GoTimeToTaskTime(milestone.Closed_at)
|
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].Description = milestone.Description
|
||||||
task.Annotations[0].Entry = taskwarrior.GoTimeToTaskTime(milestone.Updated_at)
|
task.Annotations[0].Entry = taskwarrior.GoTimeToTaskTime(milestone.Updated_at)
|
||||||
} else {
|
} 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))
|
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
|
return milestone, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: how to do basic authorization?
|
|
||||||
func (gitea *Gitea) UpdateMilestone(repo Repository, milestone Milestone) error {
|
func (gitea *Gitea) UpdateMilestone(repo Repository, milestone Milestone) error {
|
||||||
url := fmt.Sprintf("%s/repos/%s/milestones/%d", gitea.Url(), repo.Full_name, milestone.Id)
|
url := fmt.Sprintf("%s/repos/%s/milestones/%d", gitea.Url(), repo.Full_name, milestone.Id)
|
||||||
payload := make(map[string]interface{})
|
payload := make(map[string]interface{})
|
||||||
@@ -128,6 +127,7 @@ func (gitea *Gitea) UpdateMilestone(repo Repository, milestone Milestone) error
|
|||||||
}
|
}
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
request, err := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(json))
|
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")
|
request.Header.Set("content-type", "application/json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -137,7 +137,7 @@ func (gitea *Gitea) UpdateMilestone(repo Repository, milestone Milestone) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer result.Body.Close()
|
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 errors.New(fmt.Sprintf("\tRequest returned status: %s\n", result.Status))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package gitw
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -76,10 +77,10 @@ func (project *Project) Push() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, task := range tasks {
|
for x, task := range tasks {
|
||||||
if task.Git_type == string(taskwarrior.ISSUE) {
|
if task.Git_type == string(taskwarrior.ISSUE) {
|
||||||
var issue gitea.Issue
|
var issue gitea.Issue
|
||||||
issue.Id = uint(task.Git_id)
|
issue.Number = uint(task.Git_number)
|
||||||
issue.Title = task.Description
|
issue.Title = task.Description
|
||||||
issue.Body = task.Annotations[0].Description
|
issue.Body = task.Annotations[0].Description
|
||||||
if len(task.Due) > 0 {
|
if len(task.Due) > 0 {
|
||||||
@@ -98,7 +99,7 @@ func (project *Project) Push() error {
|
|||||||
for _, milestone := range milestones {
|
for _, milestone := range milestones {
|
||||||
for _, dep := range milestone.Depends {
|
for _, dep := range milestone.Depends {
|
||||||
if task.Uuid == dep {
|
if task.Uuid == dep {
|
||||||
issue.Milestone.Id = uint(milestone.Git_id)
|
issue.Milestone.Id = uint(milestone.Git_number)
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -117,7 +118,7 @@ func (project *Project) Push() error {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var milestone gitea.Milestone
|
var milestone gitea.Milestone
|
||||||
milestone.Id = uint(task.Git_id)
|
milestone.Id = uint(task.Git_number)
|
||||||
milestone.Title = task.Description
|
milestone.Title = task.Description
|
||||||
milestone.Description = task.Annotations[0].Description
|
milestone.Description = task.Annotations[0].Description
|
||||||
milestone.Due_on = taskwarrior.TaskTimeToGoTime(task.Due)
|
milestone.Due_on = taskwarrior.TaskTimeToGoTime(task.Due)
|
||||||
@@ -130,19 +131,73 @@ func (project *Project) Push() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
comment_ids := strings.Split(task.Git_comment_ids, ",")
|
||||||
for i, annotation := range task.Annotations {
|
for i, annotation := range task.Annotations {
|
||||||
if i == 0 { // that the body of the issue / milestone
|
if i == 0 { // that the body of the issue / milestone
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var comment gitea.Comment
|
var comment gitea.Comment
|
||||||
comment.Id = uint(task.Git_id)
|
comment_id, err := strconv.Atoi(comment_ids[i])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if comment_id == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if comment_id < 0 {
|
||||||
|
// create new comment
|
||||||
|
var issue gitea.Issue
|
||||||
|
found_issue := false
|
||||||
|
for _, git_issue := range project.issues {
|
||||||
|
if git_issue.git_issue.Number == uint(task.Git_number) {
|
||||||
|
issue = git_issue.git_issue
|
||||||
|
found_issue = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found_issue {
|
||||||
|
return errors.New("Could not find corresponding issue for annotation to create new comment on gitea.")
|
||||||
|
}
|
||||||
|
comment.Body = annotation.Description
|
||||||
|
comment.Created_at = taskwarrior.TaskTimeToGoTime(annotation.Entry)
|
||||||
|
fmt.Printf("\tAdd comment to '%s'#'%d'\n", issue.Title, issue.Number)
|
||||||
|
if comment, err = project.server.NewComment(project.repository, issue, comment); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// update the corresponding id from -1 to the one assigned by git
|
||||||
|
comment_ids[i] = fmt.Sprintf("%d", comment.Id)
|
||||||
|
} else {
|
||||||
|
// update existing comment
|
||||||
|
comment.Id = uint(comment_id)
|
||||||
comment.Body = annotation.Description
|
comment.Body = annotation.Description
|
||||||
if err = project.server.UpdateComment(project.repository, comment); err != nil {
|
if err = project.server.UpdateComment(project.repository, comment); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
if len(task.Annotations) < len(comment_ids) {
|
||||||
|
// there have been annotations removed, hence the corresponding comments need to be removed as well
|
||||||
|
for i := len(task.Annotations); i < len(comment_ids); i += 1 {
|
||||||
|
comment_id, err := strconv.Atoi(comment_ids[i])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if comment_id < 0 {
|
||||||
|
return errors.New("Tried to delete comment with id < 0")
|
||||||
|
}
|
||||||
|
fmt.Printf("\tRemoving comment\n")
|
||||||
|
if err = project.server.DeleteComment(project.repository, uint(comment_id)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
comment_ids = comment_ids[:len(task.Annotations)]
|
||||||
|
}
|
||||||
|
// update task
|
||||||
|
tasks[x].Git_comment_ids = strings.Join(comment_ids, ",")
|
||||||
|
// as we update the task we also update the last update time as well
|
||||||
|
tasks[x].Last_gitw_update = taskwarrior.GoTimeToTaskTime(time.Now().In(time.Local))
|
||||||
|
}
|
||||||
|
return taskwarrior.UpdateTasks(tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: tasks should include the corresponding time's of the git related issues and milestones
|
// TODO: tasks should include the corresponding time's of the git related issues and milestones
|
||||||
@@ -155,7 +210,7 @@ func (project *Project) merge() error {
|
|||||||
// NOTE: merge tasks
|
// NOTE: merge tasks
|
||||||
for _, issue := range project.issues {
|
for _, issue := range project.issues {
|
||||||
filter.Reset()
|
filter.Reset()
|
||||||
filter.IncludeGitId(issue.git_issue.Id)
|
filter.IncludeGitNumber(issue.git_issue.Number)
|
||||||
filter.IncludeGitType(taskwarrior.ISSUE)
|
filter.IncludeGitType(taskwarrior.ISSUE)
|
||||||
git_tasks, err := taskwarrior.GetTasks(filter)
|
git_tasks, err := taskwarrior.GetTasks(filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -197,7 +252,7 @@ func (project *Project) merge() error {
|
|||||||
// TODO: merge milestones
|
// TODO: merge milestones
|
||||||
for _, milestone := range project.milestones {
|
for _, milestone := range project.milestones {
|
||||||
filter.Reset()
|
filter.Reset()
|
||||||
filter.IncludeGitId(milestone.Id)
|
filter.IncludeGitNumber(milestone.Id)
|
||||||
filter.IncludeGitType(taskwarrior.MILESTONE)
|
filter.IncludeGitType(taskwarrior.MILESTONE)
|
||||||
git_tasks, err := taskwarrior.GetTasks(filter)
|
git_tasks, err := taskwarrior.GetTasks(filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -213,12 +268,12 @@ func (project *Project) merge() error {
|
|||||||
// NOTE: this milestone does not yet exist
|
// NOTE: this milestone does not yet exist
|
||||||
task = milestone.IntoTask(project.repository)
|
task = milestone.IntoTask(project.repository)
|
||||||
for _, issue := range project.issues {
|
for _, issue := range project.issues {
|
||||||
if issue.git_issue.State == "closed" || issue.git_issue.Milestone.Id != milestone.Id {
|
if issue.git_issue.State == string(gitea.CLOSED) || issue.git_issue.Milestone.Id != milestone.Id {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// link to the corresponding task
|
// link to the corresponding task
|
||||||
filter.Reset()
|
filter.Reset()
|
||||||
filter.IncludeGitId(issue.git_issue.Id)
|
filter.IncludeGitNumber(issue.git_issue.Number)
|
||||||
filter.IncludeGitType(taskwarrior.ISSUE)
|
filter.IncludeGitType(taskwarrior.ISSUE)
|
||||||
tasks, err := taskwarrior.GetTasks(filter)
|
tasks, err := taskwarrior.GetTasks(filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -258,14 +313,14 @@ func (issue *Issue) IntoTask(repository gitea.Repository) (task taskwarrior.Task
|
|||||||
task = taskwarrior.NewTask(
|
task = taskwarrior.NewTask(
|
||||||
issue.git_issue.Title,
|
issue.git_issue.Title,
|
||||||
repository.Name,
|
repository.Name,
|
||||||
issue.git_issue.Id,
|
issue.git_issue.Number,
|
||||||
taskwarrior.ISSUE,
|
taskwarrior.ISSUE,
|
||||||
issue.git_issue.Labels...,
|
issue.git_issue.Labels...,
|
||||||
)
|
)
|
||||||
task.Entry = taskwarrior.GoTimeToTaskTime(issue.git_issue.Created_at)
|
task.Entry = taskwarrior.GoTimeToTaskTime(issue.git_issue.Created_at)
|
||||||
task.Modified = taskwarrior.GoTimeToTaskTime(issue.git_issue.Updated_at)
|
task.Modified = taskwarrior.GoTimeToTaskTime(issue.git_issue.Updated_at)
|
||||||
for _, comment := range issue.comments {
|
for _, comment := range issue.comments {
|
||||||
task.AppendComment(comment.Body, comment.Updated_at)
|
task.AppendComment(int(comment.Id), comment.Body, comment.Updated_at)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -280,14 +335,13 @@ func (issue *Issue) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
|||||||
if task.Description != issue.git_issue.Title {
|
if task.Description != issue.git_issue.Title {
|
||||||
task.Description = diff.Prompt(task.Description, issue.git_issue.Title, task.Description)
|
task.Description = diff.Prompt(task.Description, issue.git_issue.Title, task.Description)
|
||||||
}
|
}
|
||||||
if task.Status == "completed" || issue.git_issue.State == "closed" {
|
if task.Status == "completed" || issue.git_issue.State == string(gitea.CLOSED) {
|
||||||
if !(task.Status == "completed" && issue.git_issue.State == "closed" || task.Status != "completed" && issue.git_issue.State != "closed") {
|
if !(task.Status == "completed" && issue.git_issue.State == string(gitea.CLOSED) || task.Status != "completed" && issue.git_issue.State != string(gitea.CLOSED)) {
|
||||||
task.Status = diff.Prompt(task.Status, issue.git_issue.State, task.Status)
|
task.Status = diff.Prompt(task.Status, issue.git_issue.State, task.Status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: try to automatically derive the correct required changes
|
// TODO: try to automatically derive the correct required changes
|
||||||
var annotations []string
|
var annotations []string
|
||||||
annotations = append(annotations, issue.git_issue.Body)
|
|
||||||
for _, annotation := range task.Annotations {
|
for _, annotation := range task.Annotations {
|
||||||
annotations = append(annotations, annotation.Description)
|
annotations = append(annotations, annotation.Description)
|
||||||
}
|
}
|
||||||
@@ -295,7 +349,9 @@ func (issue *Issue) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
|||||||
for _, comment := range issue.comments {
|
for _, comment := range issue.comments {
|
||||||
comments = append(comments, comment.Body)
|
comments = append(comments, comment.Body)
|
||||||
}
|
}
|
||||||
// TODO: provide options for theirs, mine and manual edit of the task annotations
|
// FIXME: provide options for theirs, mine and manual edit of the task annotations
|
||||||
|
// FIXME: prompted for no right reason
|
||||||
|
// FIXME: changes the task incorrectly
|
||||||
annotation_joined := diff.Prompt(strings.Join(annotations, "\n\n"), strings.Join(comments, "\n\n"), strings.Join(annotations, "\n\n"))
|
annotation_joined := diff.Prompt(strings.Join(annotations, "\n\n"), strings.Join(comments, "\n\n"), strings.Join(annotations, "\n\n"))
|
||||||
for i, description := range strings.Split(annotation_joined, "\n\n") {
|
for i, description := range strings.Split(annotation_joined, "\n\n") {
|
||||||
if len(description) == 0 {
|
if len(description) == 0 {
|
||||||
@@ -304,13 +360,13 @@ func (issue *Issue) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
|||||||
if i < len(task.Annotations) {
|
if i < len(task.Annotations) {
|
||||||
task.Annotations[i].Description = description
|
task.Annotations[i].Description = description
|
||||||
} else {
|
} else {
|
||||||
task.AppendComment(description, time.Now().In(time.Local))
|
task.AppendComment(-1, description, time.Now().In(time.Local))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// NOTE: there are no modifications between the last received update and the current version, hence we just accept theirs fully
|
// NOTE: there are no modifications between the last received update and the current version, hence we just accept theirs fully
|
||||||
task.Description = issue.git_issue.Title
|
task.Description = issue.git_issue.Title
|
||||||
if issue.git_issue.State == "closed" {
|
if issue.git_issue.State == string(gitea.CLOSED) {
|
||||||
// otherwise do not update the value
|
// otherwise do not update the value
|
||||||
task.Status = "completed"
|
task.Status = "completed"
|
||||||
task.End = taskwarrior.GoTimeToTaskTime(issue.git_issue.Closed_at)
|
task.End = taskwarrior.GoTimeToTaskTime(issue.git_issue.Closed_at)
|
||||||
@@ -322,7 +378,7 @@ func (issue *Issue) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
|||||||
task.Annotations[i].Description = comment.Body
|
task.Annotations[i].Description = comment.Body
|
||||||
task.Annotations[i].Entry = taskwarrior.GoTimeToTaskTime(comment.Updated_at)
|
task.Annotations[i].Entry = taskwarrior.GoTimeToTaskTime(comment.Updated_at)
|
||||||
} else {
|
} else {
|
||||||
task.AppendComment(comment.Body, comment.Updated_at)
|
task.AppendComment(-1, comment.Body, comment.Updated_at)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ func (f *Filter) IncludeIds(ids ...uint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filter) IncludeGitId(id uint) {
|
func (f *Filter) IncludeGitNumber(id uint) {
|
||||||
f.filter = append(f.filter, fmt.Sprintf("git_id=%d", id))
|
f.filter = append(f.filter, fmt.Sprintf("git_number=%d", id))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Filter) IncludeGitType(value Type) {
|
func (f *Filter) IncludeGitType(value Type) {
|
||||||
|
|||||||
@@ -15,12 +15,13 @@ import (
|
|||||||
|
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Id uint `json:"id,omitempty"`
|
Id uint `json:"id,omitempty"`
|
||||||
Git_id float32 `json:"git_id,omitempty"` // uda
|
Git_number float32 `json:"git_number,omitempty"` // uda
|
||||||
Git_type string `json:"git_type,omitempty"` // uda
|
Git_type string `json:"git_type,omitempty"` // uda
|
||||||
Project string `json:"project,omitempty"`
|
Project string `json:"project,omitempty"`
|
||||||
Tags []string `json:"tags,omitempty"`
|
Tags []string `json:"tags,omitempty"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Annotations []Annotation `json:"annotations,omitempty"`
|
Annotations []Annotation `json:"annotations,omitempty"`
|
||||||
|
Git_comment_ids string `json:"git_comment_ids,omitempty"` // uda
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
Depends []string `json:"depends,omitempty"`
|
Depends []string `json:"depends,omitempty"`
|
||||||
Due string `json:"due,omitempty"`
|
Due string `json:"due,omitempty"`
|
||||||
@@ -33,25 +34,34 @@ type Task struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Annotation struct {
|
type Annotation struct {
|
||||||
|
Id int `json:"-"`
|
||||||
Description string `json:"description,omitempty"`
|
Description string `json:"description,omitempty"`
|
||||||
Entry string `json:"entry,omitempty"`
|
Entry string `json:"entry,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (task *Task) AppendComment(description string, time time.Time) {
|
func (task *Task) AppendComment(comment_id int, description string, time time.Time) {
|
||||||
annotation := Annotation{
|
annotation := Annotation{
|
||||||
|
Id: comment_id,
|
||||||
Description: description,
|
Description: description,
|
||||||
Entry: GoTimeToTaskTime(time),
|
Entry: GoTimeToTaskTime(time),
|
||||||
}
|
}
|
||||||
|
var comment_ids []string
|
||||||
|
comment_ids = nil
|
||||||
|
if len(task.Git_comment_ids) > 0 {
|
||||||
|
comment_ids = strings.Split(task.Git_comment_ids, ",")
|
||||||
|
}
|
||||||
|
comment_ids = append(comment_ids, fmt.Sprintf("%d", comment_id))
|
||||||
|
task.Git_comment_ids = strings.Join(comment_ids, ",")
|
||||||
task.Annotations = append(task.Annotations, annotation)
|
task.Annotations = append(task.Annotations, annotation)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTask(description string, project string, git_id uint, git_type Type, tags ...string) Task {
|
func NewTask(description string, project string, git_number uint, git_type Type, tags ...string) Task {
|
||||||
// TODO: update task struct to include the new user defined value, which shall
|
// TODO: update task struct to include the new user defined value, which shall
|
||||||
// also be provided as an argument
|
// also be provided as an argument
|
||||||
return Task{
|
return Task{
|
||||||
Project: project,
|
Project: project,
|
||||||
Description: description,
|
Description: description,
|
||||||
Git_id: float32(git_id),
|
Git_number: float32(git_number),
|
||||||
Git_type: string(git_type),
|
Git_type: string(git_type),
|
||||||
Last_gitw_update: GoTimeToTaskTime(time.Now()),
|
Last_gitw_update: GoTimeToTaskTime(time.Now()),
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
|
|||||||
Reference in New Issue
Block a user