bitbucket code is mostly working

This commit is contained in:
Brad Rydzewski 2015-10-04 18:34:06 -07:00
parent 528fbb0f2c
commit ac6133c922
5 changed files with 60 additions and 6 deletions

View file

@ -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) {

View file

@ -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"`

View file

@ -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
}
}

View file

@ -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
}

View file

@ -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))
}