Skip to content

Commit

Permalink
chore: migrate from old addresses to new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Nov 1, 2023
1 parent d7c4825 commit fab345b
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 42 deletions.
133 changes: 97 additions & 36 deletions lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class RepositorySetup extends Construct {
}
) {
super(scope, name);
const moveLabel = (label: string) => `${this.node.path}-${label}`;

const {
protectMain = false,
Expand All @@ -50,46 +51,75 @@ export class RepositorySetup extends Construct {
webhookUrl,
} = config;

setOldId(
new IssueLabel(this, `automerge-label`, {
color: "5DC8DB",
name: "automerge",
repository: repository.name,
provider,
})
);
const oldIssueLabel = new IssueLabel(this, `automerge-label-old`, {
color: "5DC8DB",
name: "automerge",
repository: repository.name,
provider,
});
setOldId(oldIssueLabel);
oldIssueLabel.moveTo(moveLabel("automerge-label"));
new IssueLabel(this, `automerge-label`, {
color: "5DC8DB",
name: "automerge",
repository: repository.name,
provider,
}).addMoveTarget(moveLabel("automerge-label"));

if (protectMain) {
setOldId(
new BranchProtection(this, "main-protection", {
pattern: "main",
repositoryId: repository.name,
enforceAdmins: true,
allowsDeletions: false,
allowsForcePushes: false,
requiredStatusChecks: [
{
strict: true,
contexts: protectMainChecks,
},
],
provider,
})
);
const oldProtectMain = new BranchProtection(this, "main-protection-old", {
pattern: "main",
repositoryId: repository.name,
enforceAdmins: true,
allowsDeletions: false,
allowsForcePushes: false,
requiredStatusChecks: [
{
strict: true,
contexts: protectMainChecks,
},
],
provider,
});
setOldId(oldProtectMain);
oldProtectMain.moveTo(moveLabel("main-protection"));

new BranchProtection(this, "main-protection", {
pattern: "main",
repositoryId: repository.name,
enforceAdmins: true,
allowsDeletions: false,
allowsForcePushes: false,
requiredStatusChecks: [
{
strict: true,
contexts: protectMainChecks,
},
],
provider,
}).addMoveTarget(moveLabel("main-protection"));
}

setOldId(
new TeamRepository(this, "managing-team", {
repository: repository.name,
teamId: team.id,
permission: "admin",
provider,
})
);
const oldManagingTeam = new TeamRepository(this, "managing-team-old", {
repository: repository.name,
teamId: team.id,
permission: "admin",
provider,
});
setOldId(oldManagingTeam);
oldManagingTeam.moveTo(moveLabel("managing-team"));
new TeamRepository(this, "managing-team", {
repository: repository.name,
teamId: team.id,
permission: "admin",
provider,
}).addMoveTarget(moveLabel("managing-team"));

// Slack integration so we can be notified about new PRs and Issues
setOldId(
new RepositoryWebhook(this, "slack-webhook", {
const oldSlackIntegration = new RepositoryWebhook(
this,
"slack-webhook-old",
{
repository: repository.name,

configuration: {
Expand All @@ -100,8 +130,22 @@ export class RepositorySetup extends Construct {
// We don't need to notify about PRs since they are auto-created
events: ["issues"],
provider,
})
}
);
setOldId(oldSlackIntegration);
oldSlackIntegration.moveTo(moveLabel("slack-webhook"));
new RepositoryWebhook(this, "slack-webhook", {
repository: repository.name,

configuration: {
url: webhookUrl,
contentType: "json",
},

// We don't need to notify about PRs since they are auto-created
events: ["issues"],
provider,
}).addMoveTarget(moveLabel("slack-webhook"));
}
}

Expand All @@ -126,6 +170,23 @@ export class GithubRepository extends Construct {
provider,
} = config;
this.provider = provider;
const moveLabel = (label: string) => `${this.node.path}-${label}`;

const oldRepo = new Repository(this, "repo-old", {
name,
description,
visibility: "public",
homepageUrl: "https://cdk.tf",
hasIssues: !name.endsWith("-go"),
hasWiki: false,
autoInit: true,
hasProjects: false,
deleteBranchOnMerge: true,
topics,
provider,
});
setOldId(oldRepo);
oldRepo.moveTo(moveLabel("repo"));

this.resource = new Repository(this, "repo", {
name,
Expand All @@ -140,7 +201,7 @@ export class GithubRepository extends Construct {
topics,
provider,
});
setOldId(this.resource);
this.resource.addMoveTarget(moveLabel("repo"));

new RepositorySetup(this, "repository-setup", {
...config,
Expand Down
37 changes: 31 additions & 6 deletions lib/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,49 @@ export class SecretFromVariable extends Construct {
repository: Repository | DataGithubRepository,
ghProvider: GithubProvider
) {
const secret = setOldId(
new ActionsSecret(repository, `secret-${this.name}`, {
const moveLabel = (label: string) =>
`${this.node.path}-${repository.node.path}-${label}`;
const oldActionSecret = new ActionsSecret(
repository,
`secret-${this.name}-old`,
{
plaintextValue: this.variable.value,
secretName: constantCase(this.name),
repository: repository.name,
provider: ghProvider,
})
}
);
setOldId(oldActionSecret);
oldActionSecret.moveTo(moveLabel("secret"));

const secret = new ActionsSecret(repository, `secret-${this.name}`, {
plaintextValue: this.variable.value,
secretName: constantCase(this.name),
repository: repository.name,
provider: ghProvider,
});
secret.addMoveTarget(moveLabel("secret"));

this.secretNames.forEach((name) => {
setOldId(
new ActionsSecret(repository, `secret-${this.name}-alias-${name}`, {
const oldActionSecretAlias = new ActionsSecret(
repository,
`secret-${this.name}-alias-${name}-old`,
{
plaintextValue: this.variable.value,
secretName: constantCase(name),
repository: repository.name,
provider: ghProvider,
})
}
);
setOldId(oldActionSecretAlias);
oldActionSecretAlias.moveTo(moveLabel("secret-alias-" + name));

new ActionsSecret(repository, `secret-${this.name}-alias-${name}`, {
plaintextValue: this.variable.value,
secretName: constantCase(name),
repository: repository.name,
provider: ghProvider,
}).addMoveTarget(moveLabel("secret-alias-" + name));
});

return secret;
Expand Down

0 comments on commit fab345b

Please sign in to comment.