Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve git revision from CodePipeline #109

Merged
merged 2 commits into from
Mar 20, 2017

Conversation

jesseadams
Copy link

@jesseadams jesseadams commented Mar 16, 2017

Fixes #80

@jesseadams jesseadams changed the title WIP Retrieve git revision from CodePipeline Mar 17, 2017
@jesseadams jesseadams force-pushed the git-revision-from-codepipeline branch 2 times, most recently from a5f5033 to b8b3314 Compare March 17, 2017 21:05
@jesseadams jesseadams force-pushed the git-revision-from-codepipeline branch from b8b3314 to e0f8293 Compare March 17, 2017 21:07
@jesseadams
Copy link
Author

@cplee - Should be ready for review. I don't have a test (yet). I am not sure if you would rather wait on one before merge or not.

@@ -47,3 +48,26 @@ func (cplMgr *codePipelineManager) ListState(pipelineName string) ([]*codepipeli

return output.StageStates, nil
}

func getRevisionFromCodePipeline(pipelineName string) (string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create the function on the codePipelineManager (see: ListState). Function will need to be uppercase to make it public and then would suggest a name like GetCurrentRevision. Then also create an interface named PipelineRevisionGetter with the single method. Include the interface in the PipelineManager interface.

Why?

  • You have access to the connection to the codepipeline service that has already been established (see ListState)
  • Consistency with other functions


func getRevisionFromCodePipeline(pipelineName string) (string, error) {
sess := session.Must(session.NewSession())
service := codepipeline.New(sess)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't start a new session...reuse connection in codepipelineiface.CodePipelineAPI. This one is already honoring the region and profile that the user requested.

Also, this will improve your ability to unit test. Check out the unit test for ListState and notice how you are able to mock the AWS SDK to avoid having to actually talk to the CodePipeline service.

}
for _, stageState := range response.StageStates {
for _, actionState := range stageState.ActionStates {
if *actionState.ActionName == "Source" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use aws.StringValue(actionState.ActionName)

}
}

return "", errors.New("Can not locate revision from CodePipeline: " + pipelineName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider fmt.Errorf("Can not locate revision from CodePipeline: %s",pipelineName)

@cplee cplee changed the base branch from develop to issue-80 March 20, 2017 18:54
@cplee cplee changed the base branch from issue-80 to develop March 20, 2017 18:54
@cplee cplee merged commit 3545cd1 into stelligent:develop Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants