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

Work on better display of review event+comment.
dmitshur committed 7 years ago commit 2c0fdaf59eac125b1269279405baf69497c4677a
Collapse all
gerritapi/gerritapi.go
@@ -281,21 +281,29 @@ func (s service) ListTimeline(ctx context.Context, _ string, id uint64, opt *cha
		if !ok {
			continue
		}
		switch label {
		case "Code-Review+2":
			timeline = append(timeline, changes.TimelineItem{
				Actor:     s.gerritUser(message.Author),
			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),
				Payload:   changes.ApprovedEvent{},
				State:     changes.Approved,
				Body:      body,
				Editable:  false,
			})
			continue
		case "Code-Review-2":
			timeline = append(timeline, changes.TimelineItem{
				Actor:     s.gerritUser(message.Author),
			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),
				Payload:   changes.ChangesRequestedEvent{},
				State:     changes.ChangesRequested,
				Body:      body,
				Editable:  false,
			})
			continue
		}
		if body == "" {
			continue
		}
		timeline = append(timeline, changes.Comment{
timeline.go
@@ -6,11 +6,11 @@ import (
	"github.com/shurcooL/issues"
	"github.com/shurcooL/reactions"
	"github.com/shurcooL/users"
)

// Comment represents a comment left on an issue.
// Comment represents a comment left on a change.
type Comment struct {
	ID        uint64
	User      users.User
	CreatedAt time.Time
	Edited    *Edited // Edited is nil if the comment hasn't been edited.
@@ -23,10 +23,29 @@ type Comment struct {
type Edited struct {
	By users.User
	At time.Time
}

type Review struct {
	ID        uint64
	User      users.User
	CreatedAt time.Time
	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.
}

type ReviewState int8

const (
	Approved         ReviewState = +1
	Commented        ReviewState = 0
	ChangesRequested ReviewState = -1
)

// TimelineItem represents a timeline item.
type TimelineItem struct {
	ID        uint64 // TODO: See if this belongs here.
	Actor     users.User
	CreatedAt time.Time