persist self url in repo field

This commit is contained in:
Brad Rydzewski 2015-05-12 23:58:30 -07:00
parent ed0719c624
commit 1ef6dc0bc6
7 changed files with 15 additions and 13 deletions

View file

@ -9,6 +9,7 @@ type Repo struct {
Token string `meddler:"repo_token" json:"-"` Token string `meddler:"repo_token" json:"-"`
Language string `meddler:"repo_lang" json:"language"` Language string `meddler:"repo_lang" json:"language"`
Private bool `meddler:"repo_private" json:"private"` Private bool `meddler:"repo_private" json:"private"`
Self string `meddler:"repo_self" json:"self_url"`
Link string `meddler:"repo_link" json:"link_url"` Link string `meddler:"repo_link" json:"link_url"`
Clone string `meddler:"repo_clone" json:"clone_url"` Clone string `meddler:"repo_clone" json:"clone_url"`
Branch string `meddler:"repo_branch" json:"default_branch"` Branch string `meddler:"repo_branch" json:"default_branch"`

View file

@ -64,6 +64,7 @@ CREATE TABLE IF NOT EXISTS repos (
,repo_branch VARCHAR(255) ,repo_branch VARCHAR(255)
,repo_private BOOLEAN ,repo_private BOOLEAN
,repo_trusted BOOLEAN ,repo_trusted BOOLEAN
,repo_self VARCHAR(1024)
,repo_link VARCHAR(1024) ,repo_link VARCHAR(1024)
,repo_clone VARCHAR(1024) ,repo_clone VARCHAR(1024)
,repo_push BOOLEAN ,repo_push BOOLEAN

View file

@ -212,12 +212,12 @@ func (g *GitHub) Deactivate(u *common.User, r *common.Repo, link string) error {
return DeleteHook(client, r.Owner, r.Name, link) return DeleteHook(client, r.Owner, r.Name, link)
} }
func (g *GitHub) Status(u *common.User, r *common.Repo, c *common.Commit, link string) error { func (g *GitHub) Status(u *common.User, r *common.Repo, c *common.Commit) error {
client := NewClient(g.API, u.Token, g.SkipVerify) client := NewClient(g.API, u.Token, g.SkipVerify)
if len(c.PullRequest) == 0 { if len(c.PullRequest) == 0 {
return nil return nil
} }
link := fmt.Sprintf("%s/%v", r.Self, c.Sequence)
status := getStatus(c.State) status := getStatus(c.State)
desc := getDesc(c.State) desc := getDesc(c.State)
data := github.RepoStatus{ data := github.RepoStatus{

View file

@ -27,7 +27,7 @@ type Remote interface {
// Status sends the commit status to the remote system. // Status sends the commit status to the remote system.
// An example would be the GitHub pull request status. // An example would be the GitHub pull request status.
Status(u *common.User, r *common.Repo, c *common.Commit, link string) error Status(u *common.User, r *common.Repo, c *common.Commit) error
// Netrc returns a .netrc file that can be used to clone // Netrc returns a .netrc file that can be used to clone
// private repositories from a remote system. // private repositories from a remote system.

View file

@ -35,7 +35,10 @@ func (u *updater) SetCommit(user *common.User, r *common.Repo, c *common.Commit)
return err return err
} }
// TODO invoke remote.Status to set the build status err = u.remote.Status(user, r, c)
if err != nil {
// log err
}
msg, err := json.Marshal(c) msg, err := json.Marshal(c)
if err != nil { if err != nil {

View file

@ -1,12 +1,10 @@
package server package server
import ( import (
"fmt"
"strings" "strings"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/drone/drone/common" "github.com/drone/drone/common"
"github.com/drone/drone/common/httputil"
"github.com/drone/drone/parser" "github.com/drone/drone/parser"
"github.com/drone/drone/parser/inject" "github.com/drone/drone/parser/inject"
"github.com/drone/drone/parser/matrix" "github.com/drone/drone/parser/matrix"
@ -147,13 +145,7 @@ func PostHook(c *gin.Context) {
c.JSON(200, commit) c.JSON(200, commit)
link := fmt.Sprintf( err = remote.Status(user, repo, commit)
"%s/%s/%d",
httputil.GetURL(c.Request),
repo.FullName,
commit.Sequence,
)
err = remote.Status(user, repo, commit, link)
if err != nil { if err != nil {
log.Errorf("error setting commit status for %s/%d", repo.FullName, commit.Sequence) log.Errorf("error setting commit status for %s/%d", repo.FullName, commit.Sequence)
} }

View file

@ -210,6 +210,11 @@ func PostRepo(c *gin.Context) {
r.UserID = user.ID r.UserID = user.ID
r.PostCommit = true r.PostCommit = true
r.PullRequest = true r.PullRequest = true
r.Self = fmt.Sprintf(
"%s/%s",
httputil.GetURL(c.Request),
r.FullName,
)
// generate an RSA key and add to the repo // generate an RSA key and add to the repo
key, err := sshutil.GeneratePrivateKey() key, err := sshutil.GeneratePrivateKey()