Skip to content

Commit

Permalink
techqa feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
eoinmcafee00 committed Sep 27, 2021
1 parent 9bedabe commit 00597ec
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 61 deletions.
2 changes: 1 addition & 1 deletion scm/driver/bitbucket/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (s *milestoneService) Find(ctx context.Context, repo string, id int) (*scm.
return nil, nil, scm.ErrNotSupported
}

func (s *milestoneService) List(ctx context.Context, repo string, opts scm.ListOptions) ([]*scm.Milestone, *scm.Response, error) {
func (s *milestoneService) List(ctx context.Context, repo string, opts scm.MilestoneListOptions) ([]*scm.Milestone, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}

Expand Down
32 changes: 16 additions & 16 deletions scm/driver/gitea/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (s *milestoneService) Update(ctx context.Context, repo string, id int, inpu
if input.Description != "" {
in.Description = input.Description
}
if input.DueDate != nil {
if !input.DueDate.IsZero() {
in.Deadline = input.DueDate
}
out := new(milestone)
Expand All @@ -88,23 +88,23 @@ const (
)

type milestone struct {
ID int64 `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
State StateType `json:"state"`
OpenIssues int `json:"open_issues"`
ClosedIssues int `json:"closed_issues"`
Created time.Time `json:"created_at"`
Updated *time.Time `json:"updated_at"`
Closed *time.Time `json:"closed_at"`
Deadline *time.Time `json:"due_on"`
ID int64 `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
State StateType `json:"state"`
OpenIssues int `json:"open_issues"`
ClosedIssues int `json:"closed_issues"`
Created time.Time `json:"created_at"`
Updated time.Time `json:"updated_at"`
Closed time.Time `json:"closed_at"`
Deadline time.Time `json:"due_on"`
}

type milestoneInput struct {
Title string `json:"title"`
Description string `json:"description"`
State StateType `json:"state"`
Deadline *time.Time `json:"due_on"`
Title string `json:"title"`
Description string `json:"description"`
State StateType `json:"state"`
Deadline time.Time `json:"due_on"`
}

func convertMilestoneList(src []*milestone) []*scm.Milestone {
Expand All @@ -116,7 +116,7 @@ func convertMilestoneList(src []*milestone) []*scm.Milestone {
}

func convertMilestone(src *milestone) *scm.Milestone {
if src == nil || src.Deadline == nil {
if src == nil || src.Deadline.IsZero() {
return nil
}
return &scm.Milestone{
Expand Down
4 changes: 2 additions & 2 deletions scm/driver/gitea/milestone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestMilestoneCreate(t *testing.T) {
Title: "v1.0",
Description: "Tracking milestone for version 1.0",
State: "open",
DueDate: &dueDate,
DueDate: dueDate,
}
got, _, err := client.Milestones.Create(context.Background(), "jcitizen/my-repo", input)
if err != nil {
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestMilestoneUpdate(t *testing.T) {
Title: "v1.0",
Description: "Tracking milestone for version 1.0",
State: "open",
DueDate: &dueDate,
DueDate: dueDate,
}
got, _, err := client.Milestones.Update(context.Background(), "jcitizen/my-repo", 1, input)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion scm/driver/gitea/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *releaseService) FindByTag(ctx context.Context, repo string, tag string)

func (s *releaseService) List(ctx context.Context, repo string, opts scm.ReleaseListOptions) ([]*scm.Release, *scm.Response, error) {
namespace, name := scm.Split(repo)
path := fmt.Sprintf("api/v1/repos/%s/%s/releases?%s", namespace, name, encodeReleaseListOptions(opts))
path := fmt.Sprintf("api/v1/repos/%s/%s/releases?%s", namespace, name, encodeReleaseListOptions(releaseListOptionsToGiteaListOptions(opts)))
out := []*release{}
res, err := s.client.do(ctx, "GET", path, nil, &out)
return convertReleaseList(out), res, err
Expand Down Expand Up @@ -148,3 +148,10 @@ func convertReleaseList(src []*release) []*scm.Release {
}
return dst
}

func releaseListOptionsToGiteaListOptions(in scm.ReleaseListOptions) ListOptions {
return ListOptions{
Page: in.Page,
PageSize: in.Size,
}
}
6 changes: 3 additions & 3 deletions scm/driver/gitea/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ func (s *repositoryService) DeleteHook(ctx context.Context, repo string, id stri
type (
// gitea repository resource.
repository struct {
ID int `json:"id"`
Owner user `json:"owner"`
Name string `json:"name"`
ID int `json:"id"`
Owner user `json:"owner"`
Name string `json:"name"`
FullName string `json:"full_name"`
Private bool `json:"private"`
Fork bool `json:"fork"`
Expand Down
24 changes: 10 additions & 14 deletions scm/driver/gitea/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,14 @@ func encodeMilestoneListOptions(opts scm.MilestoneListOptions) string {
return params.Encode()
}

func encodeReleaseListOptions(opts scm.ReleaseListOptions) string {
params := url.Values{}
if opts.Page != 0 {
params.Set("page", strconv.Itoa(opts.Page))
}
if opts.Size != 0 {
params.Set("per_page", strconv.Itoa(opts.Size))
}
if opts.Open && opts.Closed {
params.Set("state", "all")
} else if opts.Closed {
params.Set("state", "closed")
}
return params.Encode()
type ListOptions struct {
Page int
PageSize int
}

func encodeReleaseListOptions(o ListOptions) string {
query := make(url.Values)
query.Add("page", fmt.Sprintf("%d", o.Page))
query.Add("limit", fmt.Sprintf("%d", o.PageSize))
return query.Encode()
}
8 changes: 4 additions & 4 deletions scm/driver/github/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *milestoneService) Create(ctx context.Context, repo string, input *scm.M
Title: input.Title,
State: input.State,
Description: input.Description,
DueOn: *input.DueDate,
DueOn: input.DueDate,
}
out := new(milestone)
res, err := s.client.do(ctx, "POST", path, in, out)
Expand All @@ -82,8 +82,8 @@ func (s *milestoneService) Update(ctx context.Context, repo string, id int, inpu
if input.Description != "" {
in.Description = input.Description
}
if input.DueDate != nil {
in.DueOn = *input.DueDate
if !input.DueDate.IsZero() {
in.DueOn = input.DueDate
}
out := new(milestone)
res, err := s.client.do(ctx, "PATCH", path, in, out)
Expand All @@ -106,6 +106,6 @@ func convertMilestone(from *milestone) *scm.Milestone {
Description: from.Description,
Link: from.HTMLURL,
State: from.State,
DueDate: &from.DueOn,
DueDate: from.DueOn,
}
}
4 changes: 2 additions & 2 deletions scm/driver/github/milestone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestMilestoneCreate(t *testing.T) {
Title: "v1.0",
Description: "Tracking milestone for version 1.0",
State: "open",
DueDate: &dueDate,
DueDate: dueDate,
}

got, res, err := client.Milestones.Create(context.Background(), "octocat/hello-world", input)
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestMilestoneUpdate(t *testing.T) {
Title: "v1.0",
Description: "Tracking milestone for version 1.0",
State: "open",
DueDate: &dueDate,
DueDate: dueDate,
}

got, res, err := client.Milestones.Update(context.Background(), "octocat/hello-world", 1, input)
Expand Down
20 changes: 10 additions & 10 deletions scm/driver/gitlab/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ type milestone struct {
}

type milestoneInput struct {
Title *string `json:"title"`
StateEvent *string `json:"state_event,omitempty"`
Description *string `json:"description"`
DueDate *isoTime `json:"due_date"`
Title *string `json:"title"`
StateEvent *string `json:"state_event,omitempty"`
Description *string `json:"description"`
DueDate isoTime `json:"due_date"`
}

func (s *milestoneService) Find(ctx context.Context, repo string, id int) (*scm.Milestone, *scm.Response, error) {
Expand All @@ -99,11 +99,11 @@ func (s *milestoneService) List(ctx context.Context, repo string, opts scm.Miles

func (s *milestoneService) Create(ctx context.Context, repo string, input *scm.MilestoneInput) (*scm.Milestone, *scm.Response, error) {
path := fmt.Sprintf("api/v4/projects/%s/milestones", encode(repo))
dueDateIso := isoTime(*input.DueDate)
dueDateIso := isoTime(input.DueDate)
in := &milestoneInput{
Title: &input.Title,
Description: &input.Description,
DueDate: &dueDateIso,
DueDate: dueDateIso,
}
out := new(milestone)
res, err := s.client.do(ctx, "POST", path, in, out)
Expand Down Expand Up @@ -133,9 +133,9 @@ func (s *milestoneService) Update(ctx context.Context, repo string, id int, inpu
if input.Description != "" {
in.Description = &input.Description
}
if input.DueDate != nil {
dueDateIso := isoTime(*input.DueDate)
in.DueDate = &dueDateIso
if !input.DueDate.IsZero() {
dueDateIso := isoTime(input.DueDate)
in.DueDate = dueDateIso
}
out := new(milestone)
res, err := s.client.do(ctx, "PATCH", path, in, out)
Expand All @@ -161,6 +161,6 @@ func convertMilestone(from *milestone) *scm.Milestone {
Title: from.Title,
Description: from.Description,
State: from.State,
DueDate: &dueDate,
DueDate: dueDate,
}
}
4 changes: 2 additions & 2 deletions scm/driver/gitlab/milestone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestMilestoneCreate(t *testing.T) {
Title: "v1.0",
Description: "Tracking milestone for version 1.0",
State: "open",
DueDate: &dueDate,
DueDate: dueDate,
}
got, res, err := client.Milestones.Create(context.Background(), "diaspora/diaspora", input)
if err != nil {
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestMilestoneUpdate(t *testing.T) {
Title: "v1.0",
Description: "Tracking milestone for version 1.0",
State: "close",
DueDate: &dueDate,
DueDate: dueDate,
}
got, res, err := client.Milestones.Update(context.Background(), "diaspora/diaspora", 1, input)
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions scm/driver/gitlab/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ type releaseInput struct {
}

func (s *releaseService) Find(ctx context.Context, repo string, id int) (*scm.Release, *scm.Response, error) {
// this could be implemented by List and filter but would be to expensive
panic("gitlab only allows to find a release by tag")
return nil, nil, scm.ErrNotSupported
}

func (s *releaseService) FindByTag(ctx context.Context, repo string, tag string) (*scm.Release, *scm.Response, error) {
Expand Down Expand Up @@ -58,8 +57,7 @@ func (s *releaseService) Create(ctx context.Context, repo string, input *scm.Rel
}

func (s *releaseService) Delete(ctx context.Context, repo string, id int) (*scm.Response, error) {
// this could be implemented by List and filter but would be to expensive
panic("gitlab only allows to delete a release by tag")
return nil, scm.ErrNotSupported
}

func (s *releaseService) DeleteByTag(ctx context.Context, repo string, tag string) (*scm.Response, error) {
Expand Down
2 changes: 1 addition & 1 deletion scm/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type (
Title string
Description string
State string
DueDate *time.Time
DueDate time.Time
}

// MilestoneListOptions provides options for querying a list of repository milestones.
Expand Down
2 changes: 1 addition & 1 deletion scm/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type (
Description string
Link string
State string
DueDate *time.Time
DueDate time.Time
}

// PullRequestService provides access to pull request resources.
Expand Down

0 comments on commit 00597ec

Please sign in to comment.