From fab345b24c292f9eb975675950fe0f4ab49814d8 Mon Sep 17 00:00:00 2001 From: Daniel Schmidt Date: Wed, 1 Nov 2023 13:43:56 +0100 Subject: [PATCH] chore: migrate from old addresses to new ones --- lib/repository.ts | 133 +++++++++++++++++++++++++++++++++------------- lib/secrets.ts | 37 ++++++++++--- 2 files changed, 128 insertions(+), 42 deletions(-) diff --git a/lib/repository.ts b/lib/repository.ts index 4a05540..33cb5e5 100644 --- a/lib/repository.ts +++ b/lib/repository.ts @@ -40,6 +40,7 @@ export class RepositorySetup extends Construct { } ) { super(scope, name); + const moveLabel = (label: string) => `${this.node.path}-${label}`; const { protectMain = false, @@ -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: { @@ -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")); } } @@ -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, @@ -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, diff --git a/lib/secrets.ts b/lib/secrets.ts index 5d46f86..5560fb8 100644 --- a/lib/secrets.ts +++ b/lib/secrets.ts @@ -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;