Add support for after_success and after_failure to email notifications

This allows you to restrict email notifications to only be sent after the build changes from success to failure or failure to success.  It errs on the side of sending the notification; if the build is in another state (hung, for instance) or there was no previous build on the branch the email will also be sent.

Since the notify plugin shouldn't really have any responsibility for querying the database to find the previous commit's status, we store it on the commit when we save it.
This commit is contained in:
Michael Nutt
2014-12-30 11:37:57 -05:00
parent 4693b1f526
commit e8b993e7da
6 changed files with 143 additions and 8 deletions

View File

@@ -48,6 +48,84 @@ func TestCommitstore(t *testing.T) {
g.Assert(commit.ID != 0).IsTrue()
})
g.It("Should Get a Commit's prior status", func() {
commit := model.Commit{
RepoID: 1,
Branch: "foo",
Status: "Failure",
Created: 1419892236,
Sha: "85f8c029b902ed9400bc600bac301a0aadb144ac",
}
err := cs.PostCommit(&commit)
g.Assert(err == nil).IsTrue()
g.Assert(commit.ID != 0).IsTrue()
g.Assert(commit.PriorStatus == "").IsTrue()
commit = model.Commit{
RepoID: 1,
Branch: "foo",
Status: "Success",
Created: 1419893583,
Sha: "25f8c029b902ed9400bc600bac301a0aadb144ac",
}
err = cs.PostCommit(&commit)
g.Assert(err == nil).IsTrue()
g.Assert(commit.ID != 0).IsTrue()
g.Assert(commit.PriorStatus == "Failure").IsTrue()
})
g.It("Should not find prior status from commits on other branches", func() {
commit := model.Commit{
RepoID: 1,
Branch: "foo",
Status: "Failure",
Created: 1419892236,
Sha: "85f8c029b902ed9400bc600bac301a0aadb144ac",
}
err := cs.PostCommit(&commit)
g.Assert(err == nil).IsTrue()
g.Assert(commit.ID != 0).IsTrue()
g.Assert(commit.PriorStatus == "").IsTrue()
commit = model.Commit{
RepoID: 1,
Branch: "bar",
Status: "Success",
Created: 1419893583,
Sha: "25f8c029b902ed9400bc600bac301a0aadb144ac",
}
err = cs.PostCommit(&commit)
g.Assert(err == nil).IsTrue()
g.Assert(commit.ID != 0).IsTrue()
g.Assert(commit.PriorStatus == "").IsTrue()
})
g.It("Should not find prior status from commits that didn't succeed or fail", func() {
commit := model.Commit{
RepoID: 1,
Branch: "foo",
Status: "Pending",
Created: 1419892236,
Sha: "85f8c029b902ed9400bc600bac301a0aadb144ac",
}
err := cs.PostCommit(&commit)
g.Assert(err == nil).IsTrue()
g.Assert(commit.ID != 0).IsTrue()
g.Assert(commit.PriorStatus == "").IsTrue()
commit = model.Commit{
RepoID: 1,
Branch: "bar",
Status: "Success",
Created: 1419893583,
Sha: "25f8c029b902ed9400bc600bac301a0aadb144ac",
}
err = cs.PostCommit(&commit)
g.Assert(err == nil).IsTrue()
g.Assert(commit.ID != 0).IsTrue()
g.Assert(commit.PriorStatus == "").IsTrue()
})
g.It("Should Get a Commit by ID", func() {
commit := model.Commit{
RepoID: 1,