]> khamidou — GitHub mirrors - prguy.git/commitdiff
group by repo 0.91
authorKarim Hamidou <karim@khamidou.com>
Tue, 6 Aug 2024 01:15:53 +0000 (18:15 -0700)
committerKarim Hamidou <karim@khamidou.com>
Tue, 6 Aug 2024 01:15:53 +0000 (18:15 -0700)
cmd/prguy/main.go
cmd/prguy/repos.go
go.mod
go.sum

index c21b1d58779333db3bfd411df08bb30e628b3622..79cb3fc88b509510f5caf90499b2237738d5d0b0 100644 (file)
@@ -85,25 +85,41 @@ func setupMenu(ctx context.Context, cancel context.CancelFunc) {
 
                        systray.ResetMenu()
 
-                       if len(myPRs) == 0 {
+                       if len(myPRs.Keys()) == 0 {
                                systray.AddMenuItem("No PRs out from you – yet", "")
                        } else {
-                               for _, pr := range myPRs {
-                                       systrayItem := renderPR(pr)
-                                       channels = append(channels, systrayItem.ClickedCh)
-                                       channelsMap[systrayItem.ClickedCh] = pr
+                               for _, repo := range myPRs.Keys() {
+                                       prs, _ := myPRs.Get(repo)
+                                       prList := prs.([]pullRequest)
+                                       if len(prList) == 0 {
+                                               continue
+                                       }
+
+                                       for _, pr := range prList {
+                                               systrayItem := renderPR(pr)
+                                               channels = append(channels, systrayItem.ClickedCh)
+                                               channelsMap[systrayItem.ClickedCh] = pr
+                                       }
                                }
                        }
 
                        systray.AddSeparator()
 
-                       if len(myPRs) != 0 && len(otherPRs) == 0 {
+                       if len(myPRs.Keys()) != 0 && len(otherPRs.Keys()) == 0 {
                                systray.AddMenuItem("No PRs to review, no news is good news.", "")
-                       } else if len(otherPRs) != 0 {
-                               for _, pr := range otherPRs {
-                                       systrayItem := renderPR(pr)
-                                       channels = append(channels, systrayItem.ClickedCh)
-                                       channelsMap[systrayItem.ClickedCh] = pr
+                       } else if len(otherPRs.Keys()) != 0 {
+                               for _, repo := range otherPRs.Keys() {
+                                       prs, _ := otherPRs.Get(repo)
+                                       prList := prs.([]pullRequest)
+                                       if len(prList) == 0 {
+                                               continue
+                                       }
+
+                                       for _, pr := range prList {
+                                               systrayItem := renderPR(pr)
+                                               channels = append(channels, systrayItem.ClickedCh)
+                                               channelsMap[systrayItem.ClickedCh] = pr
+                                       }
                                }
                        }
 
index 85286ce137654ded5fc2ca9141560ceca594f5e9..ec11d96b14bc03efa8d3cf613ba704517ff26d60 100644 (file)
@@ -4,6 +4,7 @@ import (
        "encoding/json"
        "errors"
        "fmt"
+       "github.com/iancoleman/orderedmap"
        "io/ioutil"
        "net/http"
        "time"
@@ -27,14 +28,20 @@ type pullRequest struct {
        buildStatus buildStatus
 }
 
-func listUserPRs(token string, isDemo bool) ([]pullRequest, []pullRequest, error) {
+func listUserPRs(token string, isDemo bool) (*orderedmap.OrderedMap, *orderedmap.OrderedMap, error) {
+       myPRs := orderedmap.New()
+       otherPRs := orderedmap.New()
+
        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
+               myPRs.Set("michael/repo", []pullRequest{
+                       {url: "blah", title: "Unbreak prod", mergeable: true, buildStatus: buildFailure},
+                       {url: "blah", title: "Fix the tests michael broke", mergeable: true, buildStatus: buildPending}})
+
+               otherPRs.Set("michael/repo", []pullRequest{
+                       {url: "blah", title: "Revert michael's 'fix'", mergeable: true, buildStatus: buildFailure},
+               })
+
+               return myPRs, otherPRs, nil
        }
 
        githubUrl := "https://api.github.com/notifications?participating=true&all=true"
@@ -63,9 +70,6 @@ func listUserPRs(token string, isDemo bool) ([]pullRequest, []pullRequest, error
                return nil, nil, err
        }
 
-       var myPRs []pullRequest
-       var otherPRs []pullRequest
-
        var jsonData []map[string]interface{}
        var PRsSeen = make(map[string]bool)
 
@@ -129,19 +133,34 @@ func listUserPRs(token string, isDemo bool) ([]pullRequest, []pullRequest, error
                mergeableState := prData["mergeable_state"].(string)
                mergeable := mergeableState == "clean" || mergeableState == "has_hooks"
                if reason == "author" {
-                       myPRs = append(myPRs, pullRequest{
+                       if _, ok := myPRs.Get(repoFullName); !ok {
+                               myPRs.Set(repoFullName, []pullRequest{})
+                       }
+
+                       prContents := pullRequest{
                                url:         prUrl,
                                title:       subject["title"].(string),
                                mergeable:   mergeable,
                                buildStatus: prStatus,
-                       })
+                       }
+                       contents, _ := myPRs.Get(repoFullName)
+                       var PRsList = contents.([]pullRequest)
+                       PRsList = append(PRsList, prContents)
+                       myPRs.Set(repoFullName, PRsList)
                } else {
-                       otherPRs = append(otherPRs, pullRequest{
-                               url:         prUrl,
+                       if _, ok := otherPRs.Get(repoFullName); !ok {
+                               otherPRs.Set(repoFullName, []pullRequest{})
+                       }
+
+                       prContents := pullRequest{url: prUrl,
                                title:       subject["title"].(string),
                                mergeable:   mergeable,
                                buildStatus: prStatus,
-                       })
+                       }
+                       contents, _ := otherPRs.Get(repoFullName)
+                       var PRsList = contents.([]pullRequest)
+                       PRsList = append(PRsList, prContents)
+                       otherPRs.Set(repoFullName, PRsList)
                }
 
                time.Sleep(1 * time.Second)
diff --git a/go.mod b/go.mod
index d49640c5ea19a22d5cb44fde40d165ccad149f1a..83fd09d996d683a214d66b3afd166f549933e009 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -4,6 +4,7 @@ go 1.22.3
 
 require (
        fyne.io/systray v1.10.0
+       github.com/iancoleman/orderedmap v0.3.0
        github.com/ncruces/zenity v0.10.12
        github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
 )
diff --git a/go.sum b/go.sum
index 4ee7ce4c86d28fe180cf6fb55a4c868f4bf22411..c429481d6891a75c0ed1acebba40d6559465145e 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -8,6 +8,8 @@ github.com/dchest/jsmin v0.0.0-20220218165748-59f39799265f h1:OGqDDftRTwrvUoL6pO
 github.com/dchest/jsmin v0.0.0-20220218165748-59f39799265f/go.mod h1:Dv9D0NUlAsaQcGQZa5kc5mqR9ua72SmA8VXi4cd+cBw=
 github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA=
 github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
+github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
+github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
 github.com/josephspurrier/goversioninfo v1.4.0 h1:Puhl12NSHUSALHSuzYwPYQkqa2E1+7SrtAPJorKK0C8=
 github.com/josephspurrier/goversioninfo v1.4.0/go.mod h1:JWzv5rKQr+MmW+LvM412ToT/IkYDZjaclF2pKDss8IY=
 github.com/ncruces/zenity v0.10.12 h1:o4SErDa0kQijlqG6W4OYYzO6kA0fGu34uegvJGcMLBI=