dmitri.shuralyov.com/service/change

Implement and use changes.Service interface.

Add GetDiff method to it.
dmitshur committed 7 years ago commit 1725c4c4235d315deaa2317977b3a3906328f339
Showing partial commit. Full Commit
Collapse all
changes.go
@@ -3,34 +3,38 @@ package changes

import (
	"context"
	"time"

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

// Service defines methods of a change tracking service.
type Service interface {
	// List changes.
	List(ctx context.Context, repo string) ([]Change, error)
	List(ctx context.Context, repo string, opt ListOptions) ([]Change, error)
	// Count changes.
	Count(ctx context.Context, repo string) (uint64, error)
	Count(ctx context.Context, repo string, opt ListOptions) (uint64, error)

	// Get a change.
	Get(ctx context.Context, repo string, id uint64) (Change, error)
	// Get a change diff.
	GetDiff(ctx context.Context, repo string, id uint64) ([]byte, error)

	// ListComments lists comments for specified change id.
	//ListComments(ctx context.Context, repo string, id uint64, opt *ListOptions) ([]Comment, error)
	ListComments(ctx context.Context, repo string, id uint64, opt *ListCommentsOptions) ([]issues.Comment, error)
	// ListEvents lists events for specified change id.
	//ListEvents(ctx context.Context, repo string, id uint64, opt *ListOptions) ([]Event, error)
	ListEvents(ctx context.Context, repo string, id uint64, opt *ListCommentsOptions) ([]issues.Event, error)
}

// Change represents a change in a repository.
type Change struct {
	ID        uint64
	State     State
	Title     string
	Labels    []issues.Label
	Author    users.User
	CreatedAt time.Time
	Replies   int // Number of replies to this change (not counting the mandatory change description comment).
}

@@ -43,5 +47,27 @@ const (
	// ClosedState is when a change is closed.
	ClosedState State = "closed"
	// MergedState is when a change is merged.
	MergedState State = "merged"
)

// ListOptions are options for list operations.
type ListOptions struct {
	State StateFilter
}

// StateFilter is a filter by state.
type StateFilter State

const (
	// AllStates is a state filter that includes all issues.
	AllStates StateFilter = "all"
)

// ListCommentsOptions controls pagination.
type ListCommentsOptions struct {
	// Start is the index of first result to retrieve, zero-indexed.
	Start int

	// Length is the number of results to include.
	Length int
}