Skip to content

Commit

Permalink
fix: merge pr (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlvhdr authored Aug 14, 2024
1 parent c37003b commit a7f720c
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions ui/components/tasks/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,40 @@ func PRReady(ctx *context.ProgramContext, section SectionIdentifer, pr data.RowD

func MergePR(ctx *context.ProgramContext, section SectionIdentifer, pr data.RowData) tea.Cmd {
prNumber := pr.GetNumber()
return fireTask(ctx, GitHubTask{
Id: buildTaskId("pr_merge", prNumber),
Args: []string{
"pr",
"merge",
fmt.Sprint(prNumber),
"-R",
pr.GetRepoNameWithOwner(),
},
Section: section,
c := exec.Command(
"gh",
"pr",
"merge",
fmt.Sprint(prNumber),
"-R",
pr.GetRepoNameWithOwner(),
)

taskId := fmt.Sprintf("merge_%d", prNumber)
task := context.Task{
Id: taskId,
StartText: fmt.Sprintf("Merging PR #%d", prNumber),
FinishedText: fmt.Sprintf("PR #%d has been merged", prNumber),
Msg: func(c *exec.Cmd, err error) UpdatePRMsg {
isMerged := false
if err == nil && c.ProcessState.ExitCode() == 0 {
isMerged = true
}
return UpdatePRMsg{
State: context.TaskStart,
Error: nil,
}
startCmd := ctx.StartTask(task)

return tea.Batch(startCmd, tea.ExecProcess(c, func(err error) tea.Msg {
isMerged := false
if err == nil && c.ProcessState.ExitCode() == 0 {
isMerged = true
}

return constants.TaskFinishedMsg{
SectionId: section.Id,
SectionType: section.Type,
TaskId: taskId,
Err: err,
Msg: UpdatePRMsg{
PrNumber: prNumber,
IsMerged: &isMerged,
}
},
})
},
}
}))
}

0 comments on commit a7f720c

Please sign in to comment.