mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 08:56:29 +00:00
reworked to have two distinct REST handlers
This commit is contained in:
parent
05b6dad81e
commit
ae236a3d4d
4 changed files with 44 additions and 37 deletions
|
@ -35,12 +35,12 @@ func (s *RepoService) Enable(host, owner, name string) error {
|
||||||
// DELETE /api/repos/{host}/{owner}/{name}
|
// DELETE /api/repos/{host}/{owner}/{name}
|
||||||
func (s *RepoService) Disable(host, owner, name string) error {
|
func (s *RepoService) Disable(host, owner, name string) error {
|
||||||
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
|
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
|
||||||
return s.run("DELETE", path, nil, nil)
|
return s.run("PATCH", path, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE /api/repos/{host}/{owner}/{name}?remove=true
|
// DELETE /api/repos/{host}/{owner}/{name}?remove=true
|
||||||
func (s *RepoService) Delete(host, owner, name string) error {
|
func (s *RepoService) Delete(host, owner, name string) error {
|
||||||
var path = fmt.Sprintf("/api/repos/%s/%s/%s?remove=true", host, owner, name)
|
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
|
||||||
return s.run("DELETE", path, nil, nil)
|
return s.run("DELETE", path, nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,8 @@ func GetRepo(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
}{repo, repo.PublicKey, repo.Params, role})
|
}{repo, repo.PublicKey, repo.Params, role})
|
||||||
}
|
}
|
||||||
|
|
||||||
// DelRepo accepts a request to inactivate the named
|
// DelRepo accepts a request to delete the named
|
||||||
// repository. This will disable all builds in the system
|
// repository.
|
||||||
// for this repository.
|
|
||||||
//
|
//
|
||||||
// DEL /api/repos/:host/:owner/:name
|
// DEL /api/repos/:host/:owner/:name
|
||||||
//
|
//
|
||||||
|
@ -53,10 +52,7 @@ func DelRepo(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
var ctx = context.FromC(c)
|
var ctx = context.FromC(c)
|
||||||
var repo = ToRepo(c)
|
var repo = ToRepo(c)
|
||||||
|
|
||||||
var rm = r.FormValue("remove") // using ?remove=true
|
|
||||||
|
|
||||||
// completely remove the repository from the database
|
// completely remove the repository from the database
|
||||||
if len(rm) != 0 {
|
|
||||||
var user = ToUser(c)
|
var user = ToUser(c)
|
||||||
var remote = remote.Lookup(repo.Host)
|
var remote = remote.Lookup(repo.Host)
|
||||||
if remote == nil {
|
if remote == nil {
|
||||||
|
@ -70,6 +66,7 @@ func DelRepo(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
if user_token != nil {
|
if user_token != nil {
|
||||||
user.Access = user_token.AccessToken
|
user.Access = user_token.AccessToken
|
||||||
user.Secret = user_token.RefreshToken
|
user.Secret = user_token.RefreshToken
|
||||||
|
user.TokenExpiry = user_token.Expiry
|
||||||
datastore.PutUser(ctx, user)
|
datastore.PutUser(ctx, user)
|
||||||
}
|
}
|
||||||
// setup the post-commit hook with the remote system and
|
// setup the post-commit hook with the remote system and
|
||||||
|
@ -87,9 +84,18 @@ func DelRepo(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusNoContent)
|
w.WriteHeader(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PatchRepo accepts a request to inactivate the named
|
||||||
|
// repository. This will disable all builds in the system
|
||||||
|
// for this repository.
|
||||||
|
//
|
||||||
|
// PATCH /api/repos/:host/:owner/:name
|
||||||
|
//
|
||||||
|
func PatchRepo(c web.C, w http.ResponseWriter, r *http.Request) {
|
||||||
|
var ctx = context.FromC(c)
|
||||||
|
var repo = ToRepo(c)
|
||||||
|
|
||||||
// disable everything
|
// disable everything
|
||||||
repo.Active = false
|
repo.Active = false
|
||||||
repo.PullRequest = false
|
repo.PullRequest = false
|
||||||
|
|
|
@ -46,6 +46,7 @@ func New() *web.Mux {
|
||||||
repos.Put("/api/repos/:host/:owner/:name", handler.PutRepo)
|
repos.Put("/api/repos/:host/:owner/:name", handler.PutRepo)
|
||||||
repos.Post("/api/repos/:host/:owner/:name", handler.PostRepo)
|
repos.Post("/api/repos/:host/:owner/:name", handler.PostRepo)
|
||||||
repos.Delete("/api/repos/:host/:owner/:name", handler.DelRepo)
|
repos.Delete("/api/repos/:host/:owner/:name", handler.DelRepo)
|
||||||
|
repos.Patch("/api/repos/:host/:owner/:name", handler.PatchRepo)
|
||||||
mux.Handle("/api/repos/:host/:owner/:name", repos)
|
mux.Handle("/api/repos/:host/:owner/:name", repos)
|
||||||
mux.Handle("/api/repos/:host/:owner/:name/*", repos)
|
mux.Handle("/api/repos/:host/:owner/:name/*", repos)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ type User struct {
|
||||||
Created int64 `meddler:"user_created" json:"created_at"`
|
Created int64 `meddler:"user_created" json:"created_at"`
|
||||||
Updated int64 `meddler:"user_updated" json:"updated_at"`
|
Updated int64 `meddler:"user_updated" json:"updated_at"`
|
||||||
Synced int64 `meddler:"user_synced" json:"synced_at"`
|
Synced int64 `meddler:"user_synced" json:"synced_at"`
|
||||||
TokenExpiry int64 `meddler:"user_access_expires" json:"-"`
|
TokenExpiry int64 `meddler:"user_access_expires,zeroisnull" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewUser(remote, login, email string) *User {
|
func NewUser(remote, login, email string) *User {
|
||||||
|
|
Loading…
Reference in a new issue