-
Notifications
You must be signed in to change notification settings - Fork 182
/
comment.go
56 lines (51 loc) 路 1.28 KB
/
comment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package issuesidebar
import (
"fmt"
"os/exec"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/dlvhdr/gh-dash/data"
"github.com/dlvhdr/gh-dash/ui/components/issuessection"
"github.com/dlvhdr/gh-dash/ui/constants"
"github.com/dlvhdr/gh-dash/ui/context"
)
func (m *Model) comment(body string) tea.Cmd {
issue := m.issue.Data
issueNumber := issue.GetNumber()
taskId := fmt.Sprintf("issue_comment_%d", issueNumber)
task := context.Task{
Id: taskId,
StartText: fmt.Sprintf("Commenting on issue #%d", issueNumber),
FinishedText: fmt.Sprintf("Commented on issue #%d", issueNumber),
State: context.TaskStart,
Error: nil,
}
startCmd := m.ctx.StartTask(task)
return tea.Batch(startCmd, func() tea.Msg {
c := exec.Command(
"gh",
"issue",
"comment",
fmt.Sprint(issueNumber),
"-R",
issue.GetRepoNameWithOwner(),
"-b",
body,
)
err := c.Run()
return constants.TaskFinishedMsg{
SectionId: m.sectionId,
SectionType: issuessection.SectionType,
TaskId: taskId,
Err: err,
Msg: issuessection.UpdateIssueMsg{
IssueNumber: issueNumber,
NewComment: &data.IssueComment{
Author: struct{ Login string }{Login: m.ctx.User},
Body: body,
UpdatedAt: time.Now(),
},
},
}
})
}