From 48ac995705a1af9ee3923d01a9f5cdfa6202c467 Mon Sep 17 00:00:00 2001 From: Karim Hamidou Date: Sun, 7 Jul 2024 19:20:25 -0700 Subject: [PATCH] add demo mode --- Makefile | 3 ++- cmd/prguy/main.go | 66 ++++++++++++++++++++++++---------------------- cmd/prguy/repos.go | 11 +++++++- 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 141049b..a623178 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ build: cmd/prguy/*.go - go build -o bin/$(shell basename $(PWD)) ./cmd/prguy/ + CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o bin/$(shell basename $(PWD))_amd64 ./cmd/prguy/ + GOOS=darwin GOARCH=arm64 go build -o bin/$(shell basename $(PWD))_arm64 ./cmd/prguy/ fmt: go fmt ./... diff --git a/cmd/prguy/main.go b/cmd/prguy/main.go index 441458e..667c6ac 100644 --- a/cmd/prguy/main.go +++ b/cmd/prguy/main.go @@ -3,6 +3,7 @@ package main import ( "context" "errors" + "flag" "fmt" "io/ioutil" "net/http" @@ -19,7 +20,11 @@ import ( const GH_CLIENT_ID = "Ov23liJtErJem2rhR36t" +var demoFlag = flag.Bool("demo", false, "Run the app in demo mode") + func main() { + flag.Parse() + fmt.Println("Demo mode:", *demoFlag) onExit := func() { } @@ -66,7 +71,7 @@ func setupMenu(ctx context.Context, cancel context.CancelFunc) { statusItem.Disable() fmt.Println("Fetching PRs...") - myPRs, otherPRs, err := listUserPRs(cfg.OAuthToken) + myPRs, otherPRs, err := listUserPRs(cfg.OAuthToken, *demoFlag) if err != nil { fmt.Println("Error fetching PRs:", err) time.Sleep(35 * time.Second) @@ -79,26 +84,9 @@ func setupMenu(ctx context.Context, cancel context.CancelFunc) { systray.AddMenuItem("No PRs out from you, let's get after it!", "") } else { for _, pr := range myPRs { - var pr_status string - var build_status string - if pr.mergeable { - pr_status = "✅" - } else { - pr_status = "❌" - } - - if pr.buildStatus == buildSuccess { - build_status = "🟢" - } else if pr.buildStatus == buildFailure { - build_status = "🔴" - } else { - build_status = "🔵" - } - - title := fmt.Sprintf("%-*s %s%s", 50, pr.title, build_status, pr_status) - channel := systray.AddMenuItem(title, "") - channels = append(channels, channel.ClickedCh) - channelsMap[channel.ClickedCh] = pr + systrayItem := renderPR(pr) + channels = append(channels, systrayItem.ClickedCh) + channelsMap[systrayItem.ClickedCh] = pr } } @@ -108,17 +96,9 @@ func setupMenu(ctx context.Context, cancel context.CancelFunc) { systray.AddMenuItem("No PRs to review, no news is good news.", "") } else if len(otherPRs) != 0 { for _, pr := range otherPRs { - var pr_status string - if pr.mergeable { - pr_status = "✅" - } else { - pr_status = "❌" - } - - title := fmt.Sprintf("%-*s %s", 50, pr.title, pr_status) - channel := systray.AddMenuItem(title, "") - channels = append(channels, channel.ClickedCh) - channelsMap[channel.ClickedCh] = pr + systrayItem := renderPR(pr) + channels = append(channels, systrayItem.ClickedCh) + channelsMap[systrayItem.ClickedCh] = pr } } @@ -358,3 +338,25 @@ func selectChannels(chans []chan struct{}) (int, bool) { i, _, ok := reflect.Select(cases) return i, ok } + +func renderPR(pr pullRequest) *systray.MenuItem { + var pr_status string + var build_status string + + if pr.mergeable { + pr_status = "✅" + } else { + pr_status = "❌" + } + + if pr.buildStatus == buildSuccess { + build_status = "🟢" + } else if pr.buildStatus == buildFailure { + build_status = "🔴" + } else { + build_status = "🔵" + } + + title := fmt.Sprintf("%s%s %s", pr_status, build_status, pr.title) + return systray.AddMenuItem(title, "") +} diff --git a/cmd/prguy/repos.go b/cmd/prguy/repos.go index 3ecacc5..56c05dd 100644 --- a/cmd/prguy/repos.go +++ b/cmd/prguy/repos.go @@ -26,7 +26,16 @@ type pullRequest struct { buildStatus buildStatus } -func listUserPRs(token string) ([]pullRequest, []pullRequest, error) { +func listUserPRs(token string, isDemo bool) ([]pullRequest, []pullRequest, error) { + if isDemo { + return []pullRequest{ + {url: "blah", title: "Unbreak prod", mergeable: true, buildStatus: buildFailure}, + {url: "blah", title: "Fix the tests michael broke", mergeable: true, buildStatus: buildPending}, + }, []pullRequest{ + {url: "blah", title: "Revert michael's 'fix'", mergeable: true, buildStatus: buildFailure}, + }, nil + } + githubUrl := "https://api.github.com/notifications?participating=true&all=true" req, err := http.NewRequest("GET", githubUrl, nil) if err != nil { -- 2.43.0