-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(codebuild): add ability to customize build status reporting for third-party Git sources #19408
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
Conversation
There was a problem hiding this 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 @Lilja, but I don't love the current modeling of these capabilities.
Here are the docs of these properties:
/**
* Specifies the context of the build status CodeBuild sends to the source provider. The usage of this parameter depends on the source provider.
*
* - **Bitbucket** - This parameter is used for the `name` parameter in the Bitbucket commit status. For more information, see [build](https://docs.aws.amazon.com/https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/commit/%7Bnode%7D/statuses/build) in the Bitbucket API documentation.
* - **GitHub/GitHub Enterprise Server** - This parameter is used for the `context` parameter in the GitHub commit status. For more information, see [Create a commit status](https://docs.aws.amazon.com/https://developer.github.com/v3/repos/statuses/#create-a-commit-status) in the GitHub developer guide.
*
* @link http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-buildstatusconfig.html#cfn-codebuild-project-buildstatusconfig-context
*/
readonly context?: string;
/**
* Specifies the target url of the build status CodeBuild sends to the source provider. The usage of this parameter depends on the source provider.
*
* - **Bitbucket** - This parameter is used for the `url` parameter in the Bitbucket commit status. For more information, see [build](https://docs.aws.amazon.com/https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Bworkspace%7D/%7Brepo_slug%7D/commit/%7Bnode%7D/statuses/build) in the Bitbucket API documentation.
* - **GitHub/GitHub Enterprise Server** - This parameter is used for the `target_url` parameter in the GitHub commit status. For more information, see [Create a commit status](https://docs.aws.amazon.com/https://developer.github.com/v3/repos/statuses/#create-a-commit-status) in the GitHub developer guide.
*
* @link http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-buildstatusconfig.html#cfn-codebuild-project-buildstatusconfig-targeturl
*/
readonly targetUrl?: string;
So, what should happen is:
- The properties used for creating the
BitBucketSource
,BitBucketSourceProps
, should get a new, optional property calledname
, of typestring
. - The properties for creating the
GitHubSource
andGitHubEnterpriseSource
will need to get a new, optional property, calledcontext
, of typestring
. (You might have to introduce a common superinterface to share betweenGitHubEnterpriseSourceProps
andGitHubSourceProps
. ThirdPartyGitSourceProps
should get a new, optional property, calledtargetUrl
, of typestring
.- You fill the
buildStatusConfig
property of theSourceProperty
interface that's returned from thebind()
method of all of theseSource
s (through thesourceProperty
property of theSourceConfig
returned frombind()
).
Let me know if this makes sense!
Thanks,
Adam
Maybe Feel free to propose better names, of course 🙂. |
Hey @skinny85. Thanks for the feedback. I've tried to adress it in my latest commit.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're getting there, thanks for all of your work on this @Lilja!
I hope my review answers all of your questions, if something is still unclear, let me know!
/** | ||
* This parameter is used for the `url`/`target_url` parameter in the Bitbucket/GitHub commit status. | ||
* BitBucket: `url` | ||
* Github: `target_url` | ||
* | ||
* @default ??????????? | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs are misaligned here:
/** | |
* This parameter is used for the `url`/`target_url` parameter in the Bitbucket/GitHub commit status. | |
* BitBucket: `url` | |
* Github: `target_url` | |
* | |
* @default ??????????? | |
*/ | |
/** | |
* This parameter is used for the `url`/`target_url` parameter in the Bitbucket/GitHub commit status. | |
* BitBucket: `url` | |
* Github: `target_url` | |
* | |
* @default ??????????? | |
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to talk about what exact property this fills for each type. It should be obvious from the name.
Let's change the docs to say something like "The URL that the build will report back to the source provider. Can use built-in CodeBuild variables, like $AWS_REGION
". Something like that.
Let's also add an @example
, and make @default
say something like "- link to the AWS Console for CodeBuild to a particular build execution".
/** | ||
* wip | ||
*/ | ||
export interface GithubContextProps extends ThirdPartyGitSourceProps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name isn't the best long-term I'm fairly sure. Let's change it to CommonGitHubSourceProps
.
Also, let's not make it export
ed (let's keep it module-private).
/** | ||
* wip | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once you make this interface not export
ed anymore, you'll be able to remove these JSDocs.
const buildStatusConfig = { | ||
targetUrl: this.buildStatusUrl | ||
} | ||
if (typeof superConfig["buildStatusContext"] !== "undefined") { | ||
// Github/GitHubEnterprise | ||
buildStatusConfig["context"] = superConfig["buildStatusContext"] | ||
} else if (typeof superConfig["buildStatusName"] !== "undefined") { | ||
// BitBucket | ||
buildStatusConfig["context"] = superConfig["buildStatusName"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we need to handle buildStatusConfig
separately in the two subclasses anyway, let's just remove all of this code.
|
||
return { | ||
sourceProperty: { | ||
...superConfig.sourceProperty, | ||
reportBuildStatus: this.reportBuildStatus, | ||
buildStatusConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this too (will be handled by the subclasses).
/** | ||
* This parameter is used for the `context` parameter in the GitHub commit status. | ||
* | ||
* @example 'My build #$CODEBUILD_BUILD_NUMBER' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use double quotes for the example, renders better in other languages.
buildStatusConfig: { | ||
context: this.buildStatusContext, | ||
targetUrl: this.buildStatusUrl, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we need to introduce a new, module-private superclass here, CommonGitHubSource
, that deals with the buildStatusConfig
property, so that this code is not duplicated between GitHubEnterpriseSource
and GitHubSource
.
/** | ||
* This parameter is used for the `name` parameter in the Bitbucket commit status. | ||
* | ||
* @example 'My build #$CODEBUILD_BUILD_NUMBER' | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, let's brush up on the docs here: "The name that the build will report back to the BitBucket source provider. Can use built-in CodeBuild variables, like $AWS_REGION". Something like that.
Also, double quotes for @example
.
And @default "AWS CodeBuild $AWS_REGION ($PROJECT_NAME)"
.
@@ -776,6 +824,7 @@ export interface BitBucketSourceProps extends ThirdPartyGitSourceProps { | |||
class BitBucketSource extends ThirdPartyGitSource { | |||
public readonly type = BITBUCKET_SOURCE_TYPE; | |||
private readonly httpsCloneUrl: any; | |||
private readonly buildStatusName: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to assign this field in the constructor.
Then, in bind()
, do:
return {
sourceProperty: {
...superConfig.sourceProperty,
location: this.httpsCloneUrl,
buildStatusConfig: {
context: this.buildStatusName,
targetUrl: this.buildStatusUrl,
},
},
sourceVersion: superConfig.sourceVersion,
buildTriggers: superConfig.buildTriggers,
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @Lilja, but you need to fix the formatting to get the PR build to succeed, so we can merge this in!
@@ -499,6 +499,14 @@ interface ThirdPartyGitSourceProps extends GitSourceProps { | |||
* @default every push and every Pull Request (create or update) triggers a build | |||
*/ | |||
readonly webhookFilters?: FilterGroup[]; | |||
|
|||
/** | |||
* This parameter is used for the `url`/`target_url` parameter in the Bitbucket/GitHub commit status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again - I don't think we need to specify exactly which parameter this fills. I think it's obvious from the name.
* This parameter is used for the `url`/`target_url` parameter in the Bitbucket/GitHub commit status. | |
* The URL that the build will report back to the source provider. | |
* Can use built-in CodeBuild variables, like $AWS_REGION. |
/** | ||
* This parameter is used for the `url`/`target_url` parameter in the Bitbucket/GitHub commit status. | ||
* | ||
* @example "The URL that the build will report back to the source provider. Can use built-in CodeBuild variables, like $AWS_REGION" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very weird example 😃.
* @example "The URL that the build will report back to the source provider. Can use built-in CodeBuild variables, like $AWS_REGION" | |
* @example "$CODEBUILD_PUBLIC_BUILD_URL" |
* This parameter is used for the `url`/`target_url` parameter in the Bitbucket/GitHub commit status. | ||
* | ||
* @example "The URL that the build will report back to the source provider. Can use built-in CodeBuild variables, like $AWS_REGION" | ||
* @default "link to the AWS Console for CodeBuild to a particular build execution" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the quotes here:
* @default "link to the AWS Console for CodeBuild to a particular build execution" | |
* @default - link to the AWS Console for CodeBuild to a particular build execution |
new codebuild.Project(stack, 'MyProject', { | ||
source, | ||
}) | ||
Template.fromStack(stack).hasResourceProperties( | ||
'AWS::CodeBuild::Project', { | ||
'Source': { | ||
'buildStatusConfig': { | ||
'context': context, | ||
} | ||
} | ||
} | ||
) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments here (inline source
, wrong formatting).
new codebuild.Project(stack, 'MyProject', { | ||
source, | ||
}) | ||
Template.fromStack(stack).hasResourceProperties( | ||
'AWS::CodeBuild::Project', { | ||
'Source': { | ||
'buildStatusConfig': { | ||
'context': context, | ||
'targetUrl': targetUrl, | ||
} | ||
} | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments here (inline source
, wrong formatting).
}) | ||
|
||
describe('sources with customised build status configuration', () => { | ||
test('github with targetUrl', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('github with targetUrl', () => { | |
test('GitHub with targetUrl', () => { |
'AWS::CodeBuild::Project', { | ||
'Source': { | ||
'buildStatusConfig': { | ||
'context': context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this test checks context
too, can you actually remove the first test, and just leave this one? The first test is redundant currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, my thought was to have a unit test only having either one of those parameters. The tests above only uses context and name, so my thought was to create a unit test with only targetUrl.
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semiicolons:
}) | |
}) | |
}); | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're almost there!
@@ -499,6 +499,17 @@ interface ThirdPartyGitSourceProps extends GitSourceProps { | |||
* @default every push and every Pull Request (create or update) triggers a build | |||
*/ | |||
readonly webhookFilters?: FilterGroup[]; | |||
|
|||
/** | |||
* The URL that the build will report back to the source provider. Can use built-in CodeBuild variables, like $AWS_REGION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multi-line, and full sentences, please:
* The URL that the build will report back to the source provider. Can use built-in CodeBuild variables, like $AWS_REGION | |
* The URL that the build will report back to the source provider. | |
* Can use built-in CodeBuild variables, like $AWS_REGION. |
buildStatusConfig: { | ||
context: this.buildStatusContext, | ||
targetUrl: this.buildStatusUrl, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to render this property only if at least one of this.buildStatusContext
or this.buildStatusUrl
is defined:
buildStatusConfig: { | |
context: this.buildStatusContext, | |
targetUrl: this.buildStatusUrl, | |
}, | |
buildStatusConfig: this.buildStatusContext !== undefined || this.buildStatusUrl !== undefined | |
? { | |
context: this.buildStatusContext, | |
targetUrl: this.buildStatusUrl, | |
} | |
: undefined, |
This is why the integration test is failing in the build right now:
@aws-cdk/aws-codebuild: Verifying integ.github-webhook-batch.js against integ.github-webhook-batch.expected.json ... CHANGED.
@aws-cdk/aws-codebuild: Resources
@aws-cdk/aws-codebuild: [~] AWS::CodeBuild::Project MyProject39F7B0AE
@aws-cdk/aws-codebuild: └─ [~] Source
@aws-cdk/aws-codebuild: └─ [+] Added: .BuildStatusConfig
@aws-cdk/aws-codebuild: Verifying integ.github.js against integ.github.expected.json ... CHANGED.
@aws-cdk/aws-codebuild: Resources
@aws-cdk/aws-codebuild: [~] AWS::CodeBuild::Project MyProject39F7B0AE
@aws-cdk/aws-codebuild: └─ [~] Source
@aws-cdk/aws-codebuild: └─ [+] Added: .BuildStatusConfig
buildStatusConfig: { | ||
context: this.buildStatusName, | ||
targetUrl: this.buildStatusUrl, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here - we need to render this property only if at least one of this.buildStatusName
or this.buildStatusUrl
is defined:
buildStatusConfig: { | |
context: this.buildStatusName, | |
targetUrl: this.buildStatusUrl, | |
}, | |
buildStatusConfig: this.buildStatusName !== undefined || this.buildStatusUrl !== undefined | |
? { | |
context: this.buildStatusName, | |
targetUrl: this.buildStatusUrl, | |
} | |
: undefined, |
Thanks for being so patient with me @skinny85! Fixed compliance with earlier test cases and rebased the branch. Now, there's only the remaining test case of testing the target_url. Is it interesting or should we remove it completely? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last 3 cosmetic changes, and this will be merged in!
Fixed compliance with earlier test cases and rebased the branch. Now, there's only the remaining test case of testing the target_url. Is it interesting or should we remove it completely?
Nah, we're good. Leave it as-is.
Thanks for being so patient with me @skinny85!
My pleasure, thanks for all of your hard work in contributing this feature!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great @Lilja!
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
…third-party Git sources (aws#19408) [Documentation](https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-cli.html#cli.source.buildstatusconfig.context) The idea is to be able to customise the Github "check" through the context parameter I linked in the AWS doc. aws#19403
Documentation
The idea is to be able to customise the Github "check" through the context parameter I linked in the AWS doc.
#19403