dmitri.shuralyov.com/service/change

Refactor issues.{Comment,Event} to changes.{Comment,TimelineItem}.
dmitshur committed 7 years ago commit 6c5819d156f7090ce383e102cb9bfac46dd5faca
Showing partial commit. Full Commit
Collapse all
changes.go
@@ -17,11 +17,11 @@ type Service interface {
	Count(ctx context.Context, repo string, opt ListOptions) (uint64, error)

	// Get a change.
	Get(ctx context.Context, repo string, id uint64) (Change, error)

	// ListTimeline lists timeline items (issues.Comment, issues.Event) for specified change id.
	// ListTimeline lists timeline items (changes.Comment, changes.TimelineItem) for specified change id.
	ListTimeline(ctx context.Context, repo string, id uint64, opt *ListTimelineOptions) ([]interface{}, error)
	// ListCommits lists change commits.
	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)
timeline.go
@@ -0,0 +1,82 @@
package changes

import (
	"time"

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

// Comment represents a comment left on an issue.
type Comment struct {
	ID        uint64
	User      users.User
	CreatedAt time.Time
	Edited    *Edited // Edited is nil if the comment hasn't been edited.
	Body      string
	Reactions []reactions.Reaction
	Editable  bool // Editable represents whether the current user (if any) can perform edit operations on this comment.
}

// Edited provides the actor and timing information for an edited item.
type Edited struct {
	By users.User
	At time.Time
}

// TimelineItem represents a timeline item.
type TimelineItem struct {
	ID        uint64 // 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.
	Payload interface{}
}

type (
	// ClosedEvent is when a change is closed.
	ClosedEvent struct {
		CommitID      string // CommitID is SHA of commit that closed the change, or empty string if there's no associated commit.
		CommitHTMLURL string // Optional.
	}

	// ReopenedEvent is when a change is reopened.
	ReopenedEvent struct{}

	// RenamedEvent is when a change is renamed.
	RenamedEvent struct {
		From string
		To   string
	}

	// LabeledEvent is when a change is labeled.
	LabeledEvent struct {
		Label issues.Label
	}
	// UnlabeledEvent is when a change is unlabeled.
	UnlabeledEvent struct {
		Label issues.Label
	}

	// CommentDeletedEvent is when a comment is deleted.
	CommentDeletedEvent struct{}

	ReviewRequestedEvent struct {
		RequestedReviewer users.User
	}
	ReviewRequestRemovedEvent struct {
		RequestedReviewer users.User
	}

	MergedEvent struct {
		CommitID      string
		CommitHTMLURL string // Optional.
		RefName       string
	}

	// TODO: Merge into Comment or so.
	ApprovedEvent struct{}
)