From 9cd16c5b12d093dd694e146d6c845ee4c405c774 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 17 Dec 2015 02:28:47 -0500 Subject: #1692 add organization APIs --- routers/api/v1/admin/orgs.go | 44 +++++++++++++++ routers/api/v1/admin/users.go | 6 +- routers/api/v1/api.go | 7 +++ routers/api/v1/convert/convert.go | 112 ++++++++++++++++++++++++++++++++++++++ routers/api/v1/org/org.go | 74 +++++++++++++++++++++++++ routers/api/v1/repo/hooks.go | 10 ++-- routers/api/v1/repo/keys.go | 8 +-- routers/api/v1/repo/repo.go | 12 ++-- routers/api/v1/user/email.go | 9 ++- routers/api/v1/user/keys.go | 18 +++--- routers/api/v1/utils/convert.go | 100 ---------------------------------- 11 files changed, 272 insertions(+), 128 deletions(-) create mode 100644 routers/api/v1/admin/orgs.go create mode 100644 routers/api/v1/convert/convert.go create mode 100644 routers/api/v1/org/org.go delete mode 100644 routers/api/v1/utils/convert.go (limited to 'routers/api/v1') diff --git a/routers/api/v1/admin/orgs.go b/routers/api/v1/admin/orgs.go new file mode 100644 index 00000000..5b5302ca --- /dev/null +++ b/routers/api/v1/admin/orgs.go @@ -0,0 +1,44 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package admin + +import ( + api "github.com/gogits/go-gogs-client" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/routers/api/v1/convert" + "github.com/gogits/gogs/routers/api/v1/user" +) + +// https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization +func CreateOrg(ctx *middleware.Context, form api.CreateOrgOption) { + u := user.GetUserByParams(ctx) + if ctx.Written() { + return + } + + org := &models.User{ + Name: form.UserName, + FullName: form.FullName, + Description: form.Description, + Website: form.Website, + Location: form.Location, + IsActive: true, + Type: models.ORGANIZATION, + } + if err := models.CreateOrganization(org, u); err != nil { + if models.IsErrUserAlreadyExist(err) || + models.IsErrNameReserved(err) || + models.IsErrNamePatternNotAllowed(err) { + ctx.APIError(422, "CreateOrganization", err) + } else { + ctx.APIError(500, "CreateOrganization", err) + } + return + } + + ctx.JSON(201, convert.ToApiOrganization(org)) +} diff --git a/routers/api/v1/admin/users.go b/routers/api/v1/admin/users.go index 1bd25368..9a8c906f 100644 --- a/routers/api/v1/admin/users.go +++ b/routers/api/v1/admin/users.go @@ -12,8 +12,8 @@ import ( "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" + "github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/user" - to "github.com/gogits/gogs/routers/api/v1/utils" ) func parseLoginSource(ctx *middleware.Context, u *models.User, sourceID int64, loginName string) { @@ -69,7 +69,7 @@ func CreateUser(ctx *middleware.Context, form api.CreateUserOption) { mailer.SendRegisterNotifyMail(ctx.Context, u) } - ctx.JSON(201, to.ApiUser(u)) + ctx.JSON(201, convert.ToApiUser(u)) } // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user @@ -118,7 +118,7 @@ func EditUser(ctx *middleware.Context, form api.EditUserOption) { } log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name) - ctx.JSON(200, to.ApiUser(u)) + ctx.JSON(200, convert.ToApiUser(u)) } // https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index eeba7139..bc7c1400 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -17,6 +17,7 @@ import ( "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers/api/v1/admin" "github.com/gogits/gogs/routers/api/v1/misc" + "github.com/gogits/gogs/routers/api/v1/org" "github.com/gogits/gogs/routers/api/v1/repo" "github.com/gogits/gogs/routers/api/v1/user" ) @@ -179,6 +180,11 @@ func RegisterRoutes(m *macaron.Macaron) { }, RepoAssignment()) }, ReqToken()) + // Organizations + m.Get("/user/orgs", org.ListMyOrgs) + m.Get("/users/:username/orgs", org.ListUserOrgs) + m.Combo("/orgs/:orgname").Get(org.Get).Patch(bind(api.EditOrgOption{}), org.Edit) + m.Any("/*", func(ctx *middleware.Context) { ctx.Error(404) }) @@ -191,6 +197,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Combo("").Patch(bind(api.EditUserOption{}), admin.EditUser). Delete(admin.DeleteUser) m.Post("/keys", admin.CreatePublicKey) + m.Post("/orgs", bind(api.CreateOrgOption{}), admin.CreateOrg) }) }) }, ReqAdmin()) diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go new file mode 100644 index 00000000..b91abbdd --- /dev/null +++ b/routers/api/v1/convert/convert.go @@ -0,0 +1,112 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package convert + +import ( + "fmt" + + "github.com/Unknwon/com" + + api "github.com/gogits/go-gogs-client" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/setting" +) + +// ToApiUser converts user to its API format. +func ToApiUser(u *models.User) *api.User { + return &api.User{ + ID: u.Id, + UserName: u.Name, + FullName: u.FullName, + Email: u.Email, + AvatarUrl: u.AvatarLink(), + } +} + +func ToApiEmail(email *models.EmailAddress) *api.Email { + return &api.Email{ + Email: email.Email, + Verified: email.IsActivated, + Primary: email.IsPrimary, + } +} + +// ToApiRepository converts repository to API format. +func ToApiRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository { + cl := repo.CloneLink() + return &api.Repository{ + Id: repo.ID, + Owner: *ToApiUser(owner), + FullName: owner.Name + "/" + repo.Name, + Private: repo.IsPrivate, + Fork: repo.IsFork, + HtmlUrl: setting.AppUrl + owner.Name + "/" + repo.Name, + CloneUrl: cl.HTTPS, + SshUrl: cl.SSH, + Permissions: permission, + } +} + +// ToApiPublicKey converts public key to its API format. +func ToApiPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey { + return &api.PublicKey{ + ID: key.ID, + Key: key.Content, + URL: apiLink + com.ToStr(key.ID), + Title: key.Name, + Created: key.Created, + } +} + +// ToApiHook converts webhook to its API format. +func ToApiHook(repoLink string, w *models.Webhook) *api.Hook { + config := map[string]string{ + "url": w.URL, + "content_type": w.ContentType.Name(), + } + if w.HookTaskType == models.SLACK { + s := w.GetSlackHook() + config["channel"] = s.Channel + config["username"] = s.Username + config["icon_url"] = s.IconURL + config["color"] = s.Color + } + + return &api.Hook{ + ID: w.ID, + Type: w.HookTaskType.Name(), + URL: fmt.Sprintf("%s/settings/hooks/%d", repoLink, w.ID), + Active: w.IsActive, + Config: config, + Events: w.EventsArray(), + Updated: w.Updated, + Created: w.Created, + } +} + +// ToApiDeployKey converts deploy key to its API format. +func ToApiDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey { + return &api.DeployKey{ + ID: key.ID, + Key: key.Content, + URL: apiLink + com.ToStr(key.ID), + Title: key.Name, + Created: key.Created, + ReadOnly: true, // All deploy keys are read-only. + } +} + +func ToApiOrganization(org *models.User) *api.Organization { + return &api.Organization{ + ID: org.Id, + AvatarUrl: org.AvatarLink(), + UserName: org.Name, + FullName: org.FullName, + Description: org.Description, + Website: org.Website, + Location: org.Location, + } +} diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go new file mode 100644 index 00000000..2c6d6fd3 --- /dev/null +++ b/routers/api/v1/org/org.go @@ -0,0 +1,74 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package org + +import ( + api "github.com/gogits/go-gogs-client" + + "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/routers/api/v1/convert" + "github.com/gogits/gogs/routers/api/v1/user" +) + +func listUserOrgs(ctx *middleware.Context, u *models.User, all bool) { + if err := u.GetOrganizations(all); err != nil { + ctx.APIError(500, "GetOrganizations", err) + return + } + + apiOrgs := make([]*api.Organization, len(u.Orgs)) + for i := range u.Orgs { + apiOrgs[i] = convert.ToApiOrganization(u.Orgs[i]) + } + ctx.JSON(200, &apiOrgs) +} + +// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations +func ListMyOrgs(ctx *middleware.Context) { + listUserOrgs(ctx, ctx.User, true) +} + +// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations +func ListUserOrgs(ctx *middleware.Context) { + u := user.GetUserByParams(ctx) + if ctx.Written() { + return + } + listUserOrgs(ctx, u, false) +} + +// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization +func Get(ctx *middleware.Context) { + org := user.GetUserByParamsName(ctx, ":orgname") + if ctx.Written() { + return + } + ctx.JSON(200, convert.ToApiOrganization(org)) +} + +// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization +func Edit(ctx *middleware.Context, form api.EditOrgOption) { + org := user.GetUserByParamsName(ctx, ":orgname") + if ctx.Written() { + return + } + + if !org.IsOwnedBy(ctx.User.Id) { + ctx.Error(403) + return + } + + org.FullName = form.FullName + org.Description = form.Description + org.Website = form.Website + org.Location = form.Location + if err := models.UpdateUser(org); err != nil { + ctx.APIError(500, "UpdateUser", err) + return + } + + ctx.JSON(200, convert.ToApiOrganization(org)) +} diff --git a/routers/api/v1/repo/hooks.go b/routers/api/v1/repo/hooks.go index 1ec70886..e0893a01 100644 --- a/routers/api/v1/repo/hooks.go +++ b/routers/api/v1/repo/hooks.go @@ -13,7 +13,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/middleware" - to "github.com/gogits/gogs/routers/api/v1/utils" + "github.com/gogits/gogs/routers/api/v1/convert" ) // https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks @@ -26,7 +26,7 @@ func ListHooks(ctx *middleware.Context) { apiHooks := make([]*api.Hook, len(hooks)) for i := range hooks { - apiHooks[i] = to.ApiHook(ctx.Repo.RepoLink, hooks[i]) + apiHooks[i] = convert.ToApiHook(ctx.Repo.RepoLink, hooks[i]) } ctx.JSON(200, &apiHooks) @@ -94,7 +94,7 @@ func CreateHook(ctx *middleware.Context, form api.CreateHookOption) { return } - ctx.JSON(201, to.ApiHook(ctx.Repo.RepoLink, w)) + ctx.JSON(201, convert.ToApiHook(ctx.Repo.RepoLink, w)) } // https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook @@ -104,7 +104,7 @@ func EditHook(ctx *middleware.Context, form api.EditHookOption) { if models.IsErrWebhookNotExist(err) { ctx.Error(404) } else { - ctx.APIError(500, "GetWebhookById", err) + ctx.APIError(500, "GetWebhookByID", err) } return } @@ -161,5 +161,5 @@ func EditHook(ctx *middleware.Context, form api.EditHookOption) { return } - ctx.JSON(200, to.ApiHook(ctx.Repo.RepoLink, w)) + ctx.JSON(200, convert.ToApiHook(ctx.Repo.RepoLink, w)) } diff --git a/routers/api/v1/repo/keys.go b/routers/api/v1/repo/keys.go index b0d8f914..2ec0b754 100644 --- a/routers/api/v1/repo/keys.go +++ b/routers/api/v1/repo/keys.go @@ -12,7 +12,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" - to "github.com/gogits/gogs/routers/api/v1/utils" + "github.com/gogits/gogs/routers/api/v1/convert" ) func composeDeployKeysAPILink(repoPath string) string { @@ -34,7 +34,7 @@ func ListDeployKeys(ctx *middleware.Context) { ctx.APIError(500, "GetContent", err) return } - apiKeys[i] = to.ApiDeployKey(apiLink, keys[i]) + apiKeys[i] = convert.ToApiDeployKey(apiLink, keys[i]) } ctx.JSON(200, &apiKeys) @@ -58,7 +58,7 @@ func GetDeployKey(ctx *middleware.Context) { } apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name) - ctx.JSON(200, to.ApiDeployKey(apiLink, key)) + ctx.JSON(200, convert.ToApiDeployKey(apiLink, key)) } func HandleCheckKeyStringError(ctx *middleware.Context, err error) { @@ -96,7 +96,7 @@ func CreateDeployKey(ctx *middleware.Context, form api.CreateKeyOption) { key.Content = content apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name) - ctx.JSON(201, to.ApiDeployKey(apiLink, key)) + ctx.JSON(201, convert.ToApiDeployKey(apiLink, key)) } // https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index c0d897b5..77903779 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -16,7 +16,7 @@ import ( "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" - to "github.com/gogits/gogs/routers/api/v1/utils" + "github.com/gogits/gogs/routers/api/v1/convert" ) // https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories @@ -97,12 +97,12 @@ func ListMyRepos(ctx *middleware.Context) { repos := make([]*api.Repository, numOwnRepos+len(accessibleRepos)) for i := range ownRepos { - repos[i] = to.ApiRepository(ctx.User, ownRepos[i], api.Permission{true, true, true}) + repos[i] = convert.ToApiRepository(ctx.User, ownRepos[i], api.Permission{true, true, true}) } i := numOwnRepos for repo, access := range accessibleRepos { - repos[i] = to.ApiRepository(repo.Owner, repo, api.Permission{ + repos[i] = convert.ToApiRepository(repo.Owner, repo, api.Permission{ Admin: access >= models.ACCESS_MODE_ADMIN, Push: access >= models.ACCESS_MODE_WRITE, Pull: true, @@ -139,7 +139,7 @@ func createRepo(ctx *middleware.Context, owner *models.User, opt api.CreateRepoO return } - ctx.JSON(201, to.ApiRepository(owner, repo, api.Permission{true, true, true})) + ctx.JSON(201, convert.ToApiRepository(owner, repo, api.Permission{true, true, true})) } // https://github.com/gogits/go-gogs-client/wiki/Repositories#create @@ -239,7 +239,7 @@ func Migrate(ctx *middleware.Context, form auth.MigrateRepoForm) { } log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName) - ctx.JSON(201, to.ApiRepository(ctxUser, repo, api.Permission{true, true, true})) + ctx.JSON(201, convert.ToApiRepository(ctxUser, repo, api.Permission{true, true, true})) } func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) { @@ -273,7 +273,7 @@ func Get(ctx *middleware.Context) { return } - ctx.JSON(200, to.ApiRepository(owner, repo, api.Permission{true, true, true})) + ctx.JSON(200, convert.ToApiRepository(owner, repo, api.Permission{true, true, true})) } // https://github.com/gogits/go-gogs-client/wiki/Repositories#delete diff --git a/routers/api/v1/user/email.go b/routers/api/v1/user/email.go index 449560e7..fd9193bd 100644 --- a/routers/api/v1/user/email.go +++ b/routers/api/v1/user/email.go @@ -10,9 +10,10 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" - to "github.com/gogits/gogs/routers/api/v1/utils" + "github.com/gogits/gogs/routers/api/v1/convert" ) +// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user func ListEmails(ctx *middleware.Context) { emails, err := models.GetEmailAddresses(ctx.User.Id) if err != nil { @@ -21,11 +22,12 @@ func ListEmails(ctx *middleware.Context) { } apiEmails := make([]*api.Email, len(emails)) for i := range emails { - apiEmails[i] = to.ApiEmail(emails[i]) + apiEmails[i] = convert.ToApiEmail(emails[i]) } ctx.JSON(200, &apiEmails) } +// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#add-email-addresses func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) { if len(form.Emails) == 0 { ctx.Status(422) @@ -52,11 +54,12 @@ func AddEmail(ctx *middleware.Context, form api.CreateEmailOption) { apiEmails := make([]*api.Email, len(emails)) for i := range emails { - apiEmails[i] = to.ApiEmail(emails[i]) + apiEmails[i] = convert.ToApiEmail(emails[i]) } ctx.JSON(201, &apiEmails) } +// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses func DeleteEmail(ctx *middleware.Context, form api.CreateEmailOption) { if len(form.Emails) == 0 { ctx.Status(204) diff --git a/routers/api/v1/user/keys.go b/routers/api/v1/user/keys.go index 213631e1..8ba73d99 100644 --- a/routers/api/v1/user/keys.go +++ b/routers/api/v1/user/keys.go @@ -10,13 +10,12 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/setting" + "github.com/gogits/gogs/routers/api/v1/convert" "github.com/gogits/gogs/routers/api/v1/repo" - to "github.com/gogits/gogs/routers/api/v1/utils" ) -// GetUserByParams returns user whose name is presented in URL paramenter. -func GetUserByParams(ctx *middleware.Context) *models.User { - user, err := models.GetUserByName(ctx.Params(":username")) +func GetUserByParamsName(ctx *middleware.Context, name string) *models.User { + user, err := models.GetUserByName(ctx.Params(name)) if err != nil { if models.IsErrUserNotExist(err) { ctx.Error(404) @@ -28,6 +27,11 @@ func GetUserByParams(ctx *middleware.Context) *models.User { return user } +// GetUserByParams returns user whose name is presented in URL paramenter. +func GetUserByParams(ctx *middleware.Context) *models.User { + return GetUserByParamsName(ctx, ":username") +} + func composePublicKeysAPILink() string { return setting.AppUrl + "api/v1/user/keys/" } @@ -42,7 +46,7 @@ func listPublicKeys(ctx *middleware.Context, uid int64) { apiLink := composePublicKeysAPILink() apiKeys := make([]*api.PublicKey, len(keys)) for i := range keys { - apiKeys[i] = to.ApiPublicKey(apiLink, keys[i]) + apiKeys[i] = convert.ToApiPublicKey(apiLink, keys[i]) } ctx.JSON(200, &apiKeys) @@ -75,7 +79,7 @@ func GetPublicKey(ctx *middleware.Context) { } apiLink := composePublicKeysAPILink() - ctx.JSON(200, to.ApiPublicKey(apiLink, key)) + ctx.JSON(200, convert.ToApiPublicKey(apiLink, key)) } // CreateUserPublicKey creates new public key to given user by ID. @@ -92,7 +96,7 @@ func CreateUserPublicKey(ctx *middleware.Context, form api.CreateKeyOption, uid return } apiLink := composePublicKeysAPILink() - ctx.JSON(201, to.ApiPublicKey(apiLink, key)) + ctx.JSON(201, convert.ToApiPublicKey(apiLink, key)) } // https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key diff --git a/routers/api/v1/utils/convert.go b/routers/api/v1/utils/convert.go deleted file mode 100644 index 3871c0da..00000000 --- a/routers/api/v1/utils/convert.go +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2015 The Gogs Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package utils - -import ( - "fmt" - - "github.com/Unknwon/com" - - api "github.com/gogits/go-gogs-client" - - "github.com/gogits/gogs/models" - "github.com/gogits/gogs/modules/setting" -) - -// ApiUser converts user to its API format. -func ApiUser(u *models.User) *api.User { - return &api.User{ - ID: u.Id, - UserName: u.Name, - FullName: u.FullName, - Email: u.Email, - AvatarUrl: u.AvatarLink(), - } -} - -func ApiEmail(email *models.EmailAddress) *api.Email { - return &api.Email{ - Email: email.Email, - Verified: email.IsActivated, - Primary: email.IsPrimary, - } -} - -// ApiRepository converts repository to API format. -func ApiRepository(owner *models.User, repo *models.Repository, permission api.Permission) *api.Repository { - cl := repo.CloneLink() - return &api.Repository{ - Id: repo.ID, - Owner: *ApiUser(owner), - FullName: owner.Name + "/" + repo.Name, - Private: repo.IsPrivate, - Fork: repo.IsFork, - HtmlUrl: setting.AppUrl + owner.Name + "/" + repo.Name, - CloneUrl: cl.HTTPS, - SshUrl: cl.SSH, - Permissions: permission, - } -} - -// ApiPublicKey converts public key to its API format. -func ApiPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey { - return &api.PublicKey{ - ID: key.ID, - Key: key.Content, - URL: apiLink + com.ToStr(key.ID), - Title: key.Name, - Created: key.Created, - } -} - -// ApiHook converts webhook to its API format. -func ApiHook(repoLink string, w *models.Webhook) *api.Hook { - config := map[string]string{ - "url": w.URL, - "content_type": w.ContentType.Name(), - } - if w.HookTaskType == models.SLACK { - s := w.GetSlackHook() - config["channel"] = s.Channel - config["username"] = s.Username - config["icon_url"] = s.IconURL - config["color"] = s.Color - } - - return &api.Hook{ - ID: w.ID, - Type: w.HookTaskType.Name(), - URL: fmt.Sprintf("%s/settings/hooks/%d", repoLink, w.ID), - Active: w.IsActive, - Config: config, - Events: w.EventsArray(), - Updated: w.Updated, - Created: w.Created, - } -} - -// ApiDeployKey converts deploy key to its API format. -func ApiDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey { - return &api.DeployKey{ - ID: key.ID, - Key: key.Content, - URL: apiLink + com.ToStr(key.ID), - Title: key.Name, - Created: key.Created, - ReadOnly: true, // All deploy keys are read-only. - } -} -- cgit v1.2.3