add: create new comment if annotation was added localy

This commit is contained in:
2023-10-30 20:10:04 +01:00
parent 46762c4044
commit 6f01bebe9a
2 changed files with 36 additions and 14 deletions

View File

@@ -150,6 +150,32 @@ func (project *Project) Push(dry_run bool) error {
continue continue
} }
var comment gitea.Comment 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]) comment_id, err := strconv.Atoi(comment_ids[i])
if err != nil { if err != nil {
return err 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 // 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)) tasks[x].Last_gitw_update = taskwarrior.GoTimeToTaskTime(time.Now().In(time.Local))
} }
if !dry_run { if dry_run {
return taskwarrior.UpdateTasks(tasks)
} else {
return nil return nil
} }
return taskwarrior.UpdateTasks(tasks)
} }
func (project *Project) merge(dry_run bool) error { func (project *Project) merge(dry_run bool) error {
@@ -261,14 +286,14 @@ func (project *Project) merge(dry_run bool) error {
tasks = append(tasks, task) tasks = append(tasks, task)
} }
} }
if !dry_run { if dry_run {
if err := taskwarrior.UpdateTasks(tasks); err != nil {
return err
}
} else {
for _, task := range tasks { for _, task := range tasks {
fmt.Printf("\t%#v\n\n", task) 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 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) tasks = append(tasks, task)
} }
} }
if !dry_run { if dry_run {
return taskwarrior.UpdateTasks(tasks)
} else {
for _, task := range tasks { for _, task := range tasks {
fmt.Printf("\t%#v\n\n", task) fmt.Printf("\t%#v\n\n", task)
} }
} else {
return taskwarrior.UpdateTasks(tasks)
} }
return nil return nil
} }
@@ -351,7 +376,6 @@ func (issue *Issue) IntoTask(repository gitea.Repository) (task taskwarrior.Task
return return
} }
// TODO: implement merging of git issue or milestone into a taskwarrior task
func (issue *Issue) MergeTask(task taskwarrior.Task) taskwarrior.Task { func (issue *Issue) MergeTask(task taskwarrior.Task) taskwarrior.Task {
last_update := taskwarrior.TaskTimeToGoTime(task.Last_gitw_update) last_update := taskwarrior.TaskTimeToGoTime(task.Last_gitw_update)
if issue.git_issue.Updated_at.After(last_update) { if issue.git_issue.Updated_at.After(last_update) {

View File

@@ -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 { 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{ return Task{
Project: project, Project: project,
Description: description, Description: description,