more techqa

pull/121/head
Eoin McAfee 3 years ago
parent 44e08911f4
commit 44f7ab1871

@ -87,9 +87,9 @@ type (
// gitea issue response object.
issue struct {
ID int `json:"id"`
Number int `json:"number"`
User user `json:"user"`
Title string `json:"title"`
Number int `json:"number"`
User user `json:"user"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"`
Labels []string `json:"labels"`
@ -111,9 +111,9 @@ type (
// gitea issue comment response object.
issueComment struct {
ID int `json:"id"`
HTMLURL string `json:"html_url"`
User user `json:"user"`
Body string `json:"body"`
HTMLURL string `json:"html_url"`
User user `json:"user"`
Body string `json:"body"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

@ -34,11 +34,11 @@ func (s *milestoneService) Create(ctx context.Context, repo string, input *scm.M
in := &milestoneInput{
Title: input.Title,
Description: input.Description,
State: StateOpen,
State: stateOpen,
Deadline: null.NewTime(input.DueDate, true),
}
if input.State == "closed" {
in.State = StateClosed
in.State = stateClosed
}
out := new(milestone)
res, err := s.client.do(ctx, "POST", path, in, out)
@ -60,39 +60,39 @@ func (s *milestoneService) Update(ctx context.Context, repo string, id int, inpu
}
switch input.State {
case "open":
in.State = StateOpen
in.State = stateOpen
case "close", "closed":
in.State = StateClosed
in.State = stateClosed
}
if input.Description != "" {
in.Description = input.Description
}
if !input.DueDate.IsZero() {
in.Deadline = null.NewTime(input.DueDate, true)
in.Deadline = null.TimeFrom(input.DueDate)
}
out := new(milestone)
res, err := s.client.do(ctx, "PATCH", path, in, out)
return convertMilestone(out), res, err
}
// StateType issue state type
type StateType string
// stateType issue state type
type stateType string
const (
// StateOpen pr/issue is open
StateOpen StateType = "open"
// StateClosed pr/issue is closed
StateClosed StateType = "closed"
// stateOpen pr/issue is open
stateOpen stateType = "open"
// stateClosed pr/issue is closed
stateClosed stateType = "closed"
// StateAll is all
StateAll StateType = "all"
StateAll stateType = "all"
)
type milestone struct {
ID int64 `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
State StateType `json:"state"`
OpenIssues int `json:"open_issues"`
Description string `json:"description"`
State stateType `json:"state"`
OpenIssues int `json:"open_issues"`
ClosedIssues int `json:"closed_issues"`
Created null.Time `json:"created_at"`
Updated null.Time `json:"updated_at"`
@ -103,7 +103,7 @@ type milestone struct {
type milestoneInput struct {
Title string `json:"title"`
Description string `json:"description"`
State StateType `json:"state"`
State stateType `json:"state"`
Deadline null.Time `json:"due_on"`
}

@ -83,9 +83,9 @@ func (s *pullService) Close(context.Context, string, int) (*scm.Response, error)
type pr struct {
ID int `json:"id"`
Number int `json:"number"`
User user `json:"user"`
Title string `json:"title"`
Number int `json:"number"`
User user `json:"user"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"`
HeadBranch string `json:"head_branch"`

@ -131,7 +131,7 @@ func convertRelease(src *release) *scm.Release {
ID: int(src.ID),
Title: src.Title,
Description: src.Note,
Link: ConvertAPIURLToHTMLURL(src.URL, src.TagName),
Link: convertAPIURLToHTMLURL(src.URL, src.TagName),
Tag: src.TagName,
Commitish: src.Target,
Draft: src.IsDraft,

@ -14,7 +14,7 @@ import (
func TestConvertAPIURLToHTMLURL(t *testing.T) {
got := ConvertAPIURLToHTMLURL("https://try.gitea.com/api/v1/repos/octocat/Hello-World/123", "v1.0.0")
got := convertAPIURLToHTMLURL("https://try.gitea.com/api/v1/repos/octocat/Hello-World/123", "v1.0.0")
want := "https://try.gitea.com/octocat/Hello-World/releases/tag/v1.0.0"
if diff := cmp.Diff(got, want); diff != "" {
@ -32,7 +32,7 @@ func TestConvertAPIURLToHTMLURLEmptyLinkWhenURLParseFails(t *testing.T) {
broken := []string{"http s://try.gitea.com/api/v1/repos/octocat/Hello-World/123", "https://try.gitea.com/api/v1/repos/octocat/Hello-World"}
for _, url := range broken {
got := ConvertAPIURLToHTMLURL(url, "v1.0.0")
got := convertAPIURLToHTMLURL(url, "v1.0.0")
want := ""
if diff := cmp.Diff(got, want); diff != "" {

@ -56,8 +56,8 @@ func encodePullRequestListOptions(opts scm.PullRequestListOptions) string {
return params.Encode()
}
// ConvertAPIURLToHTMLURL converts an release API endpoint into a html endpoint
func ConvertAPIURLToHTMLURL(apiURL string, tagName string) string {
// convertAPIURLToHTMLURL converts an release API endpoint into a html endpoint
func convertAPIURLToHTMLURL(apiURL string, tagName string) string {
// "url": "https://try.gitea.com/api/v1/repos/octocat/Hello-World/123",
// "html_url": "https://try.gitea.com/octocat/Hello-World/releases/tag/v1.0.0",
// the url field is the API url, not the html url, so until go-sdk v0.13.3, build it ourselves

@ -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: null.NewTime(input.DueDate, true),
DueOn: null.TimeFrom(input.DueDate),
}
out := new(milestone)
res, err := s.client.do(ctx, "POST", path, in, out)
@ -83,7 +83,7 @@ func (s *milestoneService) Update(ctx context.Context, repo string, id int, inpu
in.Description = input.Description
}
if !input.DueDate.IsZero() {
in.DueOn = null.NewTime(input.DueDate, true)
in.DueOn = null.TimeFrom(input.DueDate)
}
out := new(milestone)
res, err := s.client.do(ctx, "PATCH", path, in, out)

@ -83,5 +83,5 @@ func NewTime(t time.Time, valid bool) Time {
// TimeFrom creates a new Time that will always be valid.
func TimeFrom(t time.Time) Time {
return NewTime(t, true)
return NewTime(t, !t.IsZero())
}
Loading…
Cancel
Save