Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions chalice/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,13 @@ def package(ctx, single_file, stage, merge_template,
"This option must be provided when using a python "
"version besides 2.7."))
@click.option('-s', '--source', default='codecommit',
type=click.Choice(['codecommit', 'github']),
type=click.Choice(['codecommit', 'github', 'codestar']),
help=("Specify the input source. The default value of "
"'codecommit' will create a CodeCommit repository "
"for you. The 'github' value allows you to "
"reference an existing GitHub repository."))
"reference an existing GitHub repository."
"The 'codestar' value allows you to reference "
"bitbucket or any codestar connection."))
@click.option('-b', '--buildspec-file',
help=("Specify path for buildspec.yml file. "
"By default, the build steps are included in the "
Expand Down
5 changes: 5 additions & 0 deletions chalice/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def index():
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": ["codestar-connections:UseConnection"],
"Resource": "*",
"Effect": "Allow"
}
]
}
Expand Down
46 changes: 46 additions & 0 deletions chalice/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def create_template(self, pipeline_params):
resources = [] # type: List[BaseResource]
if pipeline_params.code_source == 'github':
resources.append(GithubSource())
elif pipeline_params.code_source == 'codestar':
resources.append(CodeStarSource())
else:
resources.append(CodeCommitSourceRepository())
resources.extend([CodeBuild(create_buildspec_v2), CodePipeline()])
Expand Down Expand Up @@ -254,6 +256,23 @@ def add_to_template(self, template, pipeline_params):
}


class CodeStarSource(BaseResource):
def add_to_template(self, template, pipeline_params):
# type: (Dict[str, Any], PipelineParameters) -> None
p = template.setdefault('Parameters', {})
p['CodeStarConnectionArn'] = {
'Type': 'String',
'Description': 'The codestar connection arn.',
}
p['CodeStarFullRepositoryId'] = {
'Type': 'String',
'Description': (
'The repository id. '
'Example, bitbucketusername/repo'
)
}


class GithubSource(BaseResource):
def add_to_template(self, template, pipeline_params):
# type: (Dict[str, Any], PipelineParameters) -> None
Expand Down Expand Up @@ -520,8 +539,35 @@ def _create_source_stage(self, pipeline_params):
# type: (PipelineParameters) -> Dict[str, Any]
if pipeline_params.code_source == 'codecommit':
return self._code_commit_source()
if pipeline_params.code_source == 'codestar':
return self._code_star_source()
return self._github_source(pipeline_params.pipeline_version)

def _code_star_source(self):
# type: (str) -> Dict[str, Any]
return {
'Name': 'Source',
'Actions': [{
"Name": "Source",
"ActionTypeId": {
"Category": "Source",
"Owner": "AWS",
"Version": "1",
"Provider": "CodeStarSourceConnection"
},
'RunOrder': 1,
'OutputArtifacts': [{
'Name': 'SourceRepo',
}],
'Configuration': {
'ConnectionArn': {'Ref': 'CodeStarConnectionArn'},
'FullRepositoryId': {'Ref': 'CodeStarFullRepositoryId'},
'BranchName': 'master',
'DetectChanges': True,
}
}],
}

def _github_source(self, pipeline_version):
# type: (str) -> Dict[str, Any]
oauth_token = {'Ref': 'GithubPersonalToken'} # type: Dict[str, Any]
Expand Down