diff --git a/chalice/cli/__init__.py b/chalice/cli/__init__.py index 90be2bf4d..3cd24017b 100644 --- a/chalice/cli/__init__.py +++ b/chalice/cli/__init__.py @@ -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 " diff --git a/chalice/constants.py b/chalice/constants.py index 6dc2021a2..c617f1407 100644 --- a/chalice/constants.py +++ b/chalice/constants.py @@ -195,6 +195,11 @@ def index(): ], "Resource": "*", "Effect": "Allow" + }, + { + "Action": ["codestar-connections:UseConnection"], + "Resource": "*", + "Effect": "Allow" } ] } diff --git a/chalice/pipeline.py b/chalice/pipeline.py index 8553bcaec..99fe41af9 100644 --- a/chalice/pipeline.py +++ b/chalice/pipeline.py @@ -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()]) @@ -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 @@ -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]