diff --git a/gitea/issue.go b/gitea/issue.go index d97f96a..c33856a 100644 --- a/gitea/issue.go +++ b/gitea/issue.go @@ -63,6 +63,14 @@ type ListIssueOption struct { Labels []string Milestones []string KeyWord string + Since time.Time + Before time.Time + // filter by created by username + CreatedBy string + // filter by assigned to username + AssignedBy string + // filter by username mentioned + MentionedBy string } // StateType issue state type @@ -111,6 +119,23 @@ func (opt *ListIssueOption) QueryEncode() string { query.Add("milestones", strings.Join(opt.Milestones, ",")) } + if !opt.Since.IsZero() { + query.Add("since", opt.Since.Format(time.RFC3339)) + } + if !opt.Before.IsZero() { + query.Add("before", opt.Before.Format(time.RFC3339)) + } + + if len(opt.CreatedBy) > 0 { + query.Add("created_by", opt.CreatedBy) + } + if len(opt.AssignedBy) > 0 { + query.Add("assigned_by", opt.AssignedBy) + } + if len(opt.MentionedBy) > 0 { + query.Add("mentioned_by", opt.MentionedBy) + } + return query.Encode() } diff --git a/gitea/notifications.go b/gitea/notifications.go index 57f83b1..8b1ffa7 100644 --- a/gitea/notifications.go +++ b/gitea/notifications.go @@ -32,7 +32,7 @@ type NotificationSubject struct { Title string `json:"title"` URL string `json:"url"` LatestCommentURL string `json:"latest_comment_url"` - Type string `json:"type"` + Type NotifySubjectType `json:"type"` State NotifySubjectState `json:"state"` } @@ -48,6 +48,20 @@ const ( NotifyStatusPinned NotifyStatus = "pinned" ) +// NotifySubjectType represent type of notification subject +type NotifySubjectType string + +const ( + // NotifySubjectIssue an issue is subject of an notification + NotifySubjectIssue NotifySubjectType = "Issue" + // NotifySubjectPull an pull is subject of an notification + NotifySubjectPull NotifySubjectType = "Pull" + // NotifySubjectCommit an commit is subject of an notification + NotifySubjectCommit NotifySubjectType = "Commit" + // NotifySubjectRepository an repository is subject of an notification + NotifySubjectRepository NotifySubjectType = "Repository" +) + // NotifySubjectState reflect state of notification subject type NotifySubjectState string @@ -63,9 +77,10 @@ const ( // ListNotificationOptions represents the filter options type ListNotificationOptions struct { ListOptions - Since time.Time - Before time.Time - Status []NotifyStatus + Since time.Time + Before time.Time + Status []NotifyStatus + SubjectTypes []NotifySubjectType } // MarkNotificationOptions represents the filter & modify options @@ -87,6 +102,9 @@ func (opt *ListNotificationOptions) QueryEncode() string { for _, s := range opt.Status { query.Add("status-types", string(s)) } + for _, s := range opt.SubjectTypes { + query.Add("subject-type", string(s)) + } return query.Encode() } diff --git a/gitea/release.go b/gitea/release.go index 7d36e71..c8e7681 100644 --- a/gitea/release.go +++ b/gitea/release.go @@ -35,6 +35,22 @@ type Release struct { // ListReleasesOptions options for listing repository's releases type ListReleasesOptions struct { ListOptions + IsDraft *bool + IsPreRelease *bool +} + +// QueryEncode turns options into querystring argument +func (opt *ListReleasesOptions) QueryEncode() string { + query := opt.getURLQuery() + + if opt.IsDraft != nil { + query.Add("draft", fmt.Sprintf("%t", *opt.IsDraft)) + } + if opt.IsPreRelease != nil { + query.Add("draft", fmt.Sprintf("%t", *opt.IsPreRelease)) + } + + return query.Encode() } // ListReleases list releases of a repository @@ -45,7 +61,7 @@ func (c *Client) ListReleases(owner, repo string, opt ListReleasesOptions) ([]*R opt.setDefaults() releases := make([]*Release, 0, opt.PageSize) resp, err := c.getParsedResponse("GET", - fmt.Sprintf("/repos/%s/%s/releases?%s", owner, repo, opt.getURLQuery().Encode()), + fmt.Sprintf("/repos/%s/%s/releases?%s", owner, repo, opt.QueryEncode()), nil, nil, &releases) return releases, resp, err } @@ -168,7 +184,7 @@ func (c *Client) DeleteReleaseByTag(user, repo string, tag string) (*Response, e // fallbackGetReleaseByTag is fallback for old gitea installations ( < 1.13.0 ) func (c *Client) fallbackGetReleaseByTag(owner, repo string, tag string) (*Release, *Response, error) { for i := 1; ; i++ { - rl, resp, err := c.ListReleases(owner, repo, ListReleasesOptions{ListOptions{Page: i}}) + rl, resp, err := c.ListReleases(owner, repo, ListReleasesOptions{ListOptions: ListOptions{Page: i}}) if err != nil { return nil, resp, err }