]> khamidou — GitHub mirrors - prguy.git/commitdiff
add demo mode
authorKarim Hamidou <karim@khamidou.com>
Mon, 8 Jul 2024 02:20:25 +0000 (19:20 -0700)
committerKarim Hamidou <karim@khamidou.com>
Mon, 8 Jul 2024 02:20:25 +0000 (19:20 -0700)
Makefile
cmd/prguy/main.go
cmd/prguy/repos.go

index 141049b5c345ccb2280b0e459bf1e8abf0973b0e..a62317832732be55d386b33c4ed0f3815899efe1 100644 (file)
--- 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 ./...
index 441458e1b0f124bb004408a624c060cbbacc1fc6..667c6ac4b086bd8c453e7ba7fceb23cd64512332 100644 (file)
@@ -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, "")
+}
index 3ecacc5d0bf074201a37a8fa2b7ee3ca2ad091cf..56c05dd0bae68e675509187916aed6db88a6ce23 100644 (file)
@@ -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 {