- commit
- adca693
- parent
- 5846087
- author
- jolheiser
- date
- 2025-08-21 22:55:11 -0400 EDT
strongly type status Signed-off-by: jolheiser <git@jolheiser.com>
M
cli.go
+12,
-12
1@@ -466,15 +466,15 @@ To get started, submit a new patch request:
2 writer := NewTabWriter(sesh)
3 fmt.Fprintln(writer, "ID\tRepoID\tName\tStatus\tPatchsets\tUser\tDate")
4 for _, req := range prs {
5- if onlyAccepted && req.Status != "accepted" {
6+ if onlyAccepted && req.Status != StatusAccepted {
7 continue
8 }
9
10- if onlyClosed && req.Status != "closed" {
11+ if onlyClosed && req.Status != StatusClosed {
12 continue
13 }
14
15- if onlyOpen && req.Status != "open" {
16+ if onlyOpen && req.Status != StatusOpen {
17 continue
18 }
19
20@@ -640,11 +640,11 @@ To get started, submit a new patch request:
21 return fmt.Errorf("you are not authorized to accept a PR")
22 }
23
24- if prq.Status == "accepted" {
25+ if prq.Status == StatusAccepted {
26 return fmt.Errorf("PR has already been accepted")
27 }
28
29- err = pr.UpdatePatchRequestStatus(prID, user.ID, "accepted")
30+ err = pr.UpdatePatchRequestStatus(prID, user.ID, StatusAccepted)
31 if err != nil {
32 return err
33 }
34@@ -701,7 +701,7 @@ To get started, submit a new patch request:
35 return fmt.Errorf("you are not authorized to change PR status")
36 }
37
38- if prq.Status == "closed" {
39+ if prq.Status == StatusClosed {
40 return fmt.Errorf("PR has already been closed")
41 }
42
43@@ -710,7 +710,7 @@ To get started, submit a new patch request:
44 return err
45 }
46
47- err = pr.UpdatePatchRequestStatus(prID, user.ID, "closed")
48+ err = pr.UpdatePatchRequestStatus(prID, user.ID, StatusClosed)
49 if err != nil {
50 return err
51 }
52@@ -760,7 +760,7 @@ To get started, submit a new patch request:
53 return fmt.Errorf("you are not authorized to change PR status")
54 }
55
56- if prq.Status == "open" {
57+ if prq.Status == StatusOpen {
58 return fmt.Errorf("PR is already open")
59 }
60
61@@ -769,7 +769,7 @@ To get started, submit a new patch request:
62 return err
63 }
64
65- err = pr.UpdatePatchRequestStatus(prID, user.ID, "open")
66+ err = pr.UpdatePatchRequestStatus(prID, user.ID, StatusOpen)
67 if err == nil {
68 wish.Printf(sesh, "Reopened PR %s (#%d)\n", prq.Name, prq.ID)
69 }
70@@ -887,17 +887,17 @@ To get started, submit a new patch request:
71 }
72
73 op := OpNormal
74- nextStatus := "open"
75+ nextStatus := StatusOpen
76 if isReview {
77 wish.Println(sesh, "Marking patchset as a review")
78 op = OpReview
79 } else if isAccept {
80 wish.Println(sesh, "Marking PR as accepted")
81- nextStatus = "accepted"
82+ nextStatus = StatusAccepted
83 op = OpAccept
84 } else if isClose {
85 wish.Println(sesh, "Marking PR as closed")
86- nextStatus = "closed"
87+ nextStatus = StatusClosed
88 op = OpClose
89 }
90
+10,
-1
1@@ -7,6 +7,15 @@ import (
2 "github.com/bluekeyes/go-gitdiff/gitdiff"
3 )
4
5+type Status string
6+
7+const (
8+ StatusOpen Status = "open"
9+ StatusClosed Status = "closed"
10+ StatusAccepted Status = "accepted"
11+ StatusReviewed Status = "reviewed"
12+)
13+
14 // User is a db model for users.
15 type User struct {
16 ID int64 `db:"id"`
17@@ -41,7 +50,7 @@ type PatchRequest struct {
18 RepoID int64 `db:"repo_id"`
19 Name string `db:"name"`
20 Text string `db:"text"`
21- Status string `db:"status"`
22+ Status Status `db:"status"`
23 CreatedAt time.Time `db:"created_at"`
24 UpdatedAt time.Time `db:"updated_at"`
25 // only used for aggregate queries
M
pr.go
+2,
-2
1@@ -43,7 +43,7 @@ type GitPatchRequest interface {
2 GetPatchsetByID(patchsetID int64) (*Patchset, error)
3 GetLatestPatchsetByPrID(prID int64) (*Patchset, error)
4 GetPatchesByPatchsetID(prID int64) ([]*Patch, error)
5- UpdatePatchRequestStatus(prID, userID int64, status string) error
6+ UpdatePatchRequestStatus(prID, userID int64, status Status) error
7 UpdatePatchRequestName(prID, userID int64, name string) error
8 DeletePatchsetByID(userID, prID int64, patchsetID int64) error
9 CreateEventLog(tx *sqlx.Tx, eventLog EventLog) error
10@@ -293,7 +293,7 @@ func (cmd PrCmd) GetPatchRequestByID(prID int64) (*PatchRequest, error) {
11 }
12
13 // Status types: open, closed, accepted, reviewed.
14-func (cmd PrCmd) UpdatePatchRequestStatus(prID int64, userID int64, status string) error {
15+func (cmd PrCmd) UpdatePatchRequestStatus(prID int64, userID int64, status Status) error {
16 tx, err := cmd.Backend.DB.Beginx()
17 if err != nil {
18 return err
M
web.go
+6,
-6
1@@ -145,8 +145,8 @@ type RepoDetailData struct {
2 func createPrDataSorter(sort, sortDir string) func(a, b *PrListData) int {
3 return func(a *PrListData, b *PrListData) int {
4 if sort == "status" {
5- statusA := strings.ToLower(a.Status)
6- statusB := strings.ToLower(b.Status)
7+ statusA := strings.ToLower(string(a.Status))
8+ statusB := strings.ToLower(string(b.Status))
9 if sortDir == "asc" {
10 return strings.Compare(statusA, statusB)
11 } else {
12@@ -191,9 +191,9 @@ func createPrDataSorter(sort, sortDir string) func(a, b *PrListData) int {
13
14 func getPrTableData(web *WebCtx, prs []*PatchRequest, query url.Values) ([]*PrListData, error) {
15 prdata := []*PrListData{}
16- status := strings.ToLower(query.Get("status"))
17+ status := Status(strings.ToLower(query.Get("status")))
18 if status == "" {
19- status = "open"
20+ status = StatusOpen
21 }
22 username := strings.ToLower(query.Get("user"))
23 title := strings.ToLower(query.Get("title"))
24@@ -361,7 +361,7 @@ type PrListData struct {
25 ID int64
26 DateOrig time.Time
27 Date string
28- Status string
29+ Status Status
30 }
31
32 func userDetailHandler(w http.ResponseWriter, r *http.Request) {
33@@ -518,7 +518,7 @@ type PrData struct {
34 ID int64
35 Title string
36 Date string
37- Status string
38+ Status Status
39 }
40
41 type PatchFile struct {