diff --git a/Gopkg.lock b/Gopkg.lock index 0f7dcc562921b..e17f15fb2985f 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -11,11 +11,11 @@ [[projects]] branch = "master" - digest = "1:aed2bc1c4026233af8ad43cab9d9464a0e3b906d3d058d2d6e814f3e1ddfa528" + digest = "1:8a559f110defa54f847a3efa2734297571d960b476699579f2008e4a37b62a1a" name = "code.gitea.io/sdk" packages = ["gitea"] pruneopts = "NUT" - revision = "d95a6e0392218961d1bdd18020290a20bd61b063" + revision = "140e9fcba7583e1c6f22eb57676bb00794ef14a8" [[projects]] digest = "1:3fcef06a1a6561955c94af6c7757a6fa37605eb653f0d06ab960e5bb80092195" diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 609a3254040e5..82c4b78de8e44 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -463,6 +463,8 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/times", repo.ListMyTrackedTimes) m.Get("/subscriptions", user.GetMyWatchedRepos) + + m.Get("/teams", org.ListUserTeams) }, reqToken()) // Repositories diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go index 79fd9d98aebf4..2db6a4fb10560 100644 --- a/routers/api/v1/org/team.go +++ b/routers/api/v1/org/team.go @@ -42,6 +42,41 @@ func ListTeams(ctx *context.APIContext) { ctx.JSON(200, apiTeams) } +// ListUserTeams list all the teams a user belongs to +func ListUserTeams(ctx *context.APIContext) { + // swagger:operation GET /user/teams user userListTeams + // --- + // summary: List all the teams a user belongs to + // produces: + // - application/json + // responses: + // "200": + // "$ref": "#/responses/TeamList" + teams, err := models.GetUserTeams(ctx.User.ID) + if err != nil { + ctx.Error(500, "GetUserTeams", err) + return + } + + cache := make(map[int64]*api.Organization) + apiTeams := make([]*api.Team, len(teams)) + for i := range teams { + apiOrg, ok := cache[teams[i].OrgID] + if !ok { + org, err := models.GetUserByID(teams[i].OrgID) + if err != nil { + ctx.Error(500, "GetUserByID", err) + return + } + apiOrg = convert.ToOrganization(org) + cache[teams[i].OrgID] = apiOrg + } + apiTeams[i] = convert.ToTeam(teams[i]) + apiTeams[i].Organization = apiOrg + } + ctx.JSON(200, apiTeams) +} + // GetTeam api for get a team func GetTeam(ctx *context.APIContext) { // swagger:operation GET /teams/{id} organization orgGetTeam diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index f30bcde786be6..153701d6dda97 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -5450,6 +5450,23 @@ } } }, + "/user/teams": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "user" + ], + "summary": "List all the teams a user belongs to", + "operationId": "userListTeams", + "responses": { + "200": { + "$ref": "#/responses/TeamList" + } + } + } + }, "/user/times": { "get": { "produces": [ @@ -7974,6 +7991,9 @@ "type": "string", "x-go-name": "Name" }, + "organization": { + "$ref": "#/definitions/Organization" + }, "permission": { "type": "string", "enum": [ diff --git a/vendor/code.gitea.io/sdk/gitea/hook.go b/vendor/code.gitea.io/sdk/gitea/hook.go index 80a5192d8eeda..ee6e2b79d50ef 100644 --- a/vendor/code.gitea.io/sdk/gitea/hook.go +++ b/vendor/code.gitea.io/sdk/gitea/hook.go @@ -371,6 +371,7 @@ type PushPayload struct { After string `json:"after"` CompareURL string `json:"compare_url"` Commits []*PayloadCommit `json:"commits"` + HeadCommit *PayloadCommit `json:"head_commit"` Repo *Repository `json:"repository"` Pusher *User `json:"pusher"` Sender *User `json:"sender"` diff --git a/vendor/code.gitea.io/sdk/gitea/org_team.go b/vendor/code.gitea.io/sdk/gitea/org_team.go index f3e98b932e91c..9de0a8d000760 100644 --- a/vendor/code.gitea.io/sdk/gitea/org_team.go +++ b/vendor/code.gitea.io/sdk/gitea/org_team.go @@ -7,9 +7,10 @@ package gitea // Team represents a team in an organization type Team struct { - ID int64 `json:"id"` - Name string `json:"name"` - Description string `json:"description"` + ID int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Organization *Organization `json:"organization"` // enum: none,read,write,admin,owner Permission string `json:"permission"` // enum: repo.code,repo.issues,repo.ext_issues,repo.wiki,repo.pulls,repo.releases,repo.ext_wiki diff --git a/vendor/code.gitea.io/sdk/gitea/release.go b/vendor/code.gitea.io/sdk/gitea/release.go index 396251dcac9d8..3605d2cd4ae0a 100644 --- a/vendor/code.gitea.io/sdk/gitea/release.go +++ b/vendor/code.gitea.io/sdk/gitea/release.go @@ -53,7 +53,7 @@ func (c *Client) GetRelease(user, repo string, id int64) (*Release, error) { type CreateReleaseOption struct { // required: true TagName string `json:"tag_name" binding:"Required"` - Target string `json:"target_commitish"` + Target string `json:"target_commitish" binding:"Required"` Title string `json:"name"` Note string `json:"body"` IsDraft bool `json:"draft"`