Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API for Issue set Subscription #8729

Merged
merged 41 commits into from
Nov 2, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
06daf4e
add issue subscriber API
6543 Oct 29, 2019
deaf69c
subscribers return []user.APIFormat
6543 Oct 29, 2019
a7c7674
add comments
6543 Oct 29, 2019
413b2b6
more meaningfull description
6543 Oct 29, 2019
1aced19
Merge branch 'master' into add-api-issues-subscriptions
6543 Oct 29, 2019
7c24ae3
without "reqToken()" api works ...
6543 Oct 29, 2019
2de7290
Merge branch 'master' into add-api-issues-subscriptions
6543 Oct 29, 2019
5eca929
FIX: getIssueWatchers() get only aktive suscriber
6543 Oct 29, 2019
e8bb557
add return avter error on right position
6543 Oct 29, 2019
2ca4a7e
Revert "FIX: getIssueWatchers() get only aktive suscriber"
6543 Oct 29, 2019
6e948d7
Merge branch 'master' into add-api-issues-subscriptions
6543 Oct 29, 2019
b2b6c05
Merge branch 'master' into add-api-issues-subscriptions
6543 Oct 30, 2019
89c5ba9
Merge branch 'master' into add-api-issues-subscriptions
6543 Oct 30, 2019
f04f7c9
Merge branch 'master' into add-api-issues-subscriptions
6543 Oct 31, 2019
432a38c
Update routers/api/v1/repo/issue.go
6543 Nov 1, 2019
bab1235
test go linter again
6543 Nov 1, 2019
69b5d7e
update swagger
6543 Nov 1, 2019
3d693fa
GetIssueWatchers -> GetIssueSubscribers
6543 Nov 1, 2019
dea6928
GetIssueWatchers -> GetIssueSubscribers
6543 Nov 1, 2019
59ca419
Revert "test go linter again"
6543 Nov 1, 2019
c7a0e7b
Merge branch 'master' into add-api-issues-subscriptions
6543 Nov 1, 2019
bb6185c
change description for unsubscribe too
6543 Nov 1, 2019
3de794d
golangci-lint timeout avter 5min
6543 Nov 1, 2019
da005ac
move issueSubscription to seperate file
6543 Nov 1, 2019
fb325d7
dont create black entitys
6543 Nov 1, 2019
bd3c737
use IsWatching until refactoring
6543 Nov 1, 2019
6f451e0
Merge branch 'master' into add-api-issues-subscriptions
6543 Nov 1, 2019
9c3bbcc
Update License Info
6543 Nov 1, 2019
d52dbcb
better swagger description
6543 Nov 1, 2019
02ea6db
Merge branch 'master' into add-api-issues-subscriptions
6543 Nov 2, 2019
1fcd434
Update .golangci.yml
6543 Nov 2, 2019
4a8d2d7
add IssueWatchList type
6543 Nov 2, 2019
577aa9c
batch tasks
6543 Nov 2, 2019
dbc2796
Merge branch 'master' into add-api-issues-subscriptions
6543 Nov 2, 2019
34f3143
use e Engien
6543 Nov 2, 2019
8bb2043
add error handling
6543 Nov 2, 2019
ad29e4c
error should be the last type when returning multiple items
6543 Nov 2, 2019
e0b11f9
short version
6543 Nov 2, 2019
2056321
reurn empy UserList instead of nil
6543 Nov 2, 2019
94d3aa3
Merge branch 'master' into add-api-issues-subscriptions
6543 Nov 2, 2019
5ce8c04
Merge branch 'master' into add-api-issues-subscriptions
6543 Nov 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ issues:
- path: routers/routes/routes.go
linters:
- dupl
- path: routers/api/v1/repo/issue.go
linters:
- dupl
zeripath marked this conversation as resolved.
Show resolved Hide resolved
- path: routers/repo/view.go
linters:
- dupl
Expand Down
5 changes: 5 additions & 0 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,11 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/start", reqToken(), repo.StartIssueStopwatch)
m.Post("/stop", reqToken(), repo.StopIssueStopwatch)
})
m.Group("/subscriptions", func() {
m.Get("", bind(api.User{}), repo.GetIssueWatchers)
6543 marked this conversation as resolved.
Show resolved Hide resolved
m.Put("/:user", repo.AddIssueSubscription)
m.Delete("/:user", repo.DelIssueSubscription)
})
})
}, mustEnableIssuesOrPulls)
m.Group("/labels", func() {
Expand Down
206 changes: 206 additions & 0 deletions routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,209 @@ func StopIssueStopwatch(ctx *context.APIContext) {

ctx.Status(201)
}

// AddIssueSubscription add user to subscription list
func AddIssueSubscription(ctx *context.APIContext) {
// swagger:operation PUT /repos/{owner}/{repo}/issues/{index}/subscriptions/{user} issue issueAddSubscription
// ---
// summary: Add user to subscription list
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: owner
// in: path
// description: owner of the repo
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo
// type: string
// required: true
// - name: index
// in: path
// description: index of the issue
// type: integer
// format: int64
// required: true
// - name: user
// in: path
// description: user witch subscribe to issue
6543 marked this conversation as resolved.
Show resolved Hide resolved
// type: string
// required: true
// responses:
// "201":
// "$ref": "#/responses/empty"
// "304":
// description: User can only subscribe itself if he is no admin
// "404":
// description: Issue not found
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetIssueByIndex", err)
}

return
}

user, err := models.GetUserByName(ctx.Params(":user"))
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetUserByName", err)
return
}
6543 marked this conversation as resolved.
Show resolved Hide resolved
}

//only admin and user for itself can change subscription
if user.ID != ctx.User.ID && !ctx.User.IsAdmin {
ctx.Error(403, "User", nil)
return
}

if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, true); err != nil {
ctx.Error(500, "CreateOrUpdateIssueWatch", err)
return
}

ctx.Status(201)
}

// DelIssueSubscription remove user to subscription list
func DelIssueSubscription(ctx *context.APIContext) {
// swagger:operation DELETE /repos/{owner}/{repo}/issues/{index}/subscriptions/{user} issue issueDeleteSubscription
// ---
// summary: Delete user from subscription list
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: owner
// in: path
// description: owner of the repo
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo
// type: string
// required: true
// - name: index
// in: path
// description: index of the issue
// type: integer
// format: int64
// required: true
// - name: user
// in: path
// description: user witch unsubscribe to issue
// type: string
// required: true
// responses:
// "201":
// "$ref": "#/responses/empty"
// "304":
// description: User can only subscribe itself if he is no admin
// "404":
// description: Issue not found
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetIssueByIndex", err)
}

return
}

user, err := models.GetUserByName(ctx.Params(":user"))
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetUserByName", err)
return
}
6543 marked this conversation as resolved.
Show resolved Hide resolved
}

//only admin and user for itself can change subscription
if user.ID != ctx.User.ID && !ctx.User.IsAdmin {
ctx.Error(403, "User", nil)
return
}

if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, false); err != nil {
ctx.Error(500, "CreateOrUpdateIssueWatch", err)
return
}

ctx.Status(201)
}

// GetIssueWatchers return subscribers of an issue
func GetIssueWatchers(ctx *context.APIContext, form api.User) {
// swagger:operation GET /repos/{owner}/{repo}/issues/{index}/subscriptions issue issueSubscriptions
// ---
// summary: Get users who subscribed on an issue.
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: owner
// in: path
// description: owner of the repo
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo
// type: string
// required: true
// - name: index
// in: path
// description: index of the issue
// type: integer
// format: int64
// required: true
// responses:
// "201":
// "$ref": "#/responses/empty"
// "404":
// description: Issue not found
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetIssueByIndex", err)
}

return
}

iw, err := models.GetIssueWatchers(issue.ID)
if err != nil {
ctx.Error(500, "GetIssueWatchers", err)
return
}

subscribers := make([]*api.User, len(iw))
for i, s := range iw {
user, err := models.GetUserByID(s.UserID)
if err != nil {
continue
}
subscribers[i] = user.APIFormat()
}

ctx.JSON(200, subscribers)
}
159 changes: 159 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3731,6 +3731,165 @@
}
}
},
"/repos/{owner}/{repo}/issues/{index}/subscriptions": {
"get": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"issue"
],
"summary": "Get users who subscribed on an issue.",
"operationId": "issueSubscriptions",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "index of the issue",
"name": "index",
"in": "path",
"required": true
}
],
"responses": {
"201": {
"$ref": "#/responses/empty"
},
"404": {
"description": "Issue not found"
}
}
}
},
"/repos/{owner}/{repo}/issues/{index}/subscriptions/{user}": {
"put": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"issue"
],
"summary": "Add user to subscription list",
"operationId": "issueAddSubscription",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "index of the issue",
"name": "index",
"in": "path",
"required": true
},
{
"type": "string",
"description": "user witch subscribe to issue",
"name": "user",
"in": "path",
"required": true
}
],
"responses": {
"201": {
"$ref": "#/responses/empty"
},
"304": {
"description": "User can only subscribe itself if he is no admin"
},
"404": {
"description": "Issue not found"
}
}
},
"delete": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"issue"
],
"summary": "Delete user from subscription list",
"operationId": "issueDeleteSubscription",
"parameters": [
{
"type": "string",
"description": "owner of the repo",
"name": "owner",
"in": "path",
"required": true
},
{
"type": "string",
"description": "name of the repo",
"name": "repo",
"in": "path",
"required": true
},
{
"type": "integer",
"format": "int64",
"description": "index of the issue",
"name": "index",
"in": "path",
"required": true
},
{
"type": "string",
"description": "user witch unsubscribe to issue",
"name": "user",
"in": "path",
"required": true
}
],
"responses": {
"201": {
"$ref": "#/responses/empty"
},
"304": {
"description": "User can only subscribe itself if he is no admin"
},
"404": {
"description": "Issue not found"
}
}
}
},
"/repos/{owner}/{repo}/keys": {
"get": {
"produces": [
Expand Down