Skip to content

Commit

Permalink
feat: allow automerge workflow on managed repositories (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiehan authored Dec 7, 2023
1 parent 44ada2f commit 3dfdcaf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/lib/collect-changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ module.exports = async ({ core, exec }) => {
}

if (commitMessageParts.length === 0) {
const repo = 'cdktf/cdktf-repository-manager'; // we could make this dynamic
const repo = "cdktf/cdktf-repository-manager"; // we could make this dynamic
let commitHash;
try {
commitHash = (
Expand Down
2 changes: 1 addition & 1 deletion .github/lib/create-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = async ({
owner,
repo,
issue_number: data.number,
labels: ["automerge"],
labels: ["automerge", "auto-approve"],
});

if (mergePullRequest) {
Expand Down
32 changes: 30 additions & 2 deletions lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class RepositorySetup extends Construct {

const {
protectMain = false,
protectMainChecks = ["build"],
protectMainChecks = ["build", "license/cla"],
provider,
repository,
team,
Expand All @@ -59,6 +59,22 @@ export class RepositorySetup extends Construct {
})
);

setOldId(
new IssueLabel(this, `no-auto-close-label`, {
color: "EE2222",
name: "no-auto-close",
repository: repository.name,
provider,
})
);

new IssueLabel(this, `auto-approve-label`, {
color: "8BF8BD",
name: "auto-approve",
repository: repository.name,
provider,
});

if (protectMain) {
setOldId(
new BranchProtection(this, "main-protection", {
Expand All @@ -67,6 +83,14 @@ export class RepositorySetup extends Construct {
enforceAdmins: true,
allowsDeletions: false,
allowsForcePushes: false,
requiredPullRequestReviews: [
{
requiredApprovingReviewCount: 1,
requireCodeOwnerReviews: false, // NOTE: In the future, Security wants to enforce this, so be warned...
dismissStaleReviews: false,
},
],
requireConversationResolution: true,
requiredStatusChecks: [
{
strict: true,
Expand Down Expand Up @@ -137,6 +161,10 @@ export class GithubRepository extends Construct {
autoInit: true,
hasProjects: false,
deleteBranchOnMerge: true,
allowAutoMerge: true,
allowUpdateBranch: true,
squashMergeCommitMessage: "PR_BODY",
squashMergeCommitTitle: "PR_TITLE",
topics,
provider,
});
Expand All @@ -160,7 +188,7 @@ export class GithubRepositoryFromExistingRepository extends Construct {
constructor(
scope: Construct,
name: string,
config: Pick<RepositoryConfig, "team" | "webhookUrl" | "provider"> & {
config: RepositoryConfig & {
repositoryName: string;
}
) {
Expand Down
14 changes: 14 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ class CustomConstructsStack extends TerraformStack {
const secrets = new PublishingSecretSet(this, "secret-set");

constructRepos.forEach(({ name: repoName, languages, topics }) => {
const protectMainChecks = ["build", "license/cla"].concat(
languages.map((language) => {
return `package-${
language === "typescript"
? "js"
: language === "csharp"
? "dotnet"
: language
}`;
})
);

const repo = new GithubRepositoryFromExistingRepository(
this,
`cdktf-construct-${repoName}`,
Expand All @@ -277,6 +289,8 @@ class CustomConstructsStack extends TerraformStack {
team: githubTeam,
webhookUrl: slackWebhook.stringValue,
provider: githubProvider,
protectMain: true,
protectMainChecks,
}
);

Expand Down

0 comments on commit 3dfdcaf

Please sign in to comment.