Skip to content

Commit

Permalink
Push code up out of 'else' clause for simplicity
Browse files Browse the repository at this point in the history
[#4]

Signed-off-by: Jacques Chester <jchester@pivotal.io>
  • Loading branch information
jchester authored and jchesterpivotal committed Aug 19, 2018
1 parent bbc3538 commit 0043ef0
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions pkg/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,38 @@ func (c checker) Check() (*config.CheckResponse, error) {
return &config.CheckResponse{
config.Version{BuildId: buildId},
}, nil
} else {
buildId, err := strconv.Atoi(version.BuildId)
if err != nil {
return nil, fmt.Errorf("could not convert build id '%s' to an int: '%s", version.BuildId, err.Error())
}
}

builds, _, found, err := c.concourseTeam.JobBuilds(pipeline, job, gc.Page{})
if err != nil {
return nil, fmt.Errorf("could not retrieve builds for '%s/%s': %s", pipeline, job, err.Error())
}
if !found {
return nil, fmt.Errorf("server could not find '%s/%s'", pipeline, job)
}
buildId, err := strconv.Atoi(version.BuildId)
if err != nil {
return nil, fmt.Errorf("could not convert build id '%s' to an int: '%s", version.BuildId, err.Error())
}

if len(builds) == 0 { // there are no builds at all
return &config.CheckResponse{}, nil
}
builds, _, found, err := c.concourseTeam.JobBuilds(pipeline, job, gc.Page{})
if err != nil {
return nil, fmt.Errorf("could not retrieve builds for '%s/%s': %s", pipeline, job, err.Error())
}
if !found {
return nil, fmt.Errorf("server could not find '%s/%s'", pipeline, job)
}

newBuilds := make(config.CheckResponse, 0)
for _, b := range builds {
if b.ID > buildId && b.Status != string(atc.StatusStarted) && b.Status != string(atc.StatusPending) {
newBuildId := strconv.Itoa(b.ID)
newBuilds = append(newBuilds, config.Version{BuildId: newBuildId})
}
}
if len(builds) == 0 { // there are no builds at all
return &config.CheckResponse{}, nil
}

if len(newBuilds) == 0 { // there were no new builds
return &config.CheckResponse{version}, nil
newBuilds := make(config.CheckResponse, 0)
for _, b := range builds {
if b.ID > buildId && b.Status != string(atc.StatusStarted) && b.Status != string(atc.StatusPending) {
newBuildId := strconv.Itoa(b.ID)
newBuilds = append(newBuilds, config.Version{BuildId: newBuildId})
}
}

return &newBuilds, nil
if len(newBuilds) == 0 { // there were no new builds
return &config.CheckResponse{version}, nil
}

return &config.CheckResponse{}, nil
return &newBuilds, nil
}

func NewChecker(input *config.CheckRequest) Checker {
Expand Down

0 comments on commit 0043ef0

Please sign in to comment.