|
|
|
@ -8,6 +8,12 @@ import ( |
|
|
|
|
"fmt" |
|
|
|
|
"net/url" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-version" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
version1_12_3, _ = version.NewVersion("1.12.3") |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// NotificationThread expose Notification on API
|
|
|
|
@ -75,7 +81,7 @@ func (opt *ListNotificationOptions) QueryEncode() string { |
|
|
|
|
// Validate the CreateUserOption struct
|
|
|
|
|
func (opt ListNotificationOptions) Validate(c *Client) error { |
|
|
|
|
if len(opt.Status) != 0 { |
|
|
|
|
return c.CheckServerVersionConstraint(">=1.12.3") |
|
|
|
|
return c.checkServerVersionGreaterThanOrEqual(version1_12_3) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
@ -98,14 +104,14 @@ func (opt *MarkNotificationOptions) QueryEncode() string { |
|
|
|
|
// Validate the CreateUserOption struct
|
|
|
|
|
func (opt MarkNotificationOptions) Validate(c *Client) error { |
|
|
|
|
if len(opt.Status) != 0 || len(opt.ToStatus) != 0 { |
|
|
|
|
return c.CheckServerVersionConstraint(">=1.12.3") |
|
|
|
|
return c.checkServerVersionGreaterThanOrEqual(version1_12_3) |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// CheckNotifications list users's notification threads
|
|
|
|
|
func (c *Client) CheckNotifications() (int64, *Response, error) { |
|
|
|
|
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { |
|
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { |
|
|
|
|
return 0, nil, err |
|
|
|
|
} |
|
|
|
|
new := struct { |
|
|
|
@ -118,7 +124,7 @@ func (c *Client) CheckNotifications() (int64, *Response, error) { |
|
|
|
|
|
|
|
|
|
// GetNotification get notification thread by ID
|
|
|
|
|
func (c *Client) GetNotification(id int64) (*NotificationThread, *Response, error) { |
|
|
|
|
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { |
|
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { |
|
|
|
|
return nil, nil, err |
|
|
|
|
} |
|
|
|
|
thread := new(NotificationThread) |
|
|
|
@ -129,7 +135,7 @@ func (c *Client) GetNotification(id int64) (*NotificationThread, *Response, erro |
|
|
|
|
// ReadNotification mark notification thread as read by ID
|
|
|
|
|
// It optionally takes a second argument if status has to be set other than 'read'
|
|
|
|
|
func (c *Client) ReadNotification(id int64, status ...NotifyStatus) (*Response, error) { |
|
|
|
|
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { |
|
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
link := fmt.Sprintf("/notifications/threads/%d", id) |
|
|
|
@ -142,7 +148,7 @@ func (c *Client) ReadNotification(id int64, status ...NotifyStatus) (*Response, |
|
|
|
|
|
|
|
|
|
// ListNotifications list users's notification threads
|
|
|
|
|
func (c *Client) ListNotifications(opt ListNotificationOptions) ([]*NotificationThread, *Response, error) { |
|
|
|
|
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { |
|
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { |
|
|
|
|
return nil, nil, err |
|
|
|
|
} |
|
|
|
|
if err := opt.Validate(c); err != nil { |
|
|
|
@ -157,7 +163,7 @@ func (c *Client) ListNotifications(opt ListNotificationOptions) ([]*Notification |
|
|
|
|
|
|
|
|
|
// ReadNotifications mark notification threads as read
|
|
|
|
|
func (c *Client) ReadNotifications(opt MarkNotificationOptions) (*Response, error) { |
|
|
|
|
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { |
|
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
if err := opt.Validate(c); err != nil { |
|
|
|
@ -171,7 +177,7 @@ func (c *Client) ReadNotifications(opt MarkNotificationOptions) (*Response, erro |
|
|
|
|
|
|
|
|
|
// ListRepoNotifications list users's notification threads on a specific repo
|
|
|
|
|
func (c *Client) ListRepoNotifications(owner, reponame string, opt ListNotificationOptions) ([]*NotificationThread, *Response, error) { |
|
|
|
|
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { |
|
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { |
|
|
|
|
return nil, nil, err |
|
|
|
|
} |
|
|
|
|
if err := opt.Validate(c); err != nil { |
|
|
|
@ -186,7 +192,7 @@ func (c *Client) ListRepoNotifications(owner, reponame string, opt ListNotificat |
|
|
|
|
|
|
|
|
|
// ReadRepoNotifications mark notification threads as read on a specific repo
|
|
|
|
|
func (c *Client) ReadRepoNotifications(owner, reponame string, opt MarkNotificationOptions) (*Response, error) { |
|
|
|
|
if err := c.CheckServerVersionConstraint(">=1.12.0"); err != nil { |
|
|
|
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
if err := opt.Validate(c); err != nil { |
|
|
|
|