-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show notification on watch finish
- Loading branch information
Showing
9 changed files
with
189 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package prssection | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/charmbracelet/log" | ||
"github.com/gen2brain/beeep" | ||
|
||
"github.com/dlvhdr/gh-dash/data" | ||
prComponent "github.com/dlvhdr/gh-dash/ui/components/pr" | ||
"github.com/dlvhdr/gh-dash/ui/constants" | ||
"github.com/dlvhdr/gh-dash/ui/context" | ||
) | ||
|
||
func (m *Model) watchChecks() tea.Cmd { | ||
pr := m.GetCurrRow() | ||
prNumber := pr.GetNumber() | ||
title := pr.GetTitle() | ||
url := pr.GetUrl() | ||
repoNameWithOwner := pr.GetRepoNameWithOwner() | ||
taskId := fmt.Sprintf("pr_reopen_%d", prNumber) | ||
task := context.Task{ | ||
Id: taskId, | ||
StartText: fmt.Sprintf("Watching checks for PR #%d", prNumber), | ||
FinishedText: fmt.Sprintf("Watching checks for PR #%d", prNumber), | ||
State: context.TaskStart, | ||
Error: nil, | ||
} | ||
startCmd := m.Ctx.StartTask(task) | ||
return tea.Batch(startCmd, func() tea.Msg { | ||
c := exec.Command( | ||
"gh", | ||
"pr", | ||
"checks", | ||
"--watch", | ||
"--fail-fast", | ||
fmt.Sprint(m.GetCurrRow().GetNumber()), | ||
"-R", | ||
m.GetCurrRow().GetRepoNameWithOwner(), | ||
) | ||
|
||
var outb, errb bytes.Buffer | ||
c.Stdout = &outb | ||
c.Stderr = &errb | ||
|
||
err := c.Start() | ||
go func() { | ||
err := c.Wait() | ||
if err != nil { | ||
log.Error("Error waiting for watch command to finish", "err", err) | ||
} | ||
|
||
// TODO: check for installation of terminal-notifier or alternative as logo isn't supported | ||
updatedPr, err := data.FetchPullRequest(url) | ||
if err != nil { | ||
log.Error("Error fetching updated PR details", "url", url, "err", err) | ||
} | ||
|
||
renderedPr := prComponent.PullRequest{Ctx: m.Ctx, Data: updatedPr} | ||
checksRollup := " Checks are pending" | ||
switch renderedPr.GetStatusChecksRollup() { | ||
case "SUCCESS": | ||
checksRollup = "✅ Checks have passed" | ||
case "FAILURE": | ||
checksRollup = "❌ Checks have failed" | ||
} | ||
|
||
err = beeep.Notify( | ||
fmt.Sprintf("gh-dash: %s", title), | ||
fmt.Sprintf("PR #%d in %s\n%s", prNumber, repoNameWithOwner, checksRollup), | ||
"", | ||
) | ||
if err != nil { | ||
log.Error("Error showing system notification", "err", err) | ||
} | ||
}() | ||
|
||
return constants.TaskFinishedMsg{ | ||
SectionId: m.Id, | ||
SectionType: SectionType, | ||
TaskId: taskId, | ||
Err: err, | ||
Msg: UpdatePRMsg{ | ||
PrNumber: prNumber, | ||
}, | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters