- commit
- 68e303f
- parent
- 48e8c7f
- author
- Eric Bower
- date
- 2024-05-31 09:52:08 -0400 EDT
fix: contributors are allowed to close their own PRs
1 files changed,
+23,
-6
M
cli.go
M
cli.go
+23,
-6
1@@ -275,8 +275,10 @@ Here's how it works:
2 if err != nil {
3 return err
4 }
5- if !be.IsAdmin(sesh.PublicKey()) {
6- return fmt.Errorf("must be admin to accpet PR")
7+
8+ isAdmin := be.IsAdmin(sesh.PublicKey())
9+ if !isAdmin {
10+ return fmt.Errorf("you are not authorized to accept a PR")
11 }
12 err = pr.UpdatePatchRequest(prID, "accept")
13 return err
14@@ -290,8 +292,15 @@ Here's how it works:
15 if err != nil {
16 return err
17 }
18- if !be.IsAdmin(sesh.PublicKey()) {
19- return fmt.Errorf("must be admin to close PR")
20+ patchReq, err := pr.GetPatchRequestByID(prID)
21+ if err != nil {
22+ return err
23+ }
24+ pk := sesh.PublicKey()
25+ isContrib := be.Pubkey(pk) == patchReq.Pubkey
26+ isAdmin := be.IsAdmin(pk)
27+ if !isAdmin && !isContrib {
28+ return fmt.Errorf("you are not authorized to change PR status")
29 }
30 err = pr.UpdatePatchRequest(prID, "close")
31 return err
32@@ -305,9 +314,17 @@ Here's how it works:
33 if err != nil {
34 return err
35 }
36- if !be.IsAdmin(sesh.PublicKey()) {
37- return fmt.Errorf("must be admin to close PR")
38+ patchReq, err := pr.GetPatchRequestByID(prID)
39+ if err != nil {
40+ return err
41 }
42+ pk := sesh.PublicKey()
43+ isContrib := be.Pubkey(pk) == patchReq.Pubkey
44+ isAdmin := be.IsAdmin(pk)
45+ if !isAdmin && !isContrib {
46+ return fmt.Errorf("you are not authorized to change PR status")
47+ }
48+
49 err = pr.UpdatePatchRequest(prID, "open")
50 return err
51 },