dmitri.shuralyov.com/service/change/...

Work on displaying inline comments.
dmitshur committed 6 years ago commit 443f5d5ceff403e50fadc426eb7f844cc0ba3896
Collapse all
gerritapi/gerritapi.go
@@ -250,10 +250,14 @@ func (s service) ListTimeline(ctx context.Context, _ string, id uint64, opt *cha

	change, _, err := s.cl.Changes.GetChangeDetail(fmt.Sprint(id), nil)
	if err != nil {
		return nil, err
	}
	comments, _, err := s.cl.Changes.ListChangeComments(fmt.Sprint(id))
	if err != nil {
		return nil, err
	}
	var timeline []interface{}
	{
		timeline = append(timeline, changes.Comment{
			ID:        0,
			User:      s.gerritUser(change.Owner),
@@ -279,41 +283,39 @@ func (s service) ListTimeline(ctx context.Context, _ string, id uint64, opt *cha
		}
		label, body, ok := parseMessage(message.Message)
		if !ok {
			continue
		}
		var state changes.ReviewState
		switch label {
		default:
			state = changes.Commented
		case "Code-Review+2":
			timeline = append(timeline, changes.Review{
				ID:        uint64(idx), // TODO: message.ID is not uint64; e.g., "bfba753d015916303152305cee7152ea7a112fe0".
				User:      s.gerritUser(message.Author),
				CreatedAt: time.Time(message.Date),
				State:     changes.Approved,
				Body:      body,
				Editable:  false,
			})
			continue
			state = changes.Approved
		case "Code-Review-2":
			timeline = append(timeline, changes.Review{
				ID:        uint64(idx), // TODO: message.ID is not uint64; e.g., "bfba753d015916303152305cee7152ea7a112fe0".
				User:      s.gerritUser(message.Author),
				CreatedAt: time.Time(message.Date),
				State:     changes.ChangesRequested,
				Body:      body,
				Editable:  false,
			})
			continue
			state = changes.ChangesRequested
		}
		if body == "" {
			continue
		var cs []changes.InlineComment
		for file, comments := range *comments {
			for _, c := range comments {
				if time.Time(c.Updated).Equal(time.Time(message.Date)) {
					cs = append(cs, changes.InlineComment{
						File: file,
						Line: c.Line,
						Body: c.Message,
					})
				}
			}
		}
		timeline = append(timeline, changes.Comment{
		timeline = append(timeline, changes.Review{
			ID:        uint64(idx), // TODO: message.ID is not uint64; e.g., "bfba753d015916303152305cee7152ea7a112fe0".
			User:      s.gerritUser(message.Author),
			CreatedAt: time.Time(message.Date),
			State:     state,
			Body:      body,
			Editable:  false,
			Comments:  cs,
		})
	}
	return timeline, nil
}

timeline.go
@@ -32,10 +32,17 @@ type Review struct {
	Edited    *Edited // Edited is nil if the review hasn't been edited.
	State     ReviewState
	Body      string // Optional.
	Reactions []reactions.Reaction
	Editable  bool // Editable represents whether the current user (if any) can perform edit operations on this review.
	Comments  []InlineComment
}

type InlineComment struct {
	File string
	Line int
	Body string
}

type ReviewState int8

const (