@@ -16,10 +16,12 @@ type Service interface { // Count changes. Count(ctx context.Context, repo string, opt ListOptions) (uint64, error) // Get a change. Get(ctx context.Context, repo string, id uint64) (Change, 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) ([]byte, error) // ListComments lists comments for specified change id. ListComments(ctx context.Context, repo string, id uint64, opt *ListCommentsOptions) ([]issues.Comment, error) @@ -36,10 +38,17 @@ type Change struct { Author users.User CreatedAt time.Time Replies int // Number of replies to this change (not counting the mandatory change description comment). } type Commit struct { SHA string Message string Author users.User AuthorTime time.Time } // State represents the change state. type State string const ( // OpenState is when a change is open.
@@ -123,10 +123,14 @@ func state(status string) changes.State { default: panic("unreachable") } } func (s service) ListCommits(ctx context.Context, _ string, id uint64) ([]changes.Commit, error) { return nil, fmt.Errorf("ListCommits: not implemented") } func (s service) GetDiff(ctx context.Context, _ string, id uint64) ([]byte, error) { diff, _, err := s.cl.Changes.GetPatch(fmt.Sprint(id), "current", &gerrit.PatchOptions{ Path: "src", // TODO. }) if err != nil {
@@ -203,10 +203,32 @@ func (s service) Get(ctx context.Context, rs string, id uint64) (changes.Change, Author: ghActor(pr.Author), CreatedAt: pr.CreatedAt.Time, }, nil } func (s service) ListCommits(ctx context.Context, rs string, id uint64) ([]changes.Commit, error) { repo, err := ghRepoSpec(rs) if err != nil { // TODO: Map to 400 Bad Request HTTP error. return nil, err } cs, _, err := s.clV3.PullRequests.ListCommits(ctx, repo.Owner, repo.Repo, int(id), nil) if err != nil { return nil, err } var commits []changes.Commit for _, c := range cs { commits = append(commits, changes.Commit{ SHA: *c.SHA, Message: *c.Commit.Message, Author: ghUser(c.Author), AuthorTime: *c.Commit.Author.Date, }) } return commits, nil } func (s service) GetDiff(ctx context.Context, rs string, id uint64) ([]byte, error) { repo, err := ghRepoSpec(rs) if err != nil { // TODO: Map to 400 Bad Request HTTP error. return nil, err
@@ -104,10 +104,14 @@ func (s service) Count(_ context.Context, repo string, opt changes.ListOptions) func (s service) Get(ctx context.Context, _ string, id uint64) (changes.Change, error) { // TODO. return changes.Change{}, fmt.Errorf("Get: not implemented") } func (s service) ListCommits(ctx context.Context, _ string, id uint64) ([]changes.Commit, error) { return nil, fmt.Errorf("ListCommits: not implemented") } func (s service) GetDiff(ctx context.Context, _ string, id uint64) ([]byte, error) { // TODO. return nil, fmt.Errorf("GetDiff: not implemented") }