@@ -275,11 +275,11 @@ func (s service) GetDiff(ctx context.Context, repo string, id uint64, opt *chang
func (s service) ListTimeline(ctx context.Context, repo string, id uint64, opt *change.ListTimelineOptions) ([]interface{}, error) {
// TODO: Pagination. Respect opt.Start and opt.Length, if given.
project := project(repo)
chg, resp, err := s.cl.Changes.GetChangeDetail(fmt.Sprintf("%s~%d", project, id), &gerrit.ChangeOptions{
AdditionalFields: []string{"CURRENT_REVISION"},
AdditionalFields: []string{"ALL_REVISIONS"},
})
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, os.ErrNotExist
}
@@ -299,10 +299,11 @@ func (s service) ListTimeline(ctx context.Context, repo string, id uint64, opt *
User: s.gerritUser(chg.Owner),
CreatedAt: chg.Created.Time,
Body: commitMessageBody(commit.Message),
Editable: false,
})
var mergedRevisionSHA string // Set to merged revision SHA when a change.MergedEvent event is encountered.
for idx, message := range chg.Messages {
if strings.HasPrefix(message.Tag, "autogenerated:") {
Outer:
switch message.Tag[len("autogenerated:"):] {
case "gerrit:merged":
@@ -312,10 +313,11 @@ func (s service) ListTimeline(ctx context.Context, repo string, id uint64, opt *
Payload: change.MergedEvent{
CommitID: chg.CurrentRevision,
RefName: chg.Branch,
},
})
mergedRevisionSHA = chg.CurrentRevision
case "gerrit:newPatchSet":
// Parse a new patchset message, check if it has comments.
body, err := parsePSMessage(message.Message, message.RevisionNumber)
if err != nil {
return nil, err
@@ -427,10 +429,25 @@ func (s service) ListTimeline(ctx context.Context, repo string, id uint64, opt *
Body: body,
Editable: false,
Comments: cs,
})
}
for sha, r := range chg.Revisions {
if r.Number == 1 || sha == mergedRevisionSHA {
// Skip first revision because it's equal to the change itself, and
// skip merged revision because it's equal to the change.MergedEvent.
continue
}
timeline = append(timeline, change.TimelineItem{
Actor: s.gerritUser(r.Uploader),
CreatedAt: r.Created.Time,
Payload: change.CommitEvent{
SHA: sha,
Subject: fmt.Sprintf("Patch Set %d", r.Number),
},
})
}
return timeline, nil
}
func parseMessage(m string) (labels string, body string, ok bool) {
// "Patch Set ".