diff --git a/controller/repo.go b/controller/repo.go index d1589d246..7dab814ff 100644 --- a/controller/repo.go +++ b/controller/repo.go @@ -199,14 +199,18 @@ func GetRepoKey(c *gin.Context) { func DeleteRepo(c *gin.Context) { db := context.Database(c) + remote := context.Remote(c) repo := session.Repo(c) + user := session.User(c) err := model.DeleteRepo(db, repo) if err != nil { c.AbortWithError(http.StatusInternalServerError, err) - } else { - c.Writer.WriteHeader(http.StatusOK) + return } + + remote.Deactivate(user, repo, httputil.GetURL(c.Request)) + c.Writer.WriteHeader(http.StatusOK) } func PostSecure(c *gin.Context) { diff --git a/model/user.go b/model/user.go index 2931d3756..a413b7fb2 100644 --- a/model/user.go +++ b/model/user.go @@ -10,7 +10,7 @@ type User struct { Login string `json:"login" meddler:"user_login"` Token string `json:"-" meddler:"user_token"` Secret string `json:"-" meddler:"user_secret"` - Expiry int64 `json:"-" meddler:"user_expiry"` + Expiry int64 `json:"-" meddler:"-"` Email string `json:"email" meddler:"user_email"` Avatar string `json:"avatar_url" meddler:"user_avatar"` Active bool `json:"active," meddler:"user_active"` diff --git a/remote/bitbucket/bitbucket.go b/remote/bitbucket/bitbucket.go index 9aa6e32a4..26107f3ba 100644 --- a/remote/bitbucket/bitbucket.go +++ b/remote/bitbucket/bitbucket.go @@ -306,7 +306,10 @@ func (bb *Bitbucket) Activate(u *model.User, r *model.Repo, k *model.Key, link s return err } if hookurl.Host == linkurl.Host { - client.DeleteHook(r.Owner, r.Name, hook.Uuid) + err = client.DeleteHook(r.Owner, r.Name, hook.Uuid) + if err != nil { + log.Errorf("unable to delete hook %s. %s", hookurl.Host, err) + } break } } diff --git a/remote/bitbucket/helper.go b/remote/bitbucket/helper.go index c417857ab..17b7c00b3 100644 --- a/remote/bitbucket/helper.go +++ b/remote/bitbucket/helper.go @@ -1,6 +1,7 @@ package bitbucket import ( + "net/url" "strings" "github.com/drone/drone/model" @@ -41,6 +42,14 @@ func convertRepo(from *Repo) *model.Repo { repo.Clone = repo.Link } + // if bitbucket tries to automatically populate the user + // in the url we must strip it out. + clone, err := url.Parse(repo.Clone) + if err == nil { + clone.User = nil + repo.Clone = clone.String() + } + return &repo } diff --git a/remote/bitbucket/types.go b/remote/bitbucket/types.go index abe409424..8f92948e3 100644 --- a/remote/bitbucket/types.go +++ b/remote/bitbucket/types.go @@ -116,13 +116,51 @@ type PushHook struct { } `json:"push"` } +type PullRequestHook struct { + Actor Account `json:"actor"` + Repo Repo `json:"repository"` + PullRequest struct { + ID int `json:"id"` + Type string `json:"type"` + Reason string `json:"reason"` + Desc string `json:"description"` + Title string `json:"title"` + State string `json:"state"` + Links Links `json:"links"` + Created time.Time `json:"created_on"` + Updated time.Time `json:"updated_on"` + + Source struct { + Repo Repo `json:"repsoitory"` + Commit struct { + Hash string `json:"hash"` + Links Links `json:"links"` + } `json:"commit"` + Branch struct { + Name string `json:"name"` + } `json:"branch"` + } `json:"source"` + + Dest struct { + Repo Repo `json:"repsoitory"` + Commit struct { + Hash string `json:"hash"` + Links Links `json:"links"` + } `json:"commit"` + Branch struct { + Name string `json:"name"` + } `json:"branch"` + } `json:"destination"` + } `json:"pullrequest"` +} + type ListOpts struct { Page int PageLen int } func (o *ListOpts) Encode() string { - params := new(url.Values) + params := url.Values{} if o.Page != 0 { params.Set("page", strconv.Itoa(o.Page)) } @@ -139,7 +177,7 @@ type ListTeamOpts struct { } func (o *ListTeamOpts) Encode() string { - params := new(url.Values) + params := url.Values{} if o.Page != 0 { params.Set("page", strconv.Itoa(o.Page)) }