dashboard / erock/git-pr / feat: static assets #3 rss

accepted · opened on 2024-07-19T14:53:23Z by erock
Help
checkout latest patchset:
ssh pr.pico.sh print pr-3 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print ps-X | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 3
add review to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add --review 3
accept PR:
ssh pr.pico.sh pr accept 3
close PR:
ssh pr.pico.sh pr close 3

Logs

erock created pr with ps-3 on 2024-07-19T14:53:23Z
erock added ps-4 on 2024-07-19T14:55:48Z
jolheiser reviewed pr with ps-5 on 2024-07-19T15:42:29Z
jolheiser changed status on 2024-07-19T15:42:29Z {"status":"reviewed"}
erock added ps-9 on 2024-07-19T17:43:47Z
jolheiser changed status on 2024-07-19T18:27:53Z {"status":"accepted"}

Patchsets

ps-3 by erock on 2024-07-19T14:53:23Z
Range Diff ↕ rd-4
2: 8919af5 ! 1: 66cafc6 feat: static assets folder
1: 3b99dc0 ! 2: 5e76ed3 fix(cli): access control for removing patchsets
3: 7346122 < -: ------- chore: create patch for smol
4: d8792d5 < -: ------- feat: static folder
ps-4 by erock on 2024-07-19T14:55:48Z
Range Diff ↕ rd-5
1: 66cafc6 = 1: cc56ea1 feat: static assets folder
2: 5e76ed3 < -: ------- fix(cli): access control for removing patchsets
-: ------- > 2: ef749a4 review: typo and future enhancement comment
ps-5 by jolheiser on 2024-07-19T15:42:29Z
Range Diff ↕ rd-9
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
ps-9 by erock on 2024-07-19T17:43:47Z

Range-diff rd-5

title
feat: static assets folder
description
Patch equal
old #1
66cafc6
new #1
cc56ea1
title
fix(cli): access control for removing patchsets
description
Patch removed
old #2
5e76ed3
new #0
(none)
title
review: typo and future enhancement comment
description
Patch added
old #0
(none)
new #2
ef749a4
Back to top
1: 66cafc6 = 1: cc56ea1 feat: static assets folder
2: 5e76ed3 < -: ------- fix(cli): access control for removing patchsets

old

old:cli.go new:cli.go
 							if err != nil {
 								return err
 							}
-							return pr.DeletePatchsetByID(patchsetID)
+
+							patchset, err := pr.GetPatchsetByID(patchsetID)
+							if err != nil {
+								return err
+							}
+
+							user, err := pr.GetUserByID(patchset.UserID)
+							if err != nil {
+								return err
+							}
+
+							pk := sesh.PublicKey()
+							isAdmin := be.IsAdmin(pk)
+							isContrib := pubkey == user.Pubkey
+							if !isAdmin && !isContrib {
+								return fmt.Errorf("you are not authorized to delete a patchset")
+							}
+
+							err = pr.DeletePatchsetByID(patchsetID)
+							if err != nil {
+								return err
+							}
+							wish.Printf(sesh, "successfully removed patchset: %d\n", patchsetID)
+							return nil
 						},
 					},
 				},
 								return err
 							}
 
-							user, err := pr.UpsertUser(pubkey, userName)
+							patchReq, err := pr.GetPatchRequestByID(prID)
 							if err != nil {
 								return err
 							}
 
-							patchReq, err := pr.GetPatchRequestByID(prID)
+							user, err := pr.GetUserByID(patchReq.UserID)
 							if err != nil {
 								return err
 							}
+
 							pk := sesh.PublicKey()
-							isContrib := be.Pubkey(pk) == user.Pubkey
+							isContrib := pubkey == user.Pubkey
 							isAdmin := be.IsAdmin(pk)
 							if !isAdmin && !isContrib {
 								return fmt.Errorf("you are not authorized to change PR status")
 								return err
 							}
 
-							user, err := pr.UpsertUser(pubkey, userName)
+							user, err := pr.GetUserByID(patchReq.UserID)
 							if err != nil {
 								return err
 							}
 
 							pk := sesh.PublicKey()
-							isContrib := be.Pubkey(pk) == user.Pubkey
+							isContrib := pubkey == user.Pubkey
 							isAdmin := be.IsAdmin(pk)
 							if !isAdmin && !isContrib {
 								return fmt.Errorf("you are not authorized to change PR status")

new


                    

old

old:pr.go new:pr.go
 	GetPatchRequests() ([]*PatchRequest, error)
 	GetPatchRequestsByRepoID(repoID string) ([]*PatchRequest, error)
 	GetPatchsetsByPrID(prID int64) ([]*Patchset, error)
+	GetPatchsetByID(patchsetID int64) (*Patchset, error)
 	GetLatestPatchsetByPrID(prID int64) (*Patchset, error)
 	GetPatchesByPatchsetID(prID int64) ([]*Patch, error)
 	UpdatePatchRequestStatus(prID, userID int64, status string) error
 	return patchsets, nil
 }
 
+func (pr PrCmd) GetPatchsetByID(patchsetID int64) (*Patchset, error) {
+	var patchset Patchset
+	err := pr.Backend.DB.Get(
+		&patchset,
+		"SELECT * FROM patchsets WHERE id=?",
+		patchsetID,
+	)
+	return &patchset, err
+}
+
 func (pr PrCmd) GetLatestPatchsetByPrID(prID int64) (*Patchset, error) {
 	patchsets, err := pr.GetPatchsetsByPrID(prID)
 	if err != nil {

new


                    
-: ------- > 2: ef749a4 review: typo and future enhancement comment

old


                    

new

old:web.go new:web.go
 	}
 }
 
+// review(jolheiser):
+// Perhaps in the future this could be extended to support per-file. For example, I may want to override CSS vars without providing an entire static assets.
+// embeded -> embedded
 func getFileSystem(logger *slog.Logger, ffs embed.FS, datadir string, dirName string) (fs.FS, error) {
 	dir := filepath.Join(datadir, dirName)
 	_, err := os.Stat(dir)