added repo repair
This commit is contained in:
parent
849c22803f
commit
18bee1b84d
4 changed files with 42 additions and 1 deletions
|
@ -42,6 +42,9 @@ type Client interface {
|
|||
// RepoChown updates a repository owner.
|
||||
RepoChown(string, string) (*model.Repo, error)
|
||||
|
||||
// RepoRepair repairs the repository hooks.
|
||||
RepoRepair(string, string) error
|
||||
|
||||
// RepoDel deletes a repository.
|
||||
RepoDel(string, string) error
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ const (
|
|||
pathRepos = "%s/api/user/repos"
|
||||
pathRepo = "%s/api/repos/%s/%s"
|
||||
pathChown = "%s/api/repos/%s/%s/chown"
|
||||
pathRepair = "%s/api/repos/%s/%s/repair"
|
||||
pathBuilds = "%s/api/repos/%s/%s/builds"
|
||||
pathBuild = "%s/api/repos/%s/%s/builds/%v"
|
||||
pathApprove = "%s/api/repos/%s/%s/builds/%d/approve"
|
||||
|
@ -165,7 +166,7 @@ func (c *client) RepoPost(owner string, name string) (*model.Repo, error) {
|
|||
return out, err
|
||||
}
|
||||
|
||||
// RepoChow updates a repository owner.
|
||||
// RepoChown updates a repository owner.
|
||||
func (c *client) RepoChown(owner string, name string) (*model.Repo, error) {
|
||||
out := new(model.Repo)
|
||||
uri := fmt.Sprintf(pathChown, c.base, owner, name)
|
||||
|
@ -173,6 +174,12 @@ func (c *client) RepoChown(owner string, name string) (*model.Repo, error) {
|
|||
return out, err
|
||||
}
|
||||
|
||||
// RepoRepair repais the repository hooks.
|
||||
func (c *client) RepoRepair(owner string, name string) error {
|
||||
uri := fmt.Sprintf(pathRepair, c.base, owner, name)
|
||||
return c.post(uri, nil, nil)
|
||||
}
|
||||
|
||||
// RepoPatch updates a repository.
|
||||
func (c *client) RepoPatch(owner, name string, in *model.RepoPatch) (*model.Repo, error) {
|
||||
out := new(model.Repo)
|
||||
|
|
|
@ -104,6 +104,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
|
|||
repo.PATCH("", session.MustPush, server.PatchRepo)
|
||||
repo.DELETE("", session.MustRepoAdmin(), server.DeleteRepo)
|
||||
repo.POST("/chown", session.MustRepoAdmin(), server.ChownRepo)
|
||||
repo.POST("/repair", session.MustRepoAdmin(), server.RepairRepo)
|
||||
|
||||
repo.POST("/builds/:number", session.MustPush, server.PostBuild)
|
||||
repo.POST("/builds/:number/approve", session.MustPush, server.PostApproval)
|
||||
|
|
|
@ -173,3 +173,33 @@ func DeleteRepo(c *gin.Context) {
|
|||
remote.Deactivate(user, repo, httputil.GetURL(c.Request))
|
||||
c.Writer.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func RepairRepo(c *gin.Context) {
|
||||
remote := remote.FromContext(c)
|
||||
repo := session.Repo(c)
|
||||
user := session.User(c)
|
||||
|
||||
// crates the jwt token used to verify the repository
|
||||
t := token.New(token.HookToken, repo.FullName)
|
||||
sig, err := t.Sign(repo.Hash)
|
||||
if err != nil {
|
||||
c.String(500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// reconstruct the link
|
||||
host := httputil.GetURL(c.Request)
|
||||
link := fmt.Sprintf(
|
||||
"%s/hook?access_token=%s",
|
||||
host,
|
||||
sig,
|
||||
)
|
||||
|
||||
remote.Deactivate(user, repo, host)
|
||||
err = remote.Activate(user, repo, link)
|
||||
if err != nil {
|
||||
c.String(500, err.Error())
|
||||
return
|
||||
}
|
||||
c.Writer.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue