added repo repair

This commit is contained in:
Brad Rydzewski 2017-04-12 15:32:44 +02:00
parent 849c22803f
commit 18bee1b84d
4 changed files with 42 additions and 1 deletions

View file

@ -42,6 +42,9 @@ type Client interface {
// RepoChown updates a repository owner. // RepoChown updates a repository owner.
RepoChown(string, string) (*model.Repo, error) RepoChown(string, string) (*model.Repo, error)
// RepoRepair repairs the repository hooks.
RepoRepair(string, string) error
// RepoDel deletes a repository. // RepoDel deletes a repository.
RepoDel(string, string) error RepoDel(string, string) error

View file

@ -31,6 +31,7 @@ const (
pathRepos = "%s/api/user/repos" pathRepos = "%s/api/user/repos"
pathRepo = "%s/api/repos/%s/%s" pathRepo = "%s/api/repos/%s/%s"
pathChown = "%s/api/repos/%s/%s/chown" pathChown = "%s/api/repos/%s/%s/chown"
pathRepair = "%s/api/repos/%s/%s/repair"
pathBuilds = "%s/api/repos/%s/%s/builds" pathBuilds = "%s/api/repos/%s/%s/builds"
pathBuild = "%s/api/repos/%s/%s/builds/%v" pathBuild = "%s/api/repos/%s/%s/builds/%v"
pathApprove = "%s/api/repos/%s/%s/builds/%d/approve" 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 return out, err
} }
// RepoChow updates a repository owner. // RepoChown updates a repository owner.
func (c *client) RepoChown(owner string, name string) (*model.Repo, error) { func (c *client) RepoChown(owner string, name string) (*model.Repo, error) {
out := new(model.Repo) out := new(model.Repo)
uri := fmt.Sprintf(pathChown, c.base, owner, name) 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 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. // RepoPatch updates a repository.
func (c *client) RepoPatch(owner, name string, in *model.RepoPatch) (*model.Repo, error) { func (c *client) RepoPatch(owner, name string, in *model.RepoPatch) (*model.Repo, error) {
out := new(model.Repo) out := new(model.Repo)

View file

@ -104,6 +104,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler {
repo.PATCH("", session.MustPush, server.PatchRepo) repo.PATCH("", session.MustPush, server.PatchRepo)
repo.DELETE("", session.MustRepoAdmin(), server.DeleteRepo) repo.DELETE("", session.MustRepoAdmin(), server.DeleteRepo)
repo.POST("/chown", session.MustRepoAdmin(), server.ChownRepo) 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", session.MustPush, server.PostBuild)
repo.POST("/builds/:number/approve", session.MustPush, server.PostApproval) repo.POST("/builds/:number/approve", session.MustPush, server.PostApproval)

View file

@ -173,3 +173,33 @@ func DeleteRepo(c *gin.Context) {
remote.Deactivate(user, repo, httputil.GetURL(c.Request)) remote.Deactivate(user, repo, httputil.GetURL(c.Request))
c.Writer.WriteHeader(http.StatusOK) 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)
}