dmitri.shuralyov.com/service/change

Add initial support for editing comments (toggling reactions).

Change timeline item ID type from uint64 to string.
dmitshur committed 6 years ago commit 5f99232c79a97ad039852df6993da46e9cff24d2
Showing partial commit. Full Commit
Collapse all
change.go
@@ -4,10 +4,11 @@ package change
import (
	"context"
	"time"

	"github.com/shurcooL/issues"
	"github.com/shurcooL/reactions"
	"github.com/shurcooL/users"
)

// Service defines methods of a change tracking service.
type Service interface {
@@ -23,10 +24,13 @@ type Service interface {
	ListTimeline(ctx context.Context, repo string, id uint64, opt *ListTimelineOptions) ([]interface{}, error)
	// ListCommits lists change commits, from first to last.
	ListCommits(ctx context.Context, repo string, id uint64) ([]Commit, error)
	// Get a change diff.
	GetDiff(ctx context.Context, repo string, id uint64, opt *GetDiffOptions) ([]byte, error)

	// EditComment edits a comment.
	EditComment(ctx context.Context, repo string, id uint64, cr CommentRequest) (Comment, error)
}

// Change represents a change in a repository.
type Change struct {
	ID        uint64
@@ -87,5 +91,11 @@ type ListTimelineOptions struct {

type GetDiffOptions struct {
	// Commit is the commit ID of the commit to fetch.
	Commit string
}

// CommentRequest is a request to edit a comment.
type CommentRequest struct {
	ID       string
	Reaction *reactions.EmojiID // If not nil, toggle this reaction.
}
timeline.go
@@ -9,11 +9,11 @@ import (
)

// Comment represents a comment left on a change.
// TODO: Consider removing in favor of Review with commented state and no inline comments.
type Comment struct {
	ID        uint64
	ID        string
	User      users.User
	CreatedAt time.Time
	Edited    *Edited // Edited is nil if the comment hasn't been edited.
	Body      string
	Reactions []reactions.Reaction
@@ -26,11 +26,11 @@ type Edited struct {
	At time.Time
}

// Review represents a review left on a change.
type Review struct {
	ID        uint64
	ID        string
	User      users.User
	CreatedAt time.Time
	Edited    *Edited // Edited is nil if the review hasn't been edited.
	State     ReviewState
	Body      string // Optional.
@@ -39,11 +39,11 @@ type Review struct {
	Comments  []InlineComment
}

// InlineComment represents an inline comment that was left as part of a review.
type InlineComment struct {
	ID        uint64
	ID        string
	File      string
	Line      int
	Body      string
	Reactions []reactions.Reaction
}
@@ -56,11 +56,11 @@ const (
	ChangesRequested ReviewState = -1
)

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

	// Payload specifies the event type. It's one of:
	// ClosedEvent, ReopenedEvent, ..., MergedEvent, ApprovedEvent.