From 10d305200dc027c984a7bba868ad3a1f91d7219e Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 26 Oct 2015 16:17:43 -0700 Subject: [PATCH 1/4] Fix badge markup on repo badges page --- template/amber/repo_badge.amber | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/amber/repo_badge.amber b/template/amber/repo_badge.amber index 75a760263..68f955455 100644 --- a/template/amber/repo_badge.amber +++ b/template/amber/repo_badge.amber @@ -28,7 +28,7 @@ block content div.col-md-3 Markup div.col-md-9 pre - | <a href="#{Link}/api/badges/#{Repo.FullName}/status.svg"><img src="#{Link}/#{Repo.FullName}" /></a> + | <a href="#{Link}/#{Repo.FullName}"><img src="#{Link}/api/badges/#{Repo.FullName}/status.svg" /></a> div.row div.col-md-3 CC Menu div.col-md-9 From 001c06bb2c5f58242b6fb03b5dbe1ebed9c423f9 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 26 Oct 2015 17:29:29 -0700 Subject: [PATCH 2/4] parses github deployment hooks for #1144 into build objects --- remote/github/types.go | 34 ++++++++++++++++++++++++++++- static/styles/modules/timeline.sass | 2 +- static/styles_gen/style.css | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/remote/github/types.go b/remote/github/types.go index f298f5852..2f0bac4fc 100644 --- a/remote/github/types.go +++ b/remote/github/types.go @@ -29,7 +29,39 @@ type pushHook struct { Sender struct { Login string `json:"login"` Avatar string `json:"avatar_url"` - } + } `json:"sender"` + + Repo struct { + Owner struct { + Login string `json:"login"` + Name string `json:"name"` + } `json:"owner"` + + Name string `json:"name"` + FullName string `json:"full_name"` + Language string `json:"language"` + Private bool `json:"private"` + HTMLURL string `json:"html_url"` + CloneURL string `json:"clone_url"` + DefaultBranch string `json:"default_branch"` + } `json:"repository"` +} + +type deployHook struct { + Deployment struct { + ID int64 `json:"id"` + Sha string `json:"sha"` + Ref string `json:"ref"` + Task string `json:"task"` + Env string `json:"environment"` + Url string `json:"url"` + Desc string `json:"description"` + } `json:"deployment"` + + Sender struct { + Login string `json:"login"` + Avatar string `json:"avatar_url"` + } `json:"sender"` Repo struct { Owner struct { diff --git a/static/styles/modules/timeline.sass b/static/styles/modules/timeline.sass index 342fa421c..b1f74e6da 100644 --- a/static/styles/modules/timeline.sass +++ b/static/styles/modules/timeline.sass @@ -10,7 +10,7 @@ border-radius: 0px; border-top: 1px solid #eceeef; text-decoration: none; - color: 2b303b; + color: #2b303b; .card-header background: #FFF; border: none; diff --git a/static/styles_gen/style.css b/static/styles_gen/style.css index 4acd75405..a96f11fd1 100644 --- a/static/styles_gen/style.css +++ b/static/styles_gen/style.css @@ -88,7 +88,7 @@ input[type=range]:focus::-ms-fill-upper { background: #367ebd; } .timeline { padding-left: 50px; position: relative; margin-top: 10px; margin-bottom: 40px; } -.timeline .card { display: flex; border: none; border-radius: 0px; border-top: 1px solid #eceeef; text-decoration: none; color: 2b303b; } +.timeline .card { display: flex; border: none; border-radius: 0px; border-top: 1px solid #eceeef; text-decoration: none; color: #2b303b; } .timeline .card .card-header { background: #FFF; border: none; padding: 0px; width: 50px; min-width: 50px; max-width: 50px; padding-top: 30px; } From e71905273dab638257a593920113304a15cfa762 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 26 Oct 2015 17:31:26 -0700 Subject: [PATCH 3/4] parses github hooks --- remote/github/github.go | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/remote/github/github.go b/remote/github/github.go index af36ce486..b1e520dc6 100644 --- a/remote/github/github.go +++ b/remote/github/github.go @@ -291,6 +291,8 @@ func (g *Github) Hook(r *http.Request) (*model.Repo, *model.Build, error) { return g.pullRequest(r) case "push": return g.push(r) + case "deployment": + return g.deployment(r) default: return nil, nil, nil } @@ -403,6 +405,56 @@ func (g *Github) pullRequest(r *http.Request) (*model.Repo, *model.Build, error) return repo, build, nil } +func (g *Github) deployment(r *http.Request) (*model.Repo, *model.Build, error) { + payload := GetPayload(r) + hook := &deployHook{} + + err := json.Unmarshal(payload, hook) + if err != nil { + return nil, nil, err + } + + repo := &model.Repo{} + repo.Owner = hook.Repo.Owner.Login + if len(repo.Owner) == 0 { + repo.Owner = hook.Repo.Owner.Name + } + repo.Name = hook.Repo.Name + repo.FullName = fmt.Sprintf("%s/%s", repo.Owner, repo.Name) + repo.Link = hook.Repo.HTMLURL + repo.IsPrivate = hook.Repo.Private + repo.Clone = hook.Repo.CloneURL + repo.Branch = hook.Repo.DefaultBranch + + // ref can be + // branch, tag, or sha + + build := &model.Build{} + build.Event = model.EventDeploy + build.Commit = hook.Deployment.Sha + build.Link = hook.Deployment.Url + build.Message = hook.Deployment.Desc + build.Avatar = hook.Sender.Avatar + build.Author = hook.Sender.Login + build.Ref = hook.Deployment.Ref + build.Branch = hook.Deployment.Ref + + // if the ref is a sha or short sha we need to manually + // construct the ref. + if strings.HasPrefix(build.Commit, build.Ref) || build.Commit == build.Ref { + build.Branch = repo.Branch + build.Ref = fmt.Sprintf("refs/heads/%s", repo.Branch) + + } + // if the ref is a branch we should make sure it has refs/heads prefix + if !strings.HasPrefix(build.Ref, "refs/") { // branch or tag + build.Ref = fmt.Sprintf("refs/heads/%s", build.Branch) + + } + + return repo, build, nil +} + const ( StatusPending = "pending" StatusSuccess = "success" From d54480b1218956189e4ec9b2a450845f6cb590ca Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Mon, 26 Oct 2015 21:01:10 -0700 Subject: [PATCH 4/4] show all repos until I have a better solution --- controller/pages.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/controller/pages.go b/controller/pages.go index 7b39cd7bb..31a014203 100644 --- a/controller/pages.go +++ b/controller/pages.go @@ -43,15 +43,15 @@ func ShowIndex(c *gin.Context) { // for each repository in the remote system we get // the intersection of those repostiories in Drone - repos_, err := store.GetRepoListOf(c, repos) - if err != nil { - log.Errorf("Failure to get repository list for %s. %s.", - user.Login, err) - } + // repos_, err := store.GetRepoListOf(c, repos) + // if err != nil { + // log.Errorf("Failure to get repository list for %s. %s.", + // user.Login, err) + // } c.HTML(200, "repos.html", gin.H{ "User": user, - "Repos": repos_, + "Repos": repos, }) }