git-pr

created pr with 3.1 on 2024-07-19T14:53:23Z · by c8ef7d19
added 3.2 on 2024-07-19T14:55:48Z · by c8ef7d19
1: 3b99dc0 < -: ------- feat: static assets
2: 8919af5 ! 1: 66cafc6 feat: static assets folder
3: 7346122 ! 2: 5e76ed3 fix(cli): access control for removing patchsets
4: d8792d5 < -: ------- feat: static folder
pr_reviewed on 2024-07-19T15:42:29Z · by 964fa508
changed status to reviewed on 2024-07-19T15:42:29Z · by 964fa508
added 3.4 on 2024-07-19T17:43:47Z · by c8ef7d19
1: cc56ea1 = 1: 0467f9e feat: static assets folder
2: ef749a4 = 2: da1730f review: typo and future enhancement comment
-: ------- > 3: c038404 refactor: per-file override for static folder
changed status to accepted on 2024-07-19T18:27:53Z · by 964fa508
cmds
checkout latest patchset:
ssh pr.pico.sh print 3 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print 3.[rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 3
set PR to open (enables RSS notifications):
ssh pr.pico.sh pr open 3
set PR to draft (stops RSS notifications):
ssh pr.pico.sh pr draft 3

Patchset 3.2 on 2024-07-19T14:55:48Z · commit 5e76ed3

+30 -6 cli.go #
......@@ -213,7 +213,30 @@ Here's how it works:
213213 if err != nil {
214214 return err
215215 }
216- return pr.DeletePatchsetByID(patchsetID)
216+
217+ patchset, err := pr.GetPatchsetByID(patchsetID)
218+ if err != nil {
219+ return err
220+ }
221+
222+ user, err := pr.GetUserByID(patchset.UserID)
223+ if err != nil {
224+ return err
225+ }
226+
227+ pk := sesh.PublicKey()
228+ isAdmin := be.IsAdmin(pk)
229+ isContrib := pubkey == user.Pubkey
230+ if !isAdmin && !isContrib {
231+ return fmt.Errorf("you are not authorized to delete a patchset")
232+ }
233+
234+ err = pr.DeletePatchsetByID(patchsetID)
235+ if err != nil {
236+ return err
237+ }
238+ wish.Printf(sesh, "successfully removed patchset: %d\n", patchsetID)
239+ return nil
217240 },
218241 },
219242 },
......@@ -597,17 +620,18 @@ Here's how it works:
597620 return err
598621 }
599622
600- user, err := pr.UpsertUser(pubkey, userName)
623+ patchReq, err := pr.GetPatchRequestByID(prID)
601624 if err != nil {
602625 return err
603626 }
604627
605- patchReq, err := pr.GetPatchRequestByID(prID)
628+ user, err := pr.GetUserByID(patchReq.UserID)
606629 if err != nil {
607630 return err
608631 }
632+
609633 pk := sesh.PublicKey()
610- isContrib := be.Pubkey(pk) == user.Pubkey
634+ isContrib := pubkey == user.Pubkey
611635 isAdmin := be.IsAdmin(pk)
612636 if !isAdmin && !isContrib {
613637 return fmt.Errorf("you are not authorized to change PR status")
......@@ -645,13 +669,13 @@ Here's how it works:
645669 return err
646670 }
647671
648- user, err := pr.UpsertUser(pubkey, userName)
672+ user, err := pr.GetUserByID(patchReq.UserID)
649673 if err != nil {
650674 return err
651675 }
652676
653677 pk := sesh.PublicKey()
654- isContrib := be.Pubkey(pk) == user.Pubkey
678+ isContrib := pubkey == user.Pubkey
655679 isAdmin := be.IsAdmin(pk)
656680 if !isAdmin && !isContrib {
657681 return fmt.Errorf("you are not authorized to change PR status")
+11 -0 pr.go #
......@@ -34,6 +34,7 @@ type GitPatchRequest interface {
3434 GetPatchRequests() ([]*PatchRequest, error)
3535 GetPatchRequestsByRepoID(repoID string) ([]*PatchRequest, error)
3636 GetPatchsetsByPrID(prID int64) ([]*Patchset, error)
37+ GetPatchsetByID(patchsetID int64) (*Patchset, error)
3738 GetLatestPatchsetByPrID(prID int64) (*Patchset, error)
3839 GetPatchesByPatchsetID(prID int64) ([]*Patch, error)
3940 UpdatePatchRequestStatus(prID, userID int64, status string) error
......@@ -234,6 +235,16 @@ func (pr PrCmd) GetPatchsetsByPrID(prID int64) ([]*Patchset, error) {
234235 return patchsets, nil
235236 }
236237
238+func (pr PrCmd) GetPatchsetByID(patchsetID int64) (*Patchset, error) {
239+ var patchset Patchset
240+ err := pr.Backend.DB.Get(
241+ &patchset,
242+ "SELECT * FROM patchsets WHERE id=?",
243+ patchsetID,
244+ )
245+ return &patchset, err
246+}
247+
237248 func (pr PrCmd) GetLatestPatchsetByPrID(prID int64) (*Patchset, error) {
238249 patchsets, err := pr.GetPatchsetsByPrID(prID)
239250 if err != nil {
Back to top