Introduce NotifySubjectState #520

Merged
6543 merged 4 commits from 6543/go-sdk:add-NotifySubjectState into master 2021-06-30 21:06:50 +00:00
6 changed files with 49 additions and 18 deletions

View File

@ -1,9 +1,7 @@
# Migration Guide: v0.11 to v0.12
v0.12.0 introduces a number of breaking changes, throu it should not be hard to
migrate.
Just follow this guid and if issues still ocure ask for help on discord or
feel free to create an issue.
v0.12.0 introduces a number of breaking changes, through which it should not be difficult to migrate.
Just follow this guid and if you still encounter problems, ask for help on discord or feel free to create an issue.
<!-- toc -->

View File

@ -1,8 +1,7 @@
# Migration Guide: v0.12 to v0.13
v0.13.0 introduces a number of breaking changes, throu it should not be hard to migrate.
Just follow this guid and if issues still ocure ask for help on discord or
feel free to create an issue.
v0.13.0 introduces a number of breaking changes, through which it should not be difficult to migrate.
Just follow this guid and if you still encounter problems, ask for help on discord or feel free to create an issue.
<!-- toc -->

View File

@ -1,8 +1,7 @@
# Migration Guide: v0.13 to v0.14
v0.14.0 introduces a number of breaking changes, throu it should not be hard to migrate.
Just follow this guid and if issues still ocure ask for help on discord or
feel free to create an issue.
v0.14.0 introduces a number of breaking changes, through which it should not be difficult to migrate.
Just follow this guid and if you still encounter problems, ask for help on discord or feel free to create an issue.
<!-- toc -->

View File

@ -0,0 +1,18 @@
# Migration Guide: v0.14 to v0.15
v0.15.0 introduces a number of api changes, through which it should not be difficult to migrate.
Just follow this guid and if you still encounter problems, ask for help on discord or feel free to create an issue.
<!-- toc -->
- [Changed Struct Fields (#520)](#changed-struct-fields)
<!-- tocstop -->
## Changed Struct Fields
- the `State` field at **NotificationSubject** changed from **StateType** to **NotifySubjectState**, it also contains `"open"`, `"closed"` and add `"merged"`
Pulls:
- [#520 Introduce NotifySubjectState](https://gitea.com/gitea/go-sdk/pulls/520)

View File

@ -29,11 +29,11 @@ type NotificationThread struct {
// NotificationSubject contains the notification subject (Issue/Pull/Commit)
type NotificationSubject struct {
Title string `json:"title"`
URL string `json:"url"`
LatestCommentURL string `json:"latest_comment_url"`
Type string `json:"type"`
State StateType `json:"state"`
Title string `json:"title"`
URL string `json:"url"`
LatestCommentURL string `json:"latest_comment_url"`
Type string `json:"type"`
State NotifySubjectState `json:"state"`
}
// NotifyStatus notification status type
@ -48,6 +48,18 @@ const (
NotifyStatusPinned NotifyStatus = "pinned"
)
// NotifySubjectState reflect state of notification subject
type NotifySubjectState string
const (
// NotifySubjectOpen if subject is a pull/issue and is open at the moment
NotifySubjectOpen NotifySubjectState = "open"
// NotifySubjectClosed if subject is a pull/issue and is closed at the moment
NotifySubjectClosed NotifySubjectState = "closed"
// NotifySubjectMerged if subject is a pull and got merged
NotifySubjectMerged NotifySubjectState = "merged"
)
// ListNotificationOptions represents the filter options
type ListNotificationOptions struct {
ListOptions

View File

@ -60,6 +60,8 @@ func TestNotifications(t *testing.T) {
for _, n := range nList {
assert.EqualValues(t, true, n.Unread)
assert.EqualValues(t, "Issue", n.Subject.Type)
assert.EqualValues(t, NotifySubjectOpen, nList[0].Subject.State)
assert.EqualValues(t, NotifySubjectOpen, nList[1].Subject.State)
if n.Subject.Title == "A Issue" {
assert.EqualValues(t, repoA.Name, n.Repository.Name)
} else if n.Subject.Title == "B Issue" {
@ -104,8 +106,8 @@ func TestNotifications(t *testing.T) {
count, _, err = c.CheckNotifications()
assert.NoError(t, err)
assert.EqualValues(t, 1, count)
assert.Len(t, nList, 1)
if len(nList) > 0 {
if assert.Len(t, nList, 1) {
assert.EqualValues(t, NotifySubjectClosed, nList[0].Subject.State)
_, err = c.ReadNotification(nList[0].ID)
assert.NoError(t, err)
}
@ -124,5 +126,8 @@ func TestNotifications(t *testing.T) {
assert.NoError(t, err)
nList, _, err = c.ListNotifications(ListNotificationOptions{Status: []NotifyStatus{NotifyStatusPinned, NotifyStatusUnread}})
assert.NoError(t, err)
assert.Len(t, nList, 2)
if assert.Len(t, nList, 2) {
assert.EqualValues(t, NotifySubjectClosed, nList[0].Subject.State)
assert.EqualValues(t, NotifySubjectClosed, nList[1].Subject.State)
}
}