- commit
- 821d0e5
- parent
- 02d2f96
- author
- Eric Bower
- date
- 2024-06-24 16:17:54 -0400 EDT
feat: ability to change PR title
M
cli.go
+47,
-6
1@@ -4,6 +4,7 @@ import (
2 "fmt"
3 "io"
4 "strconv"
5+ "strings"
6 "text/tabwriter"
7 "time"
8
9@@ -439,7 +440,7 @@ Here's how it works:
10 return fmt.Errorf("PR has already been accepted")
11 }
12
13- err = pr.UpdatePatchRequest(prID, pubkey, "accepted")
14+ err = pr.UpdatePatchRequestStatus(prID, pubkey, "accepted")
15 if err == nil {
16 wish.Printf(sesh, "Accepted PR %s (#%d)\n", patchReq.Name, patchReq.ID)
17 }
18@@ -471,7 +472,7 @@ Here's how it works:
19 return fmt.Errorf("PR has already been closed")
20 }
21
22- err = pr.UpdatePatchRequest(prID, pubkey, "closed")
23+ err = pr.UpdatePatchRequestStatus(prID, pubkey, "closed")
24 if err == nil {
25 wish.Printf(sesh, "Closed PR %s (#%d)\n", patchReq.Name, patchReq.ID)
26 }
27@@ -503,7 +504,7 @@ Here's how it works:
28 return fmt.Errorf("PR is already open")
29 }
30
31- err = pr.UpdatePatchRequest(prID, pubkey, "open")
32+ err = pr.UpdatePatchRequestStatus(prID, pubkey, "open")
33 if err == nil {
34 wish.Printf(sesh, "Reopened PR %s (#%d)\n", patchReq.Name, patchReq.ID)
35 }
36@@ -511,8 +512,48 @@ Here's how it works:
37 },
38 },
39 {
40- Name: "add",
41- Usage: "Append a patch to a PR",
42+ Name: "edit",
43+ Usage: "Edit PR title",
44+ Args: true,
45+ ArgsUsage: "[prID] [title]",
46+ Action: func(cCtx *cli.Context) error {
47+ prID, err := getPrID(cCtx.Args().First())
48+ if err != nil {
49+ return err
50+ }
51+ prq, err := pr.GetPatchRequestByID(prID)
52+ if err != nil {
53+ return err
54+ }
55+ isAdmin := be.IsAdmin(sesh.PublicKey())
56+ isPrOwner := be.IsPrOwner(prq.Pubkey, be.Pubkey(sesh.PublicKey()))
57+ if !isAdmin && !isPrOwner {
58+ return fmt.Errorf("unauthorized, you are not the owner of this PR")
59+ }
60+
61+ tail := cCtx.Args().Tail()
62+ title := strings.Join(tail, " ")
63+ if title == "" {
64+ return fmt.Errorf("must provide title")
65+ }
66+
67+ err = pr.UpdatePatchRequestName(
68+ prID,
69+ be.Pubkey(sesh.PublicKey()),
70+ title,
71+ )
72+ if err == nil {
73+ wish.Printf(sesh, "New title: %s (%d)\n", title, prq.ID)
74+ }
75+
76+ return err
77+ },
78+ },
79+ {
80+ Name: "add",
81+ Usage: "Append a patch to a PR",
82+ Args: true,
83+ ArgsUsage: "[prID]",
84 Flags: []cli.Flag{
85 &cli.BoolFlag{
86 Name: "review",
87@@ -562,7 +603,7 @@ Here's how it works:
88
89 reviewTxt := ""
90 if isReview {
91- err = pr.UpdatePatchRequest(prID, pubkey, "reviewed")
92+ err = pr.UpdatePatchRequestStatus(prID, pubkey, "reviewed")
93 if err != nil {
94 return err
95 }
M
pr.go
+23,
-3
1@@ -33,7 +33,8 @@ type GitPatchRequest interface {
2 GetPatchRequests() ([]*PatchRequest, error)
3 GetPatchRequestsByRepoID(repoID string) ([]*PatchRequest, error)
4 GetPatchesByPrID(prID int64) ([]*Patch, error)
5- UpdatePatchRequest(prID int64, pubkey, status string) error
6+ UpdatePatchRequestStatus(prID int64, pubkey, status string) error
7+ UpdatePatchRequestName(prID int64, pubkey, name string) error
8 DeletePatchesByPrID(prID int64) error
9 CreateEventLog(eventLog EventLog) error
10 GetEventLogs() ([]*EventLog, error)
11@@ -161,7 +162,7 @@ func (cmd PrCmd) GetPatchRequestByID(prID int64) (*PatchRequest, error) {
12 }
13
14 // Status types: open, closed, accepted, reviewed.
15-func (cmd PrCmd) UpdatePatchRequest(prID int64, pubkey string, status string) error {
16+func (cmd PrCmd) UpdatePatchRequestStatus(prID int64, pubkey string, status string) error {
17 _, err := cmd.Backend.DB.Exec(
18 "UPDATE patch_requests SET status=? WHERE id=?",
19 status,
20@@ -176,6 +177,25 @@ func (cmd PrCmd) UpdatePatchRequest(prID int64, pubkey string, status string) er
21 return err
22 }
23
24+func (cmd PrCmd) UpdatePatchRequestName(prID int64, pubkey string, name string) error {
25+ if name == "" {
26+ return fmt.Errorf("must provide name or text in order to update patch request")
27+ }
28+
29+ _, err := cmd.Backend.DB.Exec(
30+ "UPDATE patch_requests SET name=? WHERE id=?",
31+ name,
32+ prID,
33+ )
34+ _ = cmd.CreateEventLog(EventLog{
35+ Pubkey: pubkey,
36+ PatchRequestID: prID,
37+ Event: "pr_name_changed",
38+ Data: fmt.Sprintf(`{"name":"%s"}`, name),
39+ })
40+ return err
41+}
42+
43 func (cmd PrCmd) CreateEventLog(eventLog EventLog) error {
44 if eventLog.RepoID == "" && eventLog.PatchRequestID != 0 {
45 var pr PatchRequest
46@@ -195,7 +215,7 @@ func (cmd PrCmd) CreateEventLog(eventLog EventLog) error {
47 }
48
49 _, err := cmd.Backend.DB.Exec(
50- "INSERT INTO event_logs (pubkey, repo_id, patch_request_id, event, data) VALUES (?, ?, ?, ?, ?, ?)",
51+ "INSERT INTO event_logs (pubkey, repo_id, patch_request_id, event, data) VALUES (?, ?, ?, ?, ?)",
52 eventLog.Pubkey,
53 eventLog.RepoID,
54 eventLog.PatchRequestID,