@@ -44,24 +44,35 @@ type CommentThread struct {
44
44
Resolved * bool `json:"resolved,omitempty"`
45
45
}
46
46
47
- // Review represents the entire state of a code review.
47
+ // ReviewSummary represents the high-level state of a code review.
48
+ //
49
+ // This high-level state corresponds to the data that can be quickly read
50
+ // directly from the repo, so other methods that need to operate on a lot
51
+ // of reviews (such as listing the open reviews) should prefer operating on
52
+ // the summary rather than the details.
48
53
//
49
- // Reviews have two status fields which are orthogonal:
54
+ // Review summaries have two status fields which are orthogonal:
50
55
// 1. Resolved indicates if a reviewer has accepted or rejected the change.
51
56
// 2. Submitted indicates if the change has been incorporated into the target.
57
+ type ReviewSummary struct {
58
+ Repo repository.Repo `json:"-"`
59
+ Revision string `json:"revision"`
60
+ Request request.Request `json:"request"`
61
+ Comments []CommentThread `json:"comments,omitempty"`
62
+ Resolved * bool `json:"resolved,omitempty"`
63
+ Submitted bool `json:"submitted"`
64
+ }
65
+
66
+ // Review represents the entire state of a code review.
52
67
//
53
- // Reviews also include a list of build-and-test status reports. Those
68
+ // This extends ReviewSummary to also include a list of reports for both the
69
+ // continuous integration status, and the static analysis runs. Those reports
54
70
// correspond to either the current commit in the review ref (for pending
55
71
// reviews), or to the last commented-upon commit (for submitted reviews).
56
72
type Review struct {
57
- Repo repository.Repo `json:"-"`
58
- Revision string `json:"revision"`
59
- Request request.Request `json:"request"`
60
- Comments []CommentThread `json:"comments,omitempty"`
61
- Resolved * bool `json:"resolved,omitempty"`
62
- Submitted bool `json:"submitted"`
63
- Reports []ci.Report `json:"reports,omitempty"`
64
- Analyses []analyses.Report `json:"analyses,omitempty"`
73
+ * ReviewSummary
74
+ Reports []ci.Report `json:"reports,omitempty"`
75
+ Analyses []analyses.Report `json:"analyses,omitempty"`
65
76
}
66
77
67
78
type byTimestamp []CommentThread
@@ -173,46 +184,68 @@ func buildCommentThreads(commentsByHash map[string]comment.Comment) []CommentThr
173
184
174
185
// loadComments reads in the log-structured sequence of comments for a review,
175
186
// and then builds the corresponding tree-structured comment threads.
176
- func (r * Review ) loadComments () []CommentThread {
187
+ func (r * ReviewSummary ) loadComments () []CommentThread {
177
188
commentNotes := r .Repo .GetNotes (comment .Ref , r .Revision )
178
189
commentsByHash := comment .ParseAllValid (commentNotes )
179
190
return buildCommentThreads (commentsByHash )
180
191
}
181
192
182
- // Get returns the specified code review.
193
+ // Get returns the summary of the specified code review.
183
194
//
184
- // If no review request exists, the returned review is nil.
185
- func Get (repo repository.Repo , revision string ) (* Review , error ) {
195
+ // If no review request exists, the returned review summary is nil.
196
+ func GetSummary (repo repository.Repo , revision string ) (* ReviewSummary , error ) {
186
197
requestNotes := repo .GetNotes (request .Ref , revision )
187
198
requests := request .ParseAllValid (requestNotes )
188
199
if requests == nil {
189
200
return nil , nil
190
201
}
191
- review := Review {
202
+ reviewSummary := ReviewSummary {
192
203
Repo : repo ,
193
204
Revision : revision ,
194
205
Request : requests [len (requests )- 1 ],
195
206
}
196
- review .Comments = review .loadComments ()
197
- review .Resolved = updateThreadsStatus (review .Comments )
198
- submitted , err := repo .IsAncestor (revision , review .Request .TargetRef )
207
+ reviewSummary .Comments = reviewSummary .loadComments ()
208
+ reviewSummary .Resolved = updateThreadsStatus (reviewSummary .Comments )
209
+ submitted , err := repo .IsAncestor (revision , reviewSummary .Request .TargetRef )
199
210
if err != nil {
200
211
return nil , err
201
212
}
202
- review .Submitted = submitted
213
+ reviewSummary .Submitted = submitted
214
+ return & reviewSummary , nil
215
+ }
216
+
217
+ // Details returns the detailed review for the given summary.
218
+ func (r * ReviewSummary ) Details () (* Review , error ) {
219
+ review := Review {
220
+ ReviewSummary : r ,
221
+ }
203
222
currentCommit , err := review .GetHeadCommit ()
204
223
if err == nil {
205
- review .Reports = ci .ParseAllValid (repo .GetNotes (ci .Ref , currentCommit ))
206
- review .Analyses = analyses .ParseAllValid (repo .GetNotes (analyses .Ref , currentCommit ))
224
+ review .Reports = ci .ParseAllValid (review . Repo .GetNotes (ci .Ref , currentCommit ))
225
+ review .Analyses = analyses .ParseAllValid (review . Repo .GetNotes (analyses .Ref , currentCommit ))
207
226
}
208
227
return & review , nil
209
228
}
210
229
230
+ // Get returns the specified code review.
231
+ //
232
+ // If no review request exists, the returned review is nil.
233
+ func Get (repo repository.Repo , revision string ) (* Review , error ) {
234
+ summary , err := GetSummary (repo , revision )
235
+ if err != nil {
236
+ return nil , err
237
+ }
238
+ if summary == nil {
239
+ return nil , nil
240
+ }
241
+ return summary .Details ()
242
+ }
243
+
211
244
// ListAll returns all reviews stored in the git-notes.
212
- func ListAll (repo repository.Repo ) []Review {
213
- var reviews []Review
245
+ func ListAll (repo repository.Repo ) []ReviewSummary {
246
+ var reviews []ReviewSummary
214
247
for _ , revision := range repo .ListNotedRevisions (request .Ref ) {
215
- review , err := Get (repo , revision )
248
+ review , err := GetSummary (repo , revision )
216
249
if err == nil && review != nil {
217
250
reviews = append (reviews , * review )
218
251
}
@@ -221,8 +254,8 @@ func ListAll(repo repository.Repo) []Review {
221
254
}
222
255
223
256
// ListOpen returns all reviews that are not yet incorporated into their target refs.
224
- func ListOpen (repo repository.Repo ) []Review {
225
- var openReviews []Review
257
+ func ListOpen (repo repository.Repo ) []ReviewSummary {
258
+ var openReviews []ReviewSummary
226
259
for _ , review := range ListAll (repo ) {
227
260
if ! review .Submitted {
228
261
openReviews = append (openReviews , review )
@@ -239,7 +272,7 @@ func GetCurrent(repo repository.Repo) (*Review, error) {
239
272
if err != nil {
240
273
return nil , err
241
274
}
242
- var matchingReviews []Review
275
+ var matchingReviews []ReviewSummary
243
276
for _ , review := range ListOpen (repo ) {
244
277
if review .Request .ReviewRef == reviewRef {
245
278
matchingReviews = append (matchingReviews , review )
@@ -251,8 +284,7 @@ func GetCurrent(repo repository.Repo) (*Review, error) {
251
284
if len (matchingReviews ) != 1 {
252
285
return nil , fmt .Errorf ("There are %d open reviews for the ref \" %s\" " , len (matchingReviews ), reviewRef )
253
286
}
254
- r := & matchingReviews [0 ]
255
- return r , nil
287
+ return matchingReviews [0 ].Details ()
256
288
}
257
289
258
290
// GetBuildStatusMessage returns a string of the current build-and-test status
0 commit comments