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

feat(amplify): automatic branch deletion #9663

Merged
merged 2 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/@aws-cdk/aws-amplify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,17 @@ app.addBranch('feature/next', {
});
```

### Automatically creating branches
Use the `autoBranchCreation` prop to automatically create new branches:
### Automatically creating and deleting branches
Use the `autoBranchCreation` and `autoBranchDeletion` props to control creation/deletion
of branches:

```ts
const amplifyApp = new amplify.App(this, 'MyApp', {
repository: 'https://github.com/<user>/<repo>',
oauthToken: cdk.SecretValue.secretsManager('my-github-token'),
autoBranchCreation: {
autoBranchCreation: { // Automatically connect branches that match a pattern set
patterns: ['feature/*', 'test/*']
}
autoBranchDeletion: true, // Automatically disconnect a branch when you delete a branch from your repository
});
```
11 changes: 10 additions & 1 deletion packages/@aws-cdk/aws-amplify/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export interface AppProps {
*/
readonly autoBranchCreation?: AutoBranchCreation;

/**
* Automatically disconnect a branch in the Amplify Console when you delete a
* branch from your Git repository.
*
* @default false
*/
readonly autoBranchDeletion?: boolean;

/**
* The Basic Auth configuration. Use this to set password protection at an
* app level to all your branches.
Expand Down Expand Up @@ -210,11 +218,12 @@ export class App extends Resource implements IApp, iam.IGrantable {
buildSpec: props.autoBranchCreation.buildSpec && props.autoBranchCreation.buildSpec.toBuildSpec(),
enableAutoBranchCreation: true,
enableAutoBuild: props.autoBranchCreation.autoBuild === undefined ? true : props.autoBranchCreation.autoBuild,
environmentVariables: Lazy.anyValue({ produce: () => renderEnvironmentVariables(this.autoBranchEnvironmentVariables )}, { omitEmptyArray: true }), // eslint-disable-line max-len
environmentVariables: Lazy.anyValue({ produce: () => renderEnvironmentVariables(this.autoBranchEnvironmentVariables ) }, { omitEmptyArray: true }), // eslint-disable-line max-len
enablePullRequestPreview: props.autoBranchCreation.pullRequestPreview === undefined ? true : props.autoBranchCreation.pullRequestPreview,
pullRequestEnvironmentName: props.autoBranchCreation.pullRequestEnvironmentName,
stage: props.autoBranchCreation.stage,
},
enableBranchAutoDeletion: props.autoBranchDeletion,
basicAuthConfig: props.basicAuth && props.basicAuth.bind(this, 'AppBasicAuth'),
buildSpec: props.buildSpec && props.buildSpec.toBuildSpec(),
customRules: Lazy.anyValue({ produce: () => this.customRules }, { omitEmptyArray: true }),
Expand Down
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-amplify/test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,3 +371,20 @@ test('with auto branch creation', () => {
},
});
});

test('with auto branch deletion', () => {
// WHEN
new amplify.App(stack, 'App', {
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
owner: 'aws',
repository: 'aws-cdk',
oauthToken: SecretValue.plainText('secret'),
}),
autoBranchDeletion: true,
});

// THEN
expect(stack).toHaveResource('AWS::Amplify::App', {
EnableBranchAutoDeletion: true,
});
});