add: create new comment if annotation was added localy
This commit is contained in:
@@ -150,6 +150,32 @@ func (project *Project) Push(dry_run bool) error {
|
||||
continue
|
||||
}
|
||||
var comment gitea.Comment
|
||||
if i >= len(comment_ids) {
|
||||
// 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 !dry_run {
|
||||
if comment, err = project.server.NewComment(project.repository, issue, comment); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// add the corresponding id to the one assigned by git
|
||||
comment_ids = append(comment_ids, fmt.Sprintf("%d", comment.Id))
|
||||
continue
|
||||
}
|
||||
comment_id, err := strconv.Atoi(comment_ids[i])
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -218,11 +244,10 @@ func (project *Project) Push(dry_run bool) error {
|
||||
// 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))
|
||||
}
|
||||
if !dry_run {
|
||||
return taskwarrior.UpdateTasks(tasks)
|
||||
} else {
|
||||
if dry_run {
|
||||
return nil
|
||||
}
|
||||
return taskwarrior.UpdateTasks(tasks)
|
||||
}
|
||||
|
||||
func (project *Project) merge(dry_run bool) error {
|
||||
@@ -261,14 +286,14 @@ func (project *Project) merge(dry_run bool) error {
|
||||
tasks = append(tasks, task)
|
||||
}
|
||||
}
|
||||
if !dry_run {
|
||||
if err := taskwarrior.UpdateTasks(tasks); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if dry_run {
|
||||
for _, task := range tasks {
|
||||
fmt.Printf("\t%#v\n\n", task)
|
||||
}
|
||||
} else {
|
||||
if err := taskwarrior.UpdateTasks(tasks); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
tasks = nil // NOTE: reset tasks after successfully updating the issues
|
||||
@@ -319,12 +344,12 @@ func (project *Project) merge(dry_run bool) error {
|
||||
tasks = append(tasks, task)
|
||||
}
|
||||
}
|
||||
if !dry_run {
|
||||
return taskwarrior.UpdateTasks(tasks)
|
||||
} else {
|
||||
if dry_run {
|
||||
for _, task := range tasks {
|
||||
fmt.Printf("\t%#v\n\n", task)
|
||||
}
|
||||
} else {
|
||||
return taskwarrior.UpdateTasks(tasks)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -351,7 +376,6 @@ func (issue *Issue) IntoTask(repository gitea.Repository) (task taskwarrior.Task
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: implement merging of git issue or milestone into a taskwarrior task
|
||||
func (issue *Issue) MergeTask(task taskwarrior.Task) taskwarrior.Task {
|
||||
last_update := taskwarrior.TaskTimeToGoTime(task.Last_gitw_update)
|
||||
if issue.git_issue.Updated_at.After(last_update) {
|
||||
|
||||
@@ -56,8 +56,6 @@ func (task *Task) AppendComment(comment_id int, description string, time time.Ti
|
||||
}
|
||||
|
||||
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
|
||||
// also be provided as an argument
|
||||
return Task{
|
||||
Project: project,
|
||||
Description: description,
|
||||
|
||||
Reference in New Issue
Block a user