diff --git a/plugin/notify/webhook/webhook.go b/plugin/notify/webhook/webhook.go index b35b69f5d..b9aff0ab5 100644 --- a/plugin/notify/webhook/webhook.go +++ b/plugin/notify/webhook/webhook.go @@ -29,10 +29,11 @@ func (w *Webhook) Send(context *model.Request) error { func (w *Webhook) send(context *model.Request) error { // data will get posted in this format data := struct { + From string `json:"from_url"` Owner *model.User `json:"owner"` Repo *model.Repo `json:"repository"` Commit *model.Commit `json:"commit"` - }{context.User, context.Repo, context.Commit} + }{context.Host, context.User, context.Repo, context.Commit} // data json encoded payload, err := json.Marshal(data) diff --git a/plugin/publish/docker_test.go b/plugin/publish/docker_test.go index ffee89854..f97ac8c66 100644 --- a/plugin/publish/docker_test.go +++ b/plugin/publish/docker_test.go @@ -6,7 +6,7 @@ import ( "github.com/drone/drone/shared/build/buildfile" "github.com/drone/drone/shared/build/repo" - "gopkg.in/v1/yaml" + "gopkg.in/yaml.v1" ) type PublishToDrone struct { diff --git a/plugin/publish/github_test.go b/plugin/publish/github_test.go index 33e995b44..7fcdfaaa9 100644 --- a/plugin/publish/github_test.go +++ b/plugin/publish/github_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "gopkg.in/v1/yaml" + "gopkg.in/yaml.v1" ) var validcfg = map[string]interface{}{ diff --git a/server/datastore/database/user.go b/server/datastore/database/user.go index 25de08026..f6b25040d 100644 --- a/server/datastore/database/user.go +++ b/server/datastore/database/user.go @@ -49,20 +49,15 @@ func (db *Userstore) GetUserList() ([]*model.User, error) { // PostUser saves a User in the datastore. func (db *Userstore) PostUser(user *model.User) error { - if user.Created == 0 { - user.Created = time.Now().UTC().Unix() - } + user.Created = time.Now().UTC().Unix() user.Updated = time.Now().UTC().Unix() - return meddler.Save(db, userTable, user) + return meddler.Insert(db, userTable, user) } // PutUser saves a user in the datastore. func (db *Userstore) PutUser(user *model.User) error { - if user.Created == 0 { - user.Created = time.Now().UTC().Unix() - } user.Updated = time.Now().UTC().Unix() - return meddler.Save(db, userTable, user) + return meddler.Update(db, userTable, user) } // DelUser removes the user from the datastore. diff --git a/server/handler/login.go b/server/handler/login.go index 285702d09..2f08debed 100644 --- a/server/handler/login.go +++ b/server/handler/login.go @@ -70,6 +70,13 @@ func GetLogin(c web.C, w http.ResponseWriter, r *http.Request) { return } + // the user id should NEVER equal zero + if u.ID == 0 { + log.Println("Unable to create account. User ID is zero") + w.WriteHeader(http.StatusInternalServerError) + return + } + // if this is the first user, they // should be an admin. if u.ID == 1 { diff --git a/shared/model/request.go b/shared/model/request.go index 594cbeb2f..5cfd0abfd 100644 --- a/shared/model/request.go +++ b/shared/model/request.go @@ -1,5 +1,9 @@ package model +import ( + "fmt" +) + type Request struct { Host string `json:"-"` User *User `json:"-"` @@ -7,3 +11,16 @@ type Request struct { Commit *Commit `json:"commit"` Prior *Commit `json:"prior_commit"` } + +// URL returns the link to the commit in +// string format. +func (r *Request) URL() string { + return fmt.Sprintf("%s/%s/%s/%s/%s/%s", + r.Host, + r.Repo.Host, + r.Repo.Owner, + r.Repo.Name, + r.Commit.Branch, + r.Commit.Sha, + ) +}