git-pr
created pr with
75.1
changed pr name to
Status comments
cmds
checkout latest patchset:
ssh pr.pico.sh print 75 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 75.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 75
Patchset
75.1
strongly type status
jolheiser
2025-08-22T02:55:11ZSigned-off-by: jolheiser <git@jolheiser.com>
Semantic diff summary
1 added,
13 modified,
1 signature changed,
0 removed
across 4 analyzed files
+12
-12
cli.go
#
| ... | ... | @@ -466,15 +466,15 @@ To get started, submit a new patch request: | |
| 466 | 466 | writer := NewTabWriter(sesh) | |
| 467 | 467 | fmt.Fprintln(writer, "ID\tRepoID\tName\tStatus\tPatchsets\tUser\tDate") | |
| 468 | 468 | for _, req := range prs { | |
| 469 | - | if onlyAccepted && req.Status != "accepted" { | |
| 469 | + | if onlyAccepted && req.Status != StatusAccepted { | |
| 470 | 470 | continue | |
| 471 | 471 | } | |
| 472 | 472 | ||
| 473 | - | if onlyClosed && req.Status != "closed" { | |
| 473 | + | if onlyClosed && req.Status != StatusClosed { | |
| 474 | 474 | continue | |
| 475 | 475 | } | |
| 476 | 476 | ||
| 477 | - | if onlyOpen && req.Status != "open" { | |
| 477 | + | if onlyOpen && req.Status != StatusOpen { | |
| 478 | 478 | continue | |
| 479 | 479 | } | |
| 480 | 480 |
| ... | ... | @@ -640,11 +640,11 @@ To get started, submit a new patch request: | |
| 640 | 640 | return fmt.Errorf("you are not authorized to accept a PR") | |
| 641 | 641 | } | |
| 642 | 642 | ||
| 643 | - | if prq.Status == "accepted" { | |
| 643 | + | if prq.Status == StatusAccepted { | |
| 644 | 644 | return fmt.Errorf("PR has already been accepted") | |
| 645 | 645 | } | |
| 646 | 646 | ||
| 647 | - | err = pr.UpdatePatchRequestStatus(prID, user.ID, "accepted") | |
| 647 | + | err = pr.UpdatePatchRequestStatus(prID, user.ID, StatusAccepted) | |
| 648 | 648 | if err != nil { | |
| 649 | 649 | return err | |
| 650 | 650 | } |
| ... | ... | @@ -769,7 +769,7 @@ To get started, submit a new patch request: | |
| 769 | 769 | return err | |
| 770 | 770 | } | |
| 771 | 771 | ||
| 772 | - | err = pr.UpdatePatchRequestStatus(prID, user.ID, "open") | |
| 772 | + | err = pr.UpdatePatchRequestStatus(prID, user.ID, StatusOpen) | |
| 773 | 773 | if err == nil { | |
| 774 | 774 | wish.Printf(sesh, "Reopened PR %s (#%d)\n", prq.Name, prq.ID) | |
| 775 | 775 | } |
| ... | ... | @@ -887,17 +887,17 @@ To get started, submit a new patch request: | |
| 887 | 887 | } | |
| 888 | 888 | ||
| 889 | 889 | op := OpNormal | |
| 890 | - | nextStatus := "open" | |
| 890 | + | nextStatus := StatusOpen | |
| 891 | 891 | if isReview { | |
| 892 | 892 | wish.Println(sesh, "Marking patchset as a review") | |
| 893 | 893 | op = OpReview | |
| 894 | 894 | } else if isAccept { | |
| 895 | 895 | wish.Println(sesh, "Marking PR as accepted") | |
| 896 | - | nextStatus = "accepted" | |
| 896 | + | nextStatus = StatusAccepted | |
| 897 | 897 | op = OpAccept | |
| 898 | 898 | } else if isClose { | |
| 899 | 899 | wish.Println(sesh, "Marking PR as closed") | |
| 900 | - | nextStatus = "closed" | |
| 900 | + | nextStatus = StatusClosed | |
| 901 | 901 | op = OpClose | |
| 902 | 902 | } | |
| 903 | 903 |
+10
-1
models.go
#
| ... | ... | @@ -7,6 +7,15 @@ import ( | |
| 7 | 7 | "github.com/bluekeyes/go-gitdiff/gitdiff" | |
| 8 | 8 | ) | |
| 9 | 9 | ||
| 10 | + | type Status string | |
| 11 | + | ||
| 12 | + | const ( | |
| 13 | + | StatusOpen Status = "open" | |
| 14 | + | StatusClosed Status = "closed" | |
| 15 | + | StatusAccepted Status = "accepted" | |
| 16 | + | StatusReviewed Status = "reviewed" | |
| 17 | + | ) | |
| 18 | + | ||
| 10 | 19 | // User is a db model for users. | |
| 11 | 20 | type User struct { | |
| 12 | 21 | ID int64 `db:"id"` |
| ... | ... | @@ -41,7 +50,7 @@ type PatchRequest struct { | |
| 41 | 50 | RepoID int64 `db:"repo_id"` | |
| 42 | 51 | Name string `db:"name"` | |
| 43 | 52 | Text string `db:"text"` | |
| 44 | - | Status string `db:"status"` | |
| 53 | + | Status Status `db:"status"` | |
| 45 | 54 | CreatedAt time.Time `db:"created_at"` | |
| 46 | 55 | UpdatedAt time.Time `db:"updated_at"` | |
| 47 | 56 | // only used for aggregate queries |
+2
-2
pr.go
#
| ... | ... | @@ -43,7 +43,7 @@ type GitPatchRequest interface { | |
| 43 | 43 | GetPatchsetByID(patchsetID int64) (*Patchset, error) | |
| 44 | 44 | GetLatestPatchsetByPrID(prID int64) (*Patchset, error) | |
| 45 | 45 | GetPatchesByPatchsetID(prID int64) ([]*Patch, error) | |
| 46 | - | UpdatePatchRequestStatus(prID, userID int64, status string) error | |
| 46 | + | UpdatePatchRequestStatus(prID, userID int64, status Status) error | |
| 47 | 47 | UpdatePatchRequestName(prID, userID int64, name string) error | |
| 48 | 48 | DeletePatchsetByID(userID, prID int64, patchsetID int64) error | |
| 49 | 49 | CreateEventLog(tx *sqlx.Tx, eventLog EventLog) error |
| ... | ... | @@ -293,7 +293,7 @@ func (cmd PrCmd) GetPatchRequestByID(prID int64) (*PatchRequest, error) { | |
| 293 | 293 | } | |
| 294 | 294 | ||
| 295 | 295 | // Status types: open, closed, accepted, reviewed. | |
| 296 | - | func (cmd PrCmd) UpdatePatchRequestStatus(prID int64, userID int64, status string) error { | |
| 296 | + | func (cmd PrCmd) UpdatePatchRequestStatus(prID int64, userID int64, status Status) error { | |
| 297 | 297 | tx, err := cmd.Backend.DB.Beginx() | |
| 298 | 298 | if err != nil { | |
| 299 | 299 | return err |
+6
-6
web.go
#
| ... | ... | @@ -145,8 +145,8 @@ type RepoDetailData struct { | |
| 145 | 145 | func createPrDataSorter(sort, sortDir string) func(a, b *PrListData) int { | |
| 146 | 146 | return func(a *PrListData, b *PrListData) int { | |
| 147 | 147 | if sort == "status" { | |
| 148 | - | statusA := strings.ToLower(a.Status) | |
| 149 | - | statusB := strings.ToLower(b.Status) | |
| 148 | + | statusA := strings.ToLower(string(a.Status)) | |
| 149 | + | statusB := strings.ToLower(string(b.Status)) | |
| 150 | 150 | if sortDir == "asc" { | |
| 151 | 151 | return strings.Compare(statusA, statusB) | |
| 152 | 152 | } else { |
| ... | ... | @@ -191,9 +191,9 @@ func createPrDataSorter(sort, sortDir string) func(a, b *PrListData) int { | |
| 191 | 191 | ||
| 192 | 192 | func getPrTableData(web *WebCtx, prs []*PatchRequest, query url.Values) ([]*PrListData, error) { | |
| 193 | 193 | prdata := []*PrListData{} | |
| 194 | - | status := strings.ToLower(query.Get("status")) | |
| 194 | + | status := Status(strings.ToLower(query.Get("status"))) | |
| 195 | 195 | if status == "" { | |
| 196 | - | status = "open" | |
| 196 | + | status = StatusOpen | |
| 197 | 197 | } | |
| 198 | 198 | username := strings.ToLower(query.Get("user")) | |
| 199 | 199 | title := strings.ToLower(query.Get("title")) |