Skip to content

Commit

Permalink
Merge pull request #93 from gardleopard/travis_handle_created_state
Browse files Browse the repository at this point in the history
Travis - consider 'created' as a running state
  • Loading branch information
ajordens committed May 13, 2016
2 parents b713253 + e0a5109 commit cbd8566
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ class TravisBuildMonitor implements PollingMonitor{

static final int NEW_BUILD_EVENT_THRESHOLD = 1

static final String BUILD_IN_PROGRESS = 'started'

@SuppressWarnings('GStringExpressionWithinString')
@Value('${spinnaker.build.pollInterval:60}')
int pollInterval
Expand Down Expand Up @@ -152,7 +150,7 @@ class TravisBuildMonitor implements PollingMonitor{

if (cachedRepoSlugs.contains(repo.slug)) {
cachedBuild = buildCache.getLastBuild(master, repo.slug)
if (((repo.lastBuildState == BUILD_IN_PROGRESS) != cachedBuild.lastBuildBuilding) ||
if ((TravisResultConverter.running(repo.lastBuildState) != cachedBuild.lastBuildBuilding) ||
(repo.lastBuildNumber != Integer.valueOf(cachedBuild.lastBuildLabel))) {
addToCache = true
log.info "Build changed: ${master}: ${repo.slug} : ${repo.lastBuildNumber} : ${repo.lastBuildState}"
Expand All @@ -164,8 +162,8 @@ class TravisBuildMonitor implements PollingMonitor{
addToCache = true
}
if (addToCache) {
log.info("Build update [${repo.slug}:${repo.lastBuildNumber}] [status:${repo.lastBuildState}] [running:${repo.lastBuildState == BUILD_IN_PROGRESS}]")
buildCache.setLastBuild(master, repo.slug, repo.lastBuildNumber, repo.lastBuildState == BUILD_IN_PROGRESS, buildCacheJobTTLSeconds())
log.info("Build update [${repo.slug}:${repo.lastBuildNumber}] [status:${repo.lastBuildState}] [running:${TravisResultConverter.running(repo.lastBuildState)}]")
buildCache.setLastBuild(master, repo.slug, repo.lastBuildNumber, TravisResultConverter.running(repo.lastBuildState), buildCacheJobTTLSeconds())
sendEventForBuild(repo, master, travisService)


Expand Down Expand Up @@ -201,7 +199,7 @@ class TravisBuildMonitor implements PollingMonitor{
String branchedSlug = travisService.branchedRepoSlug(repo.slug, repo.lastBuildNumber, commit)

if (branchedSlug != repo.slug) {
buildCache.setLastBuild(master, branchedSlug, repo.lastBuildNumber, repo.lastBuildState == BUILD_IN_PROGRESS, buildCacheJobTTLSeconds())
buildCache.setLastBuild(master, branchedSlug, repo.lastBuildNumber, TravisResultConverter.running(repo.lastBuildState), buildCacheJobTTLSeconds())
if (echoService) {
log.info "pushing event for ${master}:${branchedSlug}:${repo.lastBuildNumber}"

Expand All @@ -228,7 +226,7 @@ class TravisBuildMonitor implements PollingMonitor{
if (build?.state) {
log.info "pushing event for ${master}:${repo.slug}:${build.number}"
String url = "${travisService.baseUrl}/${repo.slug}/builds/${build.id}"
GenericProject project = new GenericProject(repo.slug, new GenericBuild((build.state == BUILD_IN_PROGRESS), build.number, build.duration, TravisResultConverter.getResultFromTravisState(build.state), repo.slug, url))
GenericProject project = new GenericProject(repo.slug, new GenericBuild((TravisResultConverter.running(build.state)), build.number, build.duration, TravisResultConverter.getResultFromTravisState(build.state), repo.slug, url))
echoService.postEvent(
new GenericBuildEvent(content: new GenericBuildContent(project: project, master: master, type: 'travis')))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ class TravisResultConverter {
throw new IllegalArgumentException("state: ${state} is not known to TravisResultConverter.")
break
}
}

static Boolean running(String state) {
switch (state) {
case "created":
return true
break
case "started":
return true
break
default:
return false
break
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,32 @@ package com.netflix.spinnaker.igor.travis.service

import com.netflix.spinnaker.igor.build.model.Result
import spock.lang.Specification
import spock.lang.Unroll

class TravisResultConverterTest extends Specification {
def "convert travis build states to Result object"() {
setup:
def state = travisBuildState

when:
Result result = TravisResultConverter.getResultFromTravisState(state)
@Unroll
def "convert travis build states to Result object state='#travisBuildState' should give Result=#expectedResult"() {
expect:
TravisResultConverter.getResultFromTravisState(travisBuildState) == expectedResult

then:
result == expectedResult
where:
travisBuildState || expectedResult
"started" || Result.BUILDING
"passed" || Result.SUCCESS
"errored" || Result.FAILURE
}

@Unroll
def "check if build is running state='#travisBuildState' should give running=#expectedResult"() {
expect:
TravisResultConverter.running(travisBuildState) == expectedResult

where:
travisBuildState | expectedResult
"started" | Result.BUILDING
"passed" | Result.SUCCESS
"errored" | Result.FAILURE
travisBuildState || expectedResult
"started" || true
"created" || true
"passed" || false
"errored" || false
}
}

0 comments on commit cbd8566

Please sign in to comment.