mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-04-26 13:34:45 +00:00
Move Badge & CCMenue into own packages (#908)
* move badge generation into own package * move ccmenue away from models * fix misspell
This commit is contained in:
parent
be0dfb280c
commit
c350af645b
5 changed files with 88 additions and 57 deletions
|
@ -19,24 +19,18 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/model"
|
"github.com/woodpecker-ci/woodpecker/server/badges"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/ccmenu"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/store"
|
"github.com/woodpecker-ci/woodpecker/server/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
badgeSuccess = `<svg xmlns="http://www.w3.org/2000/svg" width="91" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="91" height="20" fill="#555"/><rect rx="3" x="37" width="54" height="20" fill="#4c1"/><path fill="#4c1" d="M37 0h4v20h-4z"/><rect rx="3" width="91" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="63" y="15" fill="#010101" fill-opacity=".3">success</text><text x="63" y="14">success</text></g></svg>`
|
|
||||||
badgeFailure = `<svg xmlns="http://www.w3.org/2000/svg" width="83" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="83" height="20" fill="#555"/><rect rx="3" x="37" width="46" height="20" fill="#e05d44"/><path fill="#e05d44" d="M37 0h4v20h-4z"/><rect rx="3" width="83" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="59" y="15" fill="#010101" fill-opacity=".3">failure</text><text x="59" y="14">failure</text></g></svg>`
|
|
||||||
badgeStarted = `<svg xmlns="http://www.w3.org/2000/svg" width="87" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="87" height="20" fill="#555"/><rect rx="3" x="37" width="50" height="20" fill="#dfb317"/><path fill="#dfb317" d="M37 0h4v20h-4z"/><rect rx="3" width="87" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="61" y="15" fill="#010101" fill-opacity=".3">started</text><text x="61" y="14">started</text></g></svg>`
|
|
||||||
badgeError = `<svg xmlns="http://www.w3.org/2000/svg" width="76" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="76" height="20" fill="#555"/><rect rx="3" x="37" width="39" height="20" fill="#9f9f9f"/><path fill="#9f9f9f" d="M37 0h4v20h-4z"/><rect rx="3" width="76" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="55.5" y="15" fill="#010101" fill-opacity=".3">error</text><text x="55.5" y="14">error</text></g></svg>`
|
|
||||||
badgeNone = `<svg xmlns="http://www.w3.org/2000/svg" width="75" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="75" height="20" fill="#555"/><rect rx="3" x="37" width="38" height="20" fill="#9f9f9f"/><path fill="#9f9f9f" d="M37 0h4v20h-4z"/><rect rx="3" width="75" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="55" y="15" fill="#010101" fill-opacity=".3">none</text><text x="55" y="14">none</text></g></svg>`
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetBadge(c *gin.Context) {
|
func GetBadge(c *gin.Context) {
|
||||||
_store := store.FromContext(c)
|
_store := store.FromContext(c)
|
||||||
repo, err := _store.GetRepoName(c.Param("owner") + "/" + c.Param("name"))
|
repo, err := _store.GetRepoName(c.Param("owner") + "/" + c.Param("name"))
|
||||||
|
@ -45,10 +39,6 @@ func GetBadge(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// an SVG response is always served, even when error, so
|
|
||||||
// we can go ahead and set the content type appropriately.
|
|
||||||
c.Writer.Header().Set("Content-Type", "image/svg+xml")
|
|
||||||
|
|
||||||
// if no commit was found then display
|
// if no commit was found then display
|
||||||
// the 'none' badge, instead of throwing
|
// the 'none' badge, instead of throwing
|
||||||
// an error response
|
// an error response
|
||||||
|
@ -60,22 +50,12 @@ func GetBadge(c *gin.Context) {
|
||||||
build, err := _store.GetBuildLast(repo, branch)
|
build, err := _store.GetBuildLast(repo, branch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn().Err(err).Msg("")
|
log.Warn().Err(err).Msg("")
|
||||||
c.String(200, badgeNone)
|
build = nil
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch build.Status {
|
// we serve an SVG, so set content type appropriately.
|
||||||
case model.StatusSuccess:
|
c.Writer.Header().Set("Content-Type", "image/svg+xml")
|
||||||
c.String(200, badgeSuccess)
|
c.String(http.StatusOK, badges.Generate(build))
|
||||||
case model.StatusFailure:
|
|
||||||
c.String(200, badgeFailure)
|
|
||||||
case model.StatusError, model.StatusKilled:
|
|
||||||
c.String(200, badgeError)
|
|
||||||
case model.StatusPending, model.StatusRunning:
|
|
||||||
c.String(200, badgeStarted)
|
|
||||||
default:
|
|
||||||
c.String(200, badgeNone)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCC(c *gin.Context) {
|
func GetCC(c *gin.Context) {
|
||||||
|
@ -93,6 +73,6 @@ func GetCC(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/%s/%d", server.Config.Server.Host, repo.FullName, builds[0].Number)
|
url := fmt.Sprintf("%s/%s/%d", server.Config.Server.Host, repo.FullName, builds[0].Number)
|
||||||
cc := model.NewCC(repo, builds[0], url)
|
cc := ccmenu.New(repo, builds[0], url)
|
||||||
c.XML(200, cc)
|
c.XML(200, cc)
|
||||||
}
|
}
|
||||||
|
|
41
server/badges/badges.go
Normal file
41
server/badges/badges.go
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright 2022 Woodpecker Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package badges
|
||||||
|
|
||||||
|
import "github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
|
|
||||||
|
var (
|
||||||
|
badgeSuccess = `<svg xmlns="http://www.w3.org/2000/svg" width="91" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="91" height="20" fill="#555"/><rect rx="3" x="37" width="54" height="20" fill="#4c1"/><path fill="#4c1" d="M37 0h4v20h-4z"/><rect rx="3" width="91" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="63" y="15" fill="#010101" fill-opacity=".3">success</text><text x="63" y="14">success</text></g></svg>`
|
||||||
|
badgeFailure = `<svg xmlns="http://www.w3.org/2000/svg" width="83" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="83" height="20" fill="#555"/><rect rx="3" x="37" width="46" height="20" fill="#e05d44"/><path fill="#e05d44" d="M37 0h4v20h-4z"/><rect rx="3" width="83" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="59" y="15" fill="#010101" fill-opacity=".3">failure</text><text x="59" y="14">failure</text></g></svg>`
|
||||||
|
badgeStarted = `<svg xmlns="http://www.w3.org/2000/svg" width="87" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="87" height="20" fill="#555"/><rect rx="3" x="37" width="50" height="20" fill="#dfb317"/><path fill="#dfb317" d="M37 0h4v20h-4z"/><rect rx="3" width="87" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="61" y="15" fill="#010101" fill-opacity=".3">started</text><text x="61" y="14">started</text></g></svg>`
|
||||||
|
badgeError = `<svg xmlns="http://www.w3.org/2000/svg" width="76" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="76" height="20" fill="#555"/><rect rx="3" x="37" width="39" height="20" fill="#9f9f9f"/><path fill="#9f9f9f" d="M37 0h4v20h-4z"/><rect rx="3" width="76" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="55.5" y="15" fill="#010101" fill-opacity=".3">error</text><text x="55.5" y="14">error</text></g></svg>`
|
||||||
|
badgeNone = `<svg xmlns="http://www.w3.org/2000/svg" width="75" height="20"><linearGradient id="a" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><rect rx="3" width="75" height="20" fill="#555"/><rect rx="3" x="37" width="38" height="20" fill="#9f9f9f"/><path fill="#9f9f9f" d="M37 0h4v20h-4z"/><rect rx="3" width="75" height="20" fill="url(#a)"/><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="19.5" y="15" fill="#010101" fill-opacity=".3">build</text><text x="19.5" y="14">build</text><text x="55" y="15" fill="#010101" fill-opacity=".3">none</text><text x="55" y="14">none</text></g></svg>`
|
||||||
|
)
|
||||||
|
|
||||||
|
// Generate an SVG badge based on a build
|
||||||
|
func Generate(build *model.Build) string {
|
||||||
|
switch build.Status {
|
||||||
|
case model.StatusSuccess:
|
||||||
|
return badgeSuccess
|
||||||
|
case model.StatusFailure:
|
||||||
|
return badgeFailure
|
||||||
|
case model.StatusError, model.StatusKilled:
|
||||||
|
return badgeError
|
||||||
|
case model.StatusPending, model.StatusRunning:
|
||||||
|
return badgeStarted
|
||||||
|
default:
|
||||||
|
return badgeNone
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Copyright 2022 Woodpecker Authors
|
||||||
// Copyright 2018 Drone.IO Inc.
|
// Copyright 2018 Drone.IO Inc.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -12,14 +13,21 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package model
|
package ccmenu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// CCMenu displays the build status of projects on a ci server as an item in the Mac's menu bar.
|
||||||
|
// It started as part of the CruiseControl project that built the first continuous integration server.
|
||||||
|
//
|
||||||
|
// http://ccmenu.org/
|
||||||
|
|
||||||
type CCProjects struct {
|
type CCProjects struct {
|
||||||
XMLName xml.Name `xml:"Projects"`
|
XMLName xml.Name `xml:"Projects"`
|
||||||
Project *CCProject `xml:"Project"`
|
Project *CCProject `xml:"Project"`
|
||||||
|
@ -35,7 +43,7 @@ type CCProject struct {
|
||||||
WebURL string `xml:"webUrl,attr"`
|
WebURL string `xml:"webUrl,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCC(r *Repo, b *Build, link string) *CCProjects {
|
func New(r *model.Repo, b *model.Build, link string) *CCProjects {
|
||||||
proj := &CCProject{
|
proj := &CCProject{
|
||||||
Name: r.FullName,
|
Name: r.FullName,
|
||||||
WebURL: link,
|
WebURL: link,
|
||||||
|
@ -46,8 +54,8 @@ func NewCC(r *Repo, b *Build, link string) *CCProjects {
|
||||||
|
|
||||||
// if the build is not currently running then
|
// if the build is not currently running then
|
||||||
// we can return the latest build status.
|
// we can return the latest build status.
|
||||||
if b.Status != StatusPending &&
|
if b.Status != model.StatusPending &&
|
||||||
b.Status != StatusRunning {
|
b.Status != model.StatusRunning {
|
||||||
proj.Activity = "Sleeping"
|
proj.Activity = "Sleeping"
|
||||||
proj.LastBuildTime = time.Unix(b.Started, 0).Format(time.RFC3339)
|
proj.LastBuildTime = time.Unix(b.Started, 0).Format(time.RFC3339)
|
||||||
proj.LastBuildLabel = strconv.FormatInt(b.Number, 10)
|
proj.LastBuildLabel = strconv.FormatInt(b.Number, 10)
|
||||||
|
@ -56,11 +64,11 @@ func NewCC(r *Repo, b *Build, link string) *CCProjects {
|
||||||
// ensure the last build Status accepts a valid
|
// ensure the last build Status accepts a valid
|
||||||
// ccmenu enumeration
|
// ccmenu enumeration
|
||||||
switch b.Status {
|
switch b.Status {
|
||||||
case StatusError, StatusKilled:
|
case model.StatusError, model.StatusKilled:
|
||||||
proj.LastBuildStatus = "Exception"
|
proj.LastBuildStatus = "Exception"
|
||||||
case StatusSuccess:
|
case model.StatusSuccess:
|
||||||
proj.LastBuildStatus = "Success"
|
proj.LastBuildStatus = "Success"
|
||||||
case StatusFailure:
|
case model.StatusFailure:
|
||||||
proj.LastBuildStatus = "Failure"
|
proj.LastBuildStatus = "Failure"
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,15 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package model
|
package ccmenu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/franela/goblin"
|
"github.com/franela/goblin"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCC(t *testing.T) {
|
func TestCC(t *testing.T) {
|
||||||
|
@ -27,15 +29,15 @@ func TestCC(t *testing.T) {
|
||||||
g.It("Should create a project", func() {
|
g.It("Should create a project", func() {
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
nowFmt := time.Unix(now, 0).Format(time.RFC3339)
|
nowFmt := time.Unix(now, 0).Format(time.RFC3339)
|
||||||
r := &Repo{
|
r := &model.Repo{
|
||||||
FullName: "foo/bar",
|
FullName: "foo/bar",
|
||||||
}
|
}
|
||||||
b := &Build{
|
b := &model.Build{
|
||||||
Status: StatusSuccess,
|
Status: model.StatusSuccess,
|
||||||
Number: 1,
|
Number: 1,
|
||||||
Started: now,
|
Started: now,
|
||||||
}
|
}
|
||||||
cc := NewCC(r, b, "http://localhost/foo/bar/1")
|
cc := New(r, b, "http://localhost/foo/bar/1")
|
||||||
|
|
||||||
g.Assert(cc.Project.Name).Equal("foo/bar")
|
g.Assert(cc.Project.Name).Equal("foo/bar")
|
||||||
g.Assert(cc.Project.Activity).Equal("Sleeping")
|
g.Assert(cc.Project.Activity).Equal("Sleeping")
|
||||||
|
@ -46,49 +48,49 @@ func TestCC(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should properly label exceptions", func() {
|
g.It("Should properly label exceptions", func() {
|
||||||
r := &Repo{FullName: "foo/bar"}
|
r := &model.Repo{FullName: "foo/bar"}
|
||||||
b := &Build{
|
b := &model.Build{
|
||||||
Status: StatusError,
|
Status: model.StatusError,
|
||||||
Number: 1,
|
Number: 1,
|
||||||
Started: 1257894000,
|
Started: 1257894000,
|
||||||
}
|
}
|
||||||
cc := NewCC(r, b, "http://localhost/foo/bar/1")
|
cc := New(r, b, "http://localhost/foo/bar/1")
|
||||||
g.Assert(cc.Project.LastBuildStatus).Equal("Exception")
|
g.Assert(cc.Project.LastBuildStatus).Equal("Exception")
|
||||||
g.Assert(cc.Project.Activity).Equal("Sleeping")
|
g.Assert(cc.Project.Activity).Equal("Sleeping")
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should properly label success", func() {
|
g.It("Should properly label success", func() {
|
||||||
r := &Repo{FullName: "foo/bar"}
|
r := &model.Repo{FullName: "foo/bar"}
|
||||||
b := &Build{
|
b := &model.Build{
|
||||||
Status: StatusSuccess,
|
Status: model.StatusSuccess,
|
||||||
Number: 1,
|
Number: 1,
|
||||||
Started: 1257894000,
|
Started: 1257894000,
|
||||||
}
|
}
|
||||||
cc := NewCC(r, b, "http://localhost/foo/bar/1")
|
cc := New(r, b, "http://localhost/foo/bar/1")
|
||||||
g.Assert(cc.Project.LastBuildStatus).Equal("Success")
|
g.Assert(cc.Project.LastBuildStatus).Equal("Success")
|
||||||
g.Assert(cc.Project.Activity).Equal("Sleeping")
|
g.Assert(cc.Project.Activity).Equal("Sleeping")
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should properly label failure", func() {
|
g.It("Should properly label failure", func() {
|
||||||
r := &Repo{FullName: "foo/bar"}
|
r := &model.Repo{FullName: "foo/bar"}
|
||||||
b := &Build{
|
b := &model.Build{
|
||||||
Status: StatusFailure,
|
Status: model.StatusFailure,
|
||||||
Number: 1,
|
Number: 1,
|
||||||
Started: 1257894000,
|
Started: 1257894000,
|
||||||
}
|
}
|
||||||
cc := NewCC(r, b, "http://localhost/foo/bar/1")
|
cc := New(r, b, "http://localhost/foo/bar/1")
|
||||||
g.Assert(cc.Project.LastBuildStatus).Equal("Failure")
|
g.Assert(cc.Project.LastBuildStatus).Equal("Failure")
|
||||||
g.Assert(cc.Project.Activity).Equal("Sleeping")
|
g.Assert(cc.Project.Activity).Equal("Sleeping")
|
||||||
})
|
})
|
||||||
|
|
||||||
g.It("Should properly label running", func() {
|
g.It("Should properly label running", func() {
|
||||||
r := &Repo{FullName: "foo/bar"}
|
r := &model.Repo{FullName: "foo/bar"}
|
||||||
b := &Build{
|
b := &model.Build{
|
||||||
Status: StatusRunning,
|
Status: model.StatusRunning,
|
||||||
Number: 1,
|
Number: 1,
|
||||||
Started: 1257894000,
|
Started: 1257894000,
|
||||||
}
|
}
|
||||||
cc := NewCC(r, b, "http://localhost/foo/bar/1")
|
cc := New(r, b, "http://localhost/foo/bar/1")
|
||||||
g.Assert(cc.Project.Activity).Equal("Building")
|
g.Assert(cc.Project.Activity).Equal("Building")
|
||||||
g.Assert(cc.Project.LastBuildStatus).Equal("Unknown")
|
g.Assert(cc.Project.LastBuildStatus).Equal("Unknown")
|
||||||
g.Assert(cc.Project.LastBuildLabel).Equal("Unknown")
|
g.Assert(cc.Project.LastBuildLabel).Equal("Unknown")
|
|
@ -56,7 +56,7 @@ func (s storage) GetBuildLast(repo *model.Repo, branch string) (*model.Build, er
|
||||||
build := &model.Build{
|
build := &model.Build{
|
||||||
RepoID: repo.ID,
|
RepoID: repo.ID,
|
||||||
Branch: branch,
|
Branch: branch,
|
||||||
Event: "push",
|
Event: model.EventPush,
|
||||||
}
|
}
|
||||||
return build, wrapGet(s.engine.Desc("build_number").Get(build))
|
return build, wrapGet(s.engine.Desc("build_number").Get(build))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue