- commit
- 7fda3e7
- parent
- 220e877
- author
- Eric Bower
- date
- 2024-05-09 23:10:58 -0400 EDT
progress
M
db.go
+4,
-2
1@@ -28,10 +28,11 @@ type Patch struct {
2 PatchRequestID int64 `db:"patch_request_id"`
3 AuthorName string `db:"author_name"`
4 AuthorEmail string `db:"author_email"`
5+ AuthorDate time.Time `db:"author_date"`
6 Title string `db:"title"`
7 Body string `db:"body"`
8+ BodyAppendix string `db:"body_appendix"`
9 CommitSha string `db:"commit_sha"`
10- CommitDate time.Time `db:"commit_date"`
11 Review bool `db:"review"`
12 RawText string `db:"raw_text"`
13 CreatedAt time.Time `db:"created_at"`
14@@ -74,10 +75,11 @@ CREATE TABLE IF NOT EXISTS patches (
15 patch_request_id INTEGER NOT NULL,
16 author_name TEXT NOT NULL,
17 author_email TEXT NOT NULL,
18+ author_date DATETIME NOT NULL,
19 title TEXT NOT NULL,
20 body TEXT NOT NULL,
21+ body_appendix TEXT NOT NULL,
22 commit_sha TEXT NOT NULL,
23- commit_date DATETIME NOT NULL,
24 review BOOLEAN NOT NULL DEFAULT false,
25 raw_text TEXT NOT NULL,
26 created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
M
mdw.go
+58,
-29
1@@ -71,6 +71,7 @@ type GitPatchRequest interface {
2 GetRepos() ([]string, error)
3 SubmitPatchRequest(pubkey string, repoID string, patches io.Reader) (*PatchRequest, error)
4 SubmitPatch(pubkey string, prID int64, review bool, patch io.Reader) (*Patch, error)
5+ GetPatchRequestByID(prID int64) (*PatchRequest, error)
6 GetPatchRequests() ([]*PatchRequest, error)
7 GetPatchesByPrID(prID int64) ([]*Patch, error)
8 UpdatePatchRequest(prID int64, status string) error
9@@ -122,6 +123,16 @@ func (cmd PrCmd) GetPatchRequests() ([]*PatchRequest, error) {
10 return prs, err
11 }
12
13+func (cmd PrCmd) GetPatchRequestByID(prID int64) (*PatchRequest, error) {
14+ pr := PatchRequest{}
15+ err := cmd.Backend.DB.Get(
16+ &pr,
17+ "SELECT * FROM patch_requests WHERE id=?",
18+ prID,
19+ )
20+ return &pr, err
21+}
22+
23 // status types: open, close, accept, review
24 func (cmd PrCmd) UpdatePatchRequest(prID int64, status string) error {
25 _, err := cmd.Backend.DB.Exec(
26@@ -152,15 +163,16 @@ func (cmd PrCmd) SubmitPatch(pubkey string, prID int64, review bool, patch io.Re
27
28 patchID := 0
29 row := cmd.Backend.DB.QueryRow(
30- "INSERT INTO patches (pubkey, patch_request_id, author_name, author_email, title, body, commit_sha, commit_date, review, raw_text) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
31+ "INSERT INTO patches (pubkey, patch_request_id, author_name, author_email, author_date, title, body, body_appendix, commit_sha, review, raw_text) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id",
32 pubkey,
33 prID,
34 header.Author.Name,
35 header.Author.Email,
36+ header.AuthorDate,
37 header.Title,
38 header.Body,
39+ header.BodyAppendix,
40 header.SHA,
41- header.CommitterDate,
42 review,
43 buf.String(),
44 )
45@@ -219,15 +231,16 @@ func (cmd PrCmd) SubmitPatchRequest(pubkey string, repoID string, patches io.Rea
46 }
47
48 _, err = cmd.Backend.DB.Exec(
49- "INSERT INTO patches (pubkey, patch_request_id, author_name, author_email, title, body, commit_sha, commit_date, raw_text) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
50+ "INSERT INTO patches (pubkey, patch_request_id, author_name, author_email, author_date, title, body, body_appendix, commit_sha, raw_text) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
51 pubkey,
52 prID,
53 header.Author.Name,
54 header.Author.Email,
55+ header.AuthorDate,
56 header.Title,
57 header.Body,
58+ header.BodyAppendix,
59 header.SHA,
60- header.CommitterDate,
61 buf.String(),
62 )
63 if err != nil {
64@@ -333,41 +346,57 @@ func GitPatchRequestMiddleware(be *Backend, pr GitPatchRequest) wish.Middleware
65 }
66 wish.Printf(sesh, "Patch Request submitted! Use the ID for interacting with this Patch Request.\nID\tName\n%d\t%s\n", request.ID, request.Name)
67 } else if subCmd == "patchRequest" {
68- if *out {
69+ if *stats {
70+ request, err := pr.GetPatchRequestByID(prID)
71+ if err != nil {
72+ wish.Fatalln(sesh, err)
73+ return
74+ }
75+
76+ wish.Printf(sesh, "%s\t[%s]\n%s\n%s\n%s\n", request.Name, request.Status, request.CreatedAt.Format(time.RFC3339Nano), request.Pubkey, request.Text)
77+
78 patches, err := pr.GetPatchesByPrID(prID)
79 if err != nil {
80 wish.Fatalln(sesh, err)
81 return
82 }
83
84- if *stats {
85- for _, patch := range patches {
86- reviewTxt := ""
87- if patch.Review {
88- reviewTxt = "[R]"
89- }
90- wish.Printf(
91- sesh,
92- "%s %s\n%s <%s>\n%s\n%s\n---\n",
93- patch.Title,
94- reviewTxt,
95- patch.AuthorName,
96- patch.AuthorEmail,
97- patch.CommitDate.Format(time.RFC3339Nano),
98- patch.Body,
99- )
100- }
101- } else {
102- if len(patches) == 1 {
103- wish.Println(sesh, patches[0].RawText)
104- return
105+ for _, patch := range patches {
106+ reviewTxt := ""
107+ if patch.Review {
108+ reviewTxt = "[review]"
109 }
110+ wish.Printf(
111+ sesh,
112+ "%s %s %s\n%s <%s>\n%s\n\n---\n%s\n%s\n",
113+ patch.Title,
114+ reviewTxt,
115+ patch.CommitSha,
116+ patch.AuthorName,
117+ patch.AuthorEmail,
118+ patch.AuthorDate.Format(time.RFC3339Nano),
119+ patch.BodyAppendix,
120+ patch.Body,
121+ )
122+ }
123+ return
124+ }
125
126- for _, patch := range patches {
127- wish.Printf(sesh, "%s\n\n\n", patch.RawText)
128- }
129+ if *out {
130+ patches, err := pr.GetPatchesByPrID(prID)
131+ if err != nil {
132+ wish.Fatalln(sesh, err)
133+ return
134 }
135
136+ if len(patches) == 1 {
137+ wish.Println(sesh, patches[0].RawText)
138+ return
139+ }
140+
141+ for _, patch := range patches {
142+ wish.Printf(sesh, "%s\n\n\n", patch.RawText)
143+ }
144 } else if *accept {
145 if !be.IsAdmin(sesh.PublicKey()) {
146 wish.Fatalln(sesh, "must be admin to accept PR")