@@ -44,11 +44,11 @@ func (s service) List(ctx context.Context, repo string, opt change.ListOptions)
// "status:closed" is equivalent to "(status:abandoned OR status:merged)".
query = fmt.Sprintf("project:%s status:closed", project)
case change.FilterAll:
query = fmt.Sprintf("project:%s", project)
}
cs, resp, err := s.cl.Changes.QueryChanges(&gerrit.QueryChangeOptions{
cs, resp, err := s.cl.Changes.QueryChanges(ctx, &gerrit.QueryChangeOptions{
QueryOptions: gerrit.QueryOptions{
Query: []string{query},
Limit: 25,
},
ChangeOptions: gerrit.ChangeOptions{
@@ -95,11 +95,11 @@ func (s service) Count(_ context.Context, repo string, opt change.ListOptions) (
return 0, nil
}
func (s service) Get(ctx context.Context, repo string, id uint64) (change.Change, error) {
project := project(repo)
chg, resp, err := s.cl.Changes.GetChange(fmt.Sprintf("%s~%d", project, id), &gerrit.ChangeOptions{
chg, resp, err := s.cl.Changes.GetChange(ctx, fmt.Sprintf("%s~%d", project, id), &gerrit.ChangeOptions{
AdditionalFields: []string{"DETAILED_ACCOUNTS", "MESSAGES", "ALL_REVISIONS"},
})
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return change.Change{}, os.ErrNotExist
@@ -144,11 +144,11 @@ func changeState(status string) change.State {
}
}
func (s service) ListCommits(ctx context.Context, repo string, id uint64) ([]change.Commit, error) {
project := project(repo)
chg, resp, err := s.cl.Changes.GetChange(fmt.Sprintf("%s~%d", project, id), &gerrit.ChangeOptions{
chg, resp, err := s.cl.Changes.GetChange(ctx, fmt.Sprintf("%s~%d", project, id), &gerrit.ChangeOptions{
AdditionalFields: []string{"DETAILED_ACCOUNTS", "ALL_REVISIONS"},
//AdditionalFields: []string{"ALL_REVISIONS", "ALL_COMMITS"}, // TODO: Consider using git committer/author instead...
})
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
@@ -174,20 +174,20 @@ func (s service) ListCommits(ctx context.Context, repo string, id uint64) ([]cha
func (s service) GetDiff(ctx context.Context, repo string, id uint64, opt *change.GetDiffOptions) ([]byte, error) {
project := project(repo)
switch opt {
case nil:
diff, resp, err := s.cl.Changes.GetPatch(fmt.Sprintf("%s~%d", project, id), "current", nil)
diff, resp, err := s.cl.Changes.GetPatch(ctx, fmt.Sprintf("%s~%d", project, id), "current", nil)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, os.ErrNotExist
}
return nil, err
}
return []byte(*diff), nil
default:
chg, resp, err := s.cl.Changes.GetChange(fmt.Sprintf("%s~%d", project, id), &gerrit.ChangeOptions{
chg, resp, err := s.cl.Changes.GetChange(ctx, fmt.Sprintf("%s~%d", project, id), &gerrit.ChangeOptions{
AdditionalFields: []string{"ALL_REVISIONS"},
})
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, os.ErrNotExist
@@ -206,11 +206,11 @@ func (s service) GetDiff(ctx context.Context, repo string, id uint64, opt *chang
case 1:
base = ""
default:
base = fmt.Sprint(r.Number - 1)
}
files, _, err := s.cl.Changes.ListFiles(fmt.Sprintf("%s~%d", project, id), opt.Commit, &gerrit.FilesOptions{
files, _, err := s.cl.Changes.ListFiles(ctx, fmt.Sprintf("%s~%d", project, id), opt.Commit, &gerrit.FilesOptions{
Base: base,
})
if err != nil {
return nil, err
}
@@ -219,11 +219,11 @@ func (s service) GetDiff(ctx context.Context, repo string, id uint64, opt *chang
sortedFiles = append(sortedFiles, file)
}
sort.Strings(sortedFiles)
var diff string
for _, file := range sortedFiles {
diffInfo, _, err := s.cl.Changes.GetDiff(fmt.Sprintf("%s~%d", project, id), opt.Commit, file, &gerrit.DiffOptions{
diffInfo, _, err := s.cl.Changes.GetDiff(ctx, fmt.Sprintf("%s~%d", project, id), opt.Commit, file, &gerrit.DiffOptions{
Base: base,
Context: "5",
})
if err != nil {
return nil, err
@@ -275,24 +275,24 @@ func (s service) GetDiff(ctx context.Context, repo string, id uint64, opt *chang
func (s service) ListTimeline(ctx context.Context, repo string, id uint64, opt *change.ListTimelineOptions) ([]interface{}, error) {
// TODO: Pagination. Respect opt.Start and opt.Length, if given.
project := project(repo)
chg, resp, err := s.cl.Changes.GetChangeDetail(fmt.Sprintf("%s~%d", project, id), &gerrit.ChangeOptions{
chg, resp, err := s.cl.Changes.GetChangeDetail(ctx, fmt.Sprintf("%s~%d", project, id), &gerrit.ChangeOptions{
AdditionalFields: []string{"ALL_REVISIONS"},
})
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return nil, os.ErrNotExist
}
return nil, err
}
commit, _, err := s.cl.Changes.GetCommit(fmt.Sprintf("%s~%d", project, id), "current", nil)
commit, _, err := s.cl.Changes.GetCommit(ctx, fmt.Sprintf("%s~%d", project, id), "current", nil)
if err != nil {
return nil, err
}
comments, _, err := s.cl.Changes.ListChangeComments(fmt.Sprintf("%s~%d", project, id))
comments, _, err := s.cl.Changes.ListChangeComments(ctx, fmt.Sprintf("%s~%d", project, id))
if err != nil {
return nil, err
}
var timeline []interface{}
timeline = append(timeline, change.Comment{ // CL description.