- commit
- 4a84a43
- parent
- 8f4f074
- author
- Eric Bower
- date
- 2024-07-02 15:12:25 -0400 EDT
style(web): highlight admin style(cli): add more info to lists
3 files changed,
+47,
-5
M
cli.go
+23,
-4
1@@ -88,12 +88,15 @@ Here's how it works:
2 return err
3 }
4 writer := NewTabWriter(sesh)
5- fmt.Fprintln(writer, "ID")
6+ fmt.Fprintln(writer, "ID\tDefBranch\tClone\tDesc")
7 for _, repo := range repos {
8 fmt.Fprintf(
9 writer,
10- "%s\n",
11+ "%s\t%s\t%s\t%s\n",
12 utils.SanitizeRepo(repo.ID),
13+ repo.DefaultBranch,
14+ repo.CloneAddr,
15+ repo.Desc,
16 )
17 }
18 writer.Flush()
19@@ -175,6 +178,10 @@ Here's how it works:
20 Name: "accepted",
21 Usage: "only show accepted PRs",
22 },
23+ &cli.StringFlag{
24+ Name: "repo",
25+ Usage: "only show PRs by Repo ID",
26+ },
27 },
28 Action: func(cCtx *cli.Context) error {
29 repoID := cCtx.Args().First()
30@@ -191,10 +198,15 @@ Here's how it works:
31
32 onlyAccepted := cCtx.Bool("accepted")
33 onlyClosed := cCtx.Bool("closed")
34+ onlyRepoID := cCtx.String("repo")
35
36 writer := NewTabWriter(sesh)
37- fmt.Fprintln(writer, "ID\tRepoID\tName\tStatus\tDate")
38+ fmt.Fprintln(writer, "ID\tRepoID\tName\tStatus\tUser\tDate")
39 for _, req := range prs {
40+ if onlyRepoID != "" && req.RepoID != onlyRepoID {
41+ continue
42+ }
43+
44 if onlyAccepted && req.Status != "accepted" {
45 continue
46 }
47@@ -207,13 +219,20 @@ Here's how it works:
48 continue
49 }
50
51+ user, err := pr.GetUserByID(req.UserID)
52+ if err != nil {
53+ be.Logger.Error("could not get user for pr", "err", err)
54+ continue
55+ }
56+
57 fmt.Fprintf(
58 writer,
59- "%d\t%s\t%s\t[%s]\t%s\n",
60+ "%d\t%s\t%s\t[%s]\t%s\t%s\n",
61 req.ID,
62 req.RepoID,
63 req.Name,
64 req.Status,
65+ user.Name,
66 req.CreatedAt.Format(time.RFC3339Nano),
67 )
68 }
+1,
-1
1@@ -7,7 +7,7 @@
2 <div>
3 <code>#{{.ID}}</code>
4 <span>opened on <date>{{.Date}}</date> by </span>
5- <code title="{{.Pubkey}}">{{.UserName}}</code>
6+ <code class="{{if .IsAdmin}}pill-alert{{end}}" title="{{.Pubkey}}">{{.UserName}}</code>
7 </div>
8 </div>
9 {{end}}
M
web.go
+23,
-0
1@@ -112,8 +112,15 @@ func repoListHandler(w http.ResponseWriter, r *http.Request) {
2 var ls *PrListData
3 if repo.PatchRequest != nil {
4 curpr := repo.PatchRequest
5+ pk, err := web.Backend.PubkeyToPublicKey(repo.User.Pubkey)
6+ if err != nil {
7+ w.WriteHeader(http.StatusUnprocessableEntity)
8+ return
9+ }
10+ isAdmin := web.Backend.IsAdmin(pk)
11 ls = &PrListData{
12 ID: curpr.ID,
13+ IsAdmin: isAdmin,
14 UserName: repo.User.Name,
15 Pubkey: repo.User.Pubkey,
16 LinkData: LinkData{
17@@ -149,6 +156,7 @@ func repoListHandler(w http.ResponseWriter, r *http.Request) {
18 type PrListData struct {
19 LinkData
20 ID int64
21+ IsAdmin bool
22 UserName string
23 Pubkey string
24 Date string
25@@ -198,8 +206,15 @@ func repoDetailHandler(w http.ResponseWriter, r *http.Request) {
26 if err != nil {
27 continue
28 }
29+ pk, err := web.Backend.PubkeyToPublicKey(user.Pubkey)
30+ if err != nil {
31+ w.WriteHeader(http.StatusUnprocessableEntity)
32+ return
33+ }
34+ isAdmin := web.Backend.IsAdmin(pk)
35 ls := PrListData{
36 ID: curpr.ID,
37+ IsAdmin: isAdmin,
38 UserName: user.Name,
39 Pubkey: user.Pubkey,
40 LinkData: LinkData{
41@@ -496,6 +511,14 @@ func StartWebServer(cfg *GitCfg) {
42 Formatter: formatter,
43 Theme: styles.Get("dracula"),
44 }
45+
46+ keys, err := getAuthorizedKeys(filepath.Join(cfg.DataPath, "authorized_keys"))
47+ if err == nil {
48+ cfg.Admins = keys
49+ } else {
50+ logger.Error("could not parse authorized keys file", "err", err)
51+ }
52+
53 ctx := context.Background()
54 ctx = setWebCtx(ctx, web)
55