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

add github slack webhook feed #93

Merged
merged 2 commits into from Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/.gitignore
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
8 changes: 4 additions & 4 deletions README.md
@@ -1,11 +1,11 @@
# repository-manager

## About
This project handles repository management for the prebuilt Terraform provider packages that are published for use with [Cloud Development Kit for Terraform (CDKTF)](https://github.com/hashicorp/terraform-cdk).

CDKTF allows you to use familiar programming languages to define cloud infrastructure and provision it through HashiCorp Terraform. This gives you access to the entire Terraform ecosystem without learning HashiCorp Configuration Language (HCL). Terraform providers can be generated locally to be used with your application, or installed via one of the prebuilt packages. We currently publish and maintain a small subset of prebuilt packages for the Terraform providers that currently have the highest usage in CDKTF apps. The current list of prebuilt provider packages can be found [here](https://github.com/hashicorp/cdktf-repository-manager/blob/main/provider.json).
This project handles repository management for the prebuilt Terraform provider packages that are published for use with [Cloud Development Kit for Terraform (CDKTF)](https://github.com/hashicorp/terraform-cdk).

## Information for HashiCorp Partners
We are currently prioritizing publishing a small subset of prebuilt provider packages, based on usage in existing CDKTF applications. If you are a current partner and you are interested in having a prebuilt package made available for your provider, please contact us at [technologypartners@hashicorp.com](mailto:technologypartners@hashicorp.com) and we will add it to the team’s list for prioritization.
CDKTF allows you to use familiar programming languages to define cloud infrastructure and provision it through HashiCorp Terraform. This gives you access to the entire Terraform ecosystem without learning HashiCorp Configuration Language (HCL). Terraform providers can be generated locally to be used with your application, or installed via one of the prebuilt packages. We currently publish and maintain a small subset of prebuilt packages for the Terraform providers that currently have the highest usage in CDKTF apps. The current list of prebuilt provider packages can be found [here](https://github.com/hashicorp/cdktf-repository-manager/blob/main/provider.json).

## Information for HashiCorp Partners

We are currently prioritizing publishing a small subset of prebuilt provider packages, based on usage in existing CDKTF applications. If you are a current partner and you are interested in having a prebuilt package made available for your provider, please contact us at [technologypartners@hashicorp.com](mailto:technologypartners@hashicorp.com) and we will add it to the team’s list for prioritization.
4 changes: 2 additions & 2 deletions lib/index.ts
@@ -1,2 +1,2 @@
export * from './repository'
export * from './secret'
export * from "./repository";
export * from "./secret";
79 changes: 55 additions & 24 deletions lib/repository.ts
@@ -1,6 +1,12 @@
import { Construct } from 'constructs';
import { Resource } from 'cdktf';
import { Repository, TeamRepository, BranchProtection, IssueLabel } from '@cdktf/provider-github'
import { Construct } from "constructs";
import { Resource } from "cdktf";
import {
Repository,
TeamRepository,
BranchProtection,
IssueLabel,
RepositoryWebhook,
} from "@cdktf/provider-github";

export interface ITeam {
id: string;
Expand All @@ -11,6 +17,7 @@ export interface RepositoryConfig {
topics?: string[];
team: ITeam;
protectMain?: boolean;
webhookUrl: string;
}

export class GithubRepository extends Resource {
Expand All @@ -21,49 +28,73 @@ export class GithubRepository extends Resource {

const {
topics = [],
description = 'Repository management for prebuilt cdktf providers via cdktf',
description = "Repository management for prebuilt cdktf providers via cdktf",
team,
protectMain = false,
} = config;

this.resource = new Repository(this, 'repo', {
this.resource = new Repository(this, "repo", {
name,
description,
visibility: 'public',
homepageUrl: 'https://cdk.tf',
visibility: "public",
homepageUrl: "https://cdk.tf",
hasIssues: true,
hasWiki: false,
autoInit: true,
hasProjects: false,
deleteBranchOnMerge: true,
topics: ['cdktf', 'terraform', 'terraform-cdk', 'cdk', 'provider', 'pre-built-provider', ...topics],
})

topics: [
"cdktf",
"terraform",
"terraform-cdk",
"cdk",
"provider",
"pre-built-provider",
...topics,
],
});

new IssueLabel(this, `automerge-label`, {
color: '5DC8DB',
name: 'automerge',
color: "5DC8DB",
name: "automerge",
repository: this.resource.name,
})
});

if (protectMain) {
new BranchProtection(this, 'main-protection', {
pattern: 'main',
new BranchProtection(this, "main-protection", {
pattern: "main",
repositoryId: this.resource.name,
enforceAdmins: true,
allowsDeletions: false,
allowsForcePushes: false,
requiredStatusChecks: [{
strict: true,
contexts: ['build'],
}],
})
requiredStatusChecks: [
{
strict: true,
contexts: ["build"],
},
],
});
}

new TeamRepository(this, 'managing-team', {
new TeamRepository(this, "managing-team", {
repository: this.resource.name,
teamId: team.id,
permission: 'admin'
})
permission: "admin",
});

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

configuration: [
{
url: config.webhookUrl,
contentType: "json",
},
],

// We don't need to notify about PRs since they are auto-created
events: ["issues"],
});
}
}
}
10 changes: 10 additions & 0 deletions main.ts
Expand Up @@ -10,6 +10,7 @@ import { GithubProvider, DataGithubTeam } from "@cdktf/provider-github";
import { GithubRepository, SecretFromVariable } from "./lib";
import * as fs from "fs";
import * as path from "path";
import { TerraformVariable } from "cdktf";

const providers: Record<string, string> = JSON.parse(
fs.readFileSync(path.join(__dirname, "provider.json"), "utf8")
Expand Down Expand Up @@ -40,6 +41,11 @@ class TerraformCdkProviderStack extends TerraformStack {
},
});

const slackWebhook = new TerraformVariable(this, "slack-webhook", {
type: "string",
});
slackWebhook.overrideLogicalId("slack-webhook");

const secrets = [
"gh-token",
"npm-token",
Expand Down Expand Up @@ -72,6 +78,7 @@ class TerraformCdkProviderStack extends TerraformStack {
];
const self = new GithubRepository(this, "cdktf-repository-manager", {
team,
webhookUrl: slackWebhook.stringValue,
});
selfTokens.forEach((token) => token.for(self.resource));

Expand All @@ -80,6 +87,7 @@ class TerraformCdkProviderStack extends TerraformStack {
"cdktf-provider-project",
{
team,
webhookUrl: slackWebhook.stringValue,
}
);

Expand All @@ -91,6 +99,7 @@ class TerraformCdkProviderStack extends TerraformStack {
topics: [provider],
team,
protectMain: true,
webhookUrl: slackWebhook.stringValue,
});

// repo to publish go packages to
Expand All @@ -99,6 +108,7 @@ class TerraformCdkProviderStack extends TerraformStack {
topics: [provider],
team,
protectMain: false,
webhookUrl: slackWebhook.stringValue,
});

secrets.forEach((secret) => secret.for(repo.resource));
Expand Down
10 changes: 9 additions & 1 deletion package.json
Expand Up @@ -6,6 +6,7 @@
"license": "MPL-2.0",
"private": true,
"scripts": {
"format": "prettier --write '**/*.{ts,js,md,yml}'",
"get": "cdktf get",
"build": "yarn get && tsc",
"synth": "cdktf synth",
Expand All @@ -15,7 +16,8 @@
"upgrade": "npm i cdktf@latest cdktf-cli@latest",
"upgrade:next": "npm i cdktf@next cdktf-cli@next",
"output": "cd cdktf.out && terraform output -json -state ../terraform.tfstate",
"repos": "yarn -s output | jq 'with_entries(select(.key|match(\"providerRepos\";\"i\")))[] | .value'"
"repos": "yarn -s output | jq 'with_entries(select(.key|match(\"providerRepos\";\"i\")))[] | .value'",
"prepare": "husky install"
},
"engines": {
"node": ">=10.12"
Expand All @@ -29,6 +31,12 @@
},
"devDependencies": {
"@types/node": "^14.0.27",
"husky": ">=6",
"lint-staged": ">=10",
"prettier": "^2.7.1",
"typescript": "^3.9.7"
},
"lint-staged": {
"*.{ts,js,md,yml}": "prettier --write"
}
}