"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const codepipeline = require("@aws-cdk/aws-codepipeline-api");
const cdk = require("@aws-cdk/cdk");
/**
 * CodePipeline Source that is provided by an AWS CodeCommit repository.
 */
class PipelineSource extends codepipeline.SourceAction {
    constructor(parent, name, props) {
        super(parent, name, {
            stage: props.stage,
            provider: 'CodeCommit',
            configuration: {
                RepositoryName: props.repository.repositoryName,
                BranchName: props.branch || 'master',
                PollForSourceChanges: props.pollForSourceChanges !== undefined ? props.pollForSourceChanges : true
            },
            artifactName: props.artifactName
        });
        // https://docs.aws.amazon.com/codecommit/latest/userguide/auth-and-access-control-permissions-reference.html#aa-acp
        const actions = [
            'codecommit:GetBranch',
            'codecommit:GetCommit',
            'codecommit:UploadArchive',
            'codecommit:GetUploadArchiveStatus',
            'codecommit:CancelUploadArchive',
        ];
        props.stage.pipelineRole.addToPolicy(new cdk.PolicyStatement()
            .addResource(props.repository.repositoryArn)
            .addActions(...actions));
    }
}
exports.PipelineSource = PipelineSource;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGlwZWxpbmUtYWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsicGlwZWxpbmUtYWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsOERBQStEO0FBQy9ELG9DQUFxQztBQWdDckM7O0dBRUc7QUFDSCxNQUFhLGNBQWUsU0FBUSxZQUFZLENBQUMsWUFBWTtJQUN6RCxZQUFZLE1BQXFCLEVBQUUsSUFBWSxFQUFFLEtBQTBCO1FBQ3ZFLEtBQUssQ0FBQyxNQUFNLEVBQUUsSUFBSSxFQUFFO1lBQ2hCLEtBQUssRUFBRSxLQUFLLENBQUMsS0FBSztZQUNsQixRQUFRLEVBQUUsWUFBWTtZQUN0QixhQUFhLEVBQUU7Z0JBQ1gsY0FBYyxFQUFFLEtBQUssQ0FBQyxVQUFVLENBQUMsY0FBYztn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