diff --git a/pkg/queue/worker.go b/pkg/queue/worker.go index 3ae07a187..8151b55a3 100644 --- a/pkg/queue/worker.go +++ b/pkg/queue/worker.go @@ -9,14 +9,15 @@ import ( // Work represents an item for work to be // processed by a worker. type Work struct { - System *common.System `json:"system"` - User *common.User `json:"user"` - Repo *common.Repo `json:"repo"` - Build *common.Build `json:"build"` - Keys *common.Keypair `json:"keypair"` - Netrc *common.Netrc `json:"netrc"` - Config []byte `json:"config"` - Secret []byte `json:"secret"` + System *common.System `json:"system"` + User *common.User `json:"user"` + Repo *common.Repo `json:"repo"` + Build *common.Build `json:"build"` + BuildPrev *common.Build `json:"build_last"` + Keys *common.Keypair `json:"keypair"` + Netrc *common.Netrc `json:"netrc"` + Config []byte `json:"config"` + Secret []byte `json:"secret"` } // represents a worker that has connected diff --git a/pkg/runner/builtin/worker.go b/pkg/runner/builtin/worker.go index b92894ca3..3e5270828 100644 --- a/pkg/runner/builtin/worker.go +++ b/pkg/runner/builtin/worker.go @@ -47,6 +47,7 @@ var ( type work struct { Repo *types.Repo `json:"repo"` Build *types.Build `json:"build"` + BuildLast *types.Build `json:"build_last"` Job *types.Job `json:"job"` System *types.System `json:"system"` Workspace *types.Workspace `json:"workspace"` diff --git a/pkg/server/commits.go b/pkg/server/commits.go index 080025c36..fb811fe72 100644 --- a/pkg/server/commits.go +++ b/pkg/server/commits.go @@ -178,16 +178,21 @@ func RunBuild(c *gin.Context) { return } + // get the previous build so taht we can send + // on status change notifications + last, _ := store.BuildLast(repo, build.Commit.Branch) + c.JSON(202, build) queue_.Publish(&queue.Work{ - User: user, - Repo: repo, - Build: build, - Keys: repo.Keys, - Netrc: netrc, - Config: raw, - Secret: sec, + User: user, + Repo: repo, + Build: build, + BuildPrev: last, + Keys: repo.Keys, + Netrc: netrc, + Config: raw, + Secret: sec, System: &common.System{ Link: httputil.GetURL(c.Request), Plugins: strings.Split(os.Getenv("PLUGIN_FILTER"), " "), diff --git a/pkg/server/hooks.go b/pkg/server/hooks.go index 16a1b7cd2..81d401977 100644 --- a/pkg/server/hooks.go +++ b/pkg/server/hooks.go @@ -153,14 +153,19 @@ func PostHook(c *gin.Context) { log.Errorf("error setting commit status for %s/%d", repo.FullName, build.Number) } + // get the previous build so taht we can send + // on status change notifications + last, _ := store.BuildLast(repo, build.Commit.Branch) + queue_.Publish(&queue.Work{ - User: user, - Repo: repo, - Build: build, - Keys: repo.Keys, - Netrc: netrc, - Config: raw, - Secret: sec, + User: user, + Repo: repo, + Build: build, + BuildPrev: last, + Keys: repo.Keys, + Netrc: netrc, + Config: raw, + Secret: sec, System: &common.System{ Link: httputil.GetURL(c.Request), Plugins: strings.Split(os.Getenv("PLUGIN_FILTER"), " "),