Activate implements Bugger.Activate.
(todo *Todo)
| 71 | |
| 72 | // Activate implements Bugger.Activate. |
| 73 | func (b *GitHubBugger) Activate(todo *Todo) (bool, error) { |
| 74 | id, err := parseIssueNo(todo.Issue) |
| 75 | if err != nil { |
| 76 | return true, err |
| 77 | } |
| 78 | if id <= 0 { |
| 79 | return false, nil |
| 80 | } |
| 81 | |
| 82 | // Check against active issues cache. |
| 83 | if _, ok := b.issues[id]; ok { |
| 84 | fmt.Printf("%q is active: OK\n", todo.Issue) |
| 85 | return true, nil |
| 86 | } |
| 87 | |
| 88 | fmt.Printf("%q is not active: reopening issue %d\n", todo.Issue, id) |
| 89 | |
| 90 | // Format comment with TODO locations and search link. |
| 91 | comment := strings.Builder{} |
| 92 | fmt.Fprintln(&comment, "There are TODOs still referencing this issue:") |
| 93 | for _, l := range todo.Locations { |
| 94 | fmt.Fprintf(&comment, |
| 95 | "1. [%s:%d](https://github.com/%s/%s/blob/HEAD/%s#L%d): %s\n", |
| 96 | l.File, l.Line, b.owner, b.repo, l.File, l.Line, l.Comment) |
| 97 | } |
| 98 | fmt.Fprintf(&comment, |
| 99 | "\n\nSearch [TODO](https://github.com/%s/%s/search?q=%%22%s%%22)", b.owner, b.repo, todo.Issue) |
| 100 | |
| 101 | if b.dryRun { |
| 102 | fmt.Printf("[dry-run: skipping change to issue %d]\n%s\n=======================\n", id, comment.String()) |
| 103 | return true, nil |
| 104 | } |
| 105 | |
| 106 | ctx := context.Background() |
| 107 | req := &github.IssueRequest{State: github.String("open")} |
| 108 | _, _, err = b.client.Issues.Edit(ctx, b.owner, b.repo, id, req) |
| 109 | if err != nil { |
| 110 | return true, fmt.Errorf("failed to reactivate issue %d: %v", id, err) |
| 111 | } |
| 112 | |
| 113 | _, _, err = b.client.Issues.AddLabelsToIssue(ctx, b.owner, b.repo, id, []string{"revived"}) |
| 114 | if err != nil { |
| 115 | return true, fmt.Errorf("failed to set label on issue %d: %v", id, err) |
| 116 | } |
| 117 | |
| 118 | cmt := &github.IssueComment{ |
| 119 | Body: github.String(comment.String()), |
| 120 | Reactions: &github.Reactions{Confused: github.Int(1)}, |
| 121 | } |
| 122 | if _, _, err := b.client.Issues.CreateComment(ctx, b.owner, b.repo, id, cmt); err != nil { |
| 123 | return true, fmt.Errorf("failed to add comment to issue %d: %v", id, err) |
| 124 | } |
| 125 | |
| 126 | return true, nil |
| 127 | } |
| 128 | |
| 129 | var issuePrefixes = []string{ |
| 130 | "gvisor.dev/issue/", |
nothing calls this directly
no test coverage detected