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

fix(codepipeline-actions): use token as CodeCommitSourceAction branch #10463

Merged
merged 7 commits into from
Sep 22, 2020

Conversation

alanraison
Copy link
Contributor

@alanraison alanraison commented Sep 21, 2020

When using the EVENTS trigger, an event is created based on the branch name of
the event, however this is not possible if the branch name is an unresolved
value. Therefore generate a unique event name if this is the case.

Fixes #10263


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

When using the EVENTS trigger, an event is created based on the branch name of
the event, however this is not possible if the branch name is an unresolved
value. Therefore generate a unique event name if this is the case.

Fixes aws#10263
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @alanraison ! There's a bug lurking in the current proposal, so we need to address it before merging it in 🙂

Comment on lines 157 to 174
private generateEventId(stage: codepipeline.IStage): string {
let branchIdDisambiguator: string;
let baseId = stage.pipeline.node.uniqueId;
if (this.branch === 'master') {
branchIdDisambiguator = baseId;
} else if (Token.isUnresolved(this.branch)) {
let candidate = baseId;
let counter = 0;
while (this.props.repository.node.tryFindChild(candidate) !== undefined) {
counter += 1;
candidate = `${baseId}-Branch${counter}-`;
}
branchIdDisambiguator = candidate;
} else {
branchIdDisambiguator = `${baseId}-${this.branch}-`;
}
return `${branchIdDisambiguator}EventRule`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a hard time keeping up with this code. For example, branchIdDisambiguator sounds to me like it should be just the branch-changing part of the ID, but somehow it's the entire thing.

What do you think of this instead?

Suggested change
private generateEventId(stage: codepipeline.IStage): string {
let branchIdDisambiguator: string;
let baseId = stage.pipeline.node.uniqueId;
if (this.branch === 'master') {
branchIdDisambiguator = baseId;
} else if (Token.isUnresolved(this.branch)) {
let candidate = baseId;
let counter = 0;
while (this.props.repository.node.tryFindChild(candidate) !== undefined) {
counter += 1;
candidate = `${baseId}-Branch${counter}-`;
}
branchIdDisambiguator = candidate;
} else {
branchIdDisambiguator = `${baseId}-${this.branch}-`;
}
return `${branchIdDisambiguator}EventRule`;
}
private generateEventId(stage: codepipeline.IStage): string {
const baseId = stage.pipeline.node.uniqueId;
if (Token.isUnresolved(this.branch)) {
let candidate = '';
let counter = 0;
do {
candidate = this.eventIdFromPrefix(`${baseId}-${counter}`);
counter += 1;
} while (this.props.repository.node.tryFindChild(candidate) !== undefined);
return candidate;
} else {
const branchIdDisambiguator = this.branch === 'master' ? '' : '-${this.branch}-';
return this.eventIdFromPrefix(`${baseId}${branchIdDisambiguator}`);
}
}
private eventIdFromPrefix(eventIdPrefix: string) {
return `${eventIdPrefix}EventRule`;
}

(Notice the different loop; the current one actually checks the wrong ID, without the EvenRule suffix!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, thanks for spotting that! I think that your naming scheme with the counter needs a slight tweak though, so I will just update my branch with that.

Copy link
Contributor

@gotodeploy gotodeploy Oct 2, 2020

Choose a reason for hiding this comment

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

@skinny85 This might have a bug:

# Use buckticks instead
'-${this.branch}-' => `-${this.branch}-`

P.S. I opened #10665

Cleaning up the tests

Co-authored-by: Adam Ruka <adamruka85@gmail.com>
@mergify mergify bot dismissed skinny85’s stale review September 21, 2020 21:59

Pull request has been modified.

skinny85
skinny85 previously approved these changes Sep 22, 2020
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix @alanraison !

@mergify mergify bot dismissed skinny85’s stale review September 22, 2020 18:37

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Sep 22, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: a678aa1
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Sep 22, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 94bbabf into aws:master Sep 22, 2020
@alanraison alanraison deleted the bugfix/10263 branch September 24, 2020 17:58
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.

[codepipeline-actions] Can't use a token for branchName in CodeCommitAction
4 participants