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 support for configuring default squash and merge commit titles and messages #137

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.18.0]

### Changed

- BREAKING: update to provider `>= 4.31` for supporting default squash and merge commit titles and messages

### Added

- Add support for `squash_merge_commit_title`
- Add support for `squash_merge_commit_message`
- Add support for `merge_commit_title`
- Add support for `merge_commit_message`
- Add support for `ignore_vulnerability_alerts_during_read`

## [0.17.0]

### Added
Expand Down Expand Up @@ -385,7 +399,8 @@ Please review plans and report regressions and issues asap so we can improve doc
- This is the initial release of our GitHub Repository module with support for
creating and managing GitHub Repositories for Organizations.

[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.17.0...HEAD
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.18.0...HEAD
[0.18.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.17.0...v0.18.0
[0.17.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.16.2...v0.17.0
[0.16.2]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.16.1...v0.16.2
[0.16.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.16.0...v0.16.1
Expand Down
53 changes: 46 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
[![Build Status](https://github.com/mineiros-io/terraform-github-repository/workflows/CI/CD%20Pipeline/badge.svg)](https://github.com/mineiros-io/terraform-github-repository/actions)
[![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/mineiros-io/terraform-github-repository.svg?label=latest&sort=semver)](https://github.com/mineiros-io/terraform-github-repository/releases)
[![Terraform Version](https://img.shields.io/badge/terraform-1.x-623CE4.svg?logo=terraform)](https://github.com/hashicorp/terraform/releases)
[![Github Provider Version](https://img.shields.io/badge/GH-4.10+-F8991D.svg?logo=terraform)](https://github.com/terraform-providers/terraform-provider-github/releases)
[![Github Provider Version](https://img.shields.io/badge/GH-4.31+-F8991D.svg?logo=terraform)](https://github.com/terraform-providers/terraform-provider-github/releases)
[![Join Slack](https://img.shields.io/badge/[email protected]?logo=slack)](https://join.slack.com/t/mineiros-community/shared_invite/zt-ehidestg-aLGoIENLVs6tvwJ11w9WGg)

# terraform-github-repository

A [Terraform] module for creating a public or private repository on [Github].

**_This module supports Terraform v1.x and is compatible with the Official Terraform GitHub Provider v4.20 and above from `integrations/github`._**
**_This module supports Terraform v1.x and is compatible with the Official Terraform GitHub Provider v4.31 and above from `integrations/github`._**

**Attention: This module is incompatible with the Hashicorp GitHub Provider! The latest version of this module supporting `hashicorp/github` provider is `~> 0.10.0`**

** Note: Versions 5.3.0, 5.4.0, and 5.5.0 of the Terraform Github Provider have broken branch protections support and should not be used.**
** Note: Versions 5.3.0, 5.4.0, 5.5.0, and 5.6.0 of the Terraform Github Provider have broken branch protections support and should not be used.**


- [GitHub as Code](#github-as-code)
Expand Down Expand Up @@ -89,7 +89,8 @@ features like Branch Protection or Collaborator Management.
Teams,
Deploy Keys,
Projects,
Repository Webhooks
Repository Webhooks,
GitHub App Installations

- _Features not yet implemented_:
Project Columns support,
Expand All @@ -103,7 +104,7 @@ Most basic usage creating a new private github repository.
```hcl
module "repository" {
source = "mineiros-io/repository/github"
version = "~> 0.16.0"
version = "~> 0.18.0"

name = "terraform-github-repository"
license_template = "apache-2.0"
Expand Down Expand Up @@ -147,18 +148,28 @@ See [variables.tf] and [examples/] for details and use-cases.
`has_issues`,
`has_projects`,
`has_wiki`,
`has_downloads`,
`delete_branch_on_merge`,
`is_template`,
`allow_merge_commit`,
`allow_rebase_merge`,
`allow_squash_merge`,
`allow_auto_merge`,
`has_downloads`,
`auto_init`,
`gitignore_template`,
`license_template`,
`squash_merge_commit_title`,
`squash_merge_commit_message`,
`merge_commit_title`,
`merge_commit_message`,
`auto_init`,
`default_branch`,
`topics`,
`issue_labels_create`,
`issue_labels_merge_with_github_labels`.
`issue_labels_merge_with_github_labels`,
`vulnerability_alerts`,
`ignore_vulnerability_alerts_during_read`,
`template`.

Module defaults are used for all arguments that are not set in `defaults`.
Using top level arguments override defaults set by this argument.
Expand Down Expand Up @@ -216,6 +227,30 @@ See [variables.tf] and [examples/] for details and use-cases.

Default is `false`.

- [**`squash_merge_commit_title`**](#var-squash_merge_commit_title): *(Optional `string`)*<a name="var-squash_merge_commit_title"></a>

Set to `PR_TITLE` or `COMMIT_OR_PR_TITLE` for a default squash merge commit title.

Default is `"COMMIT_OR_PR_TITLE"`.

- [**`squash_merge_commit_message`**](#var-squash_merge_commit_message): *(Optional `string`)*<a name="var-squash_merge_commit_message"></a>

Set to `PR_BODY`, `COMMIT_MESSAGES`, or `BLANK` for a default squash merge commit message.

Default is `"COMMIT_MESSAGES"`.

- [**`merge_commit_title`**](#var-merge_commit_title): *(Optional `string`)*<a name="var-merge_commit_title"></a>

Set to `PR_TITLE` or `MERGE_MESSAGE` for a default merge commit title.

Default is `"MERGE_MESSAGE"`.

- [**`merge_commit_message`**](#var-merge_commit_message): *(Optional `string`)*<a name="var-merge_commit_message"></a>

Set to `PR_BODY`, `PR_TITLE`, or `BLANK` for a default merge commit message.

Default is `"PR_TITLE"`.

- [**`description`**](#var-description): *(Optional `string`)*<a name="var-description"></a>

A description of the repository.
Expand Down Expand Up @@ -310,6 +345,10 @@ See [variables.tf] and [examples/] for details and use-cases.
Set to `false` to disable security alerts for vulnerable dependencies.
Enabling requires alerts to be enabled on the owner level.

- [**`ignore_vulnerability_alerts_during_read`**](#var-ignore_vulnerability_alerts_during_read): *(Optional `bool`)*<a name="var-ignore_vulnerability_alerts_during_read"></a>

Set to `true` to not call the vulnerability alerts endpoint so the resource can also be used without admin permissions during read.

- [**`archive_on_destroy`**](#var-archive_on_destroy): *(Optional `bool`)*<a name="var-archive_on_destroy"></a>

Set to `false` to not archive the repository instead of deleting on destroy.
Expand Down
64 changes: 57 additions & 7 deletions README.tfdoc.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ header {
}

badge "tf-gh" {
image = "https://img.shields.io/badge/GH-4.10+-F8991D.svg?logo=terraform"
image = "https://img.shields.io/badge/GH-4.31+-F8991D.svg?logo=terraform"
url = "https://github.com/terraform-providers/terraform-provider-github/releases"
text = "Github Provider Version"
}
Expand All @@ -39,11 +39,11 @@ section {
content = <<-END
A [Terraform] module for creating a public or private repository on [Github].

**_This module supports Terraform v1.x and is compatible with the Official Terraform GitHub Provider v4.20 and above from `integrations/github`._**
**_This module supports Terraform v1.x and is compatible with the Official Terraform GitHub Provider v4.31 and above from `integrations/github`._**

**Attention: This module is incompatible with the Hashicorp GitHub Provider! The latest version of this module supporting `hashicorp/github` provider is `~> 0.10.0`**

** Note: Versions 5.3.0, 5.4.0, and 5.5.0 of the Terraform Github Provider have broken branch protections support and should not be used.**
** Note: Versions 5.3.0, 5.4.0, 5.5.0, and 5.6.0 of the Terraform Github Provider have broken branch protections support and should not be used.**
END

section {
Expand Down Expand Up @@ -92,7 +92,8 @@ section {
Teams,
Deploy Keys,
Projects,
Repository Webhooks
Repository Webhooks,
GitHub App Installations

- _Features not yet implemented_:
Project Columns support,
Expand All @@ -109,7 +110,7 @@ section {
```hcl
module "repository" {
source = "mineiros-io/repository/github"
version = "~> 0.16.0"
version = "~> 0.18.0"

name = "terraform-github-repository"
license_template = "apache-2.0"
Expand Down Expand Up @@ -164,18 +165,28 @@ section {
`has_issues`,
`has_projects`,
`has_wiki`,
`has_downloads`,
`delete_branch_on_merge`,
`is_template`,
`allow_merge_commit`,
`allow_rebase_merge`,
`allow_squash_merge`,
`allow_auto_merge`,
`has_downloads`,
`auto_init`,
`gitignore_template`,
`license_template`,
`squash_merge_commit_title`,
`squash_merge_commit_message`,
`merge_commit_title`,
`merge_commit_message`,
`auto_init`,
`default_branch`,
`topics`,
`issue_labels_create`,
`issue_labels_merge_with_github_labels`.
`issue_labels_merge_with_github_labels`,
`vulnerability_alerts`,
`ignore_vulnerability_alerts_during_read`,
`template`.

Module defaults are used for all arguments that are not set in `defaults`.
Using top level arguments override defaults set by this argument.
Expand Down Expand Up @@ -251,6 +262,38 @@ section {
END
}

variable "squash_merge_commit_title" {
type = string
default = "COMMIT_OR_PR_TITLE"
description = <<-END
Set to `PR_TITLE` or `COMMIT_OR_PR_TITLE` for a default squash merge commit title.
END
}

variable "squash_merge_commit_message" {
type = string
default = "COMMIT_MESSAGES"
description = <<-END
Set to `PR_BODY`, `COMMIT_MESSAGES`, or `BLANK` for a default squash merge commit message.
END
}

variable "merge_commit_title" {
type = string
default = "MERGE_MESSAGE"
description = <<-END
Set to `PR_TITLE` or `MERGE_MESSAGE` for a default merge commit title.
END
}

variable "merge_commit_message" {
type = string
default = "PR_TITLE"
description = <<-END
Set to `PR_BODY`, `PR_TITLE`, or `BLANK` for a default merge commit message.
END
}

variable "description" {
type = string
default = ""
Expand Down Expand Up @@ -377,6 +420,13 @@ section {
END
}

variable "ignore_vulnerability_alerts_during_read" {
type = bool
description = <<-END
Set to `true` to not call the vulnerability alerts endpoint so the resource can also be used without admin permissions during read.
END
}

variable "archive_on_destroy" {
type = bool
default = true
Expand Down
2 changes: 1 addition & 1 deletion examples/public-repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ branch protection.
```hcl
module "repository" {
source = "mineiros-io/repository/github"
version = "~> 0.13.0"
version = "~> 0.18.0"

module_depends_on = [
github_team.team
Expand Down
15 changes: 13 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ locals {
visibility = var.visibility == null ? lookup(var.defaults, "visibility", local.private_visibility) : var.visibility
has_issues = var.has_issues == null ? lookup(var.defaults, "has_issues", false) : var.has_issues
has_projects = var.has_projects == null ? lookup(var.defaults, "has_projects", false) : length(var.projects) > 0 ? true : var.has_projects
has_downloads = var.has_downloads == null ? lookup(var.defaults, "has_downloads", false) : var.has_downloads
has_wiki = var.has_wiki == null ? lookup(var.defaults, "has_wiki", false) : var.has_wiki
allow_merge_commit = var.allow_merge_commit == null ? lookup(var.defaults, "allow_merge_commit", true) : var.allow_merge_commit
allow_rebase_merge = var.allow_rebase_merge == null ? lookup(var.defaults, "allow_rebase_merge", false) : var.allow_rebase_merge
allow_squash_merge = var.allow_squash_merge == null ? lookup(var.defaults, "allow_squash_merge", false) : var.allow_squash_merge
allow_auto_merge = var.allow_auto_merge == null ? lookup(var.defaults, "allow_auto_merge", false) : var.allow_auto_merge
delete_branch_on_merge = var.delete_branch_on_merge == null ? lookup(var.defaults, "delete_branch_on_merge", true) : var.delete_branch_on_merge
is_template = var.is_template == null ? lookup(var.defaults, "is_template", false) : var.is_template
has_downloads = var.has_downloads == null ? lookup(var.defaults, "has_downloads", false) : var.has_downloads
auto_init = var.auto_init == null ? lookup(var.defaults, "auto_init", true) : var.auto_init
gitignore_template = var.gitignore_template == null ? lookup(var.defaults, "gitignore_template", "") : var.gitignore_template
license_template = var.license_template == null ? lookup(var.defaults, "license_template", "") : var.license_template
Expand All @@ -29,6 +29,11 @@ locals {
issue_labels_create = var.issue_labels_create == null ? lookup(var.defaults, "issue_labels_create", local.issue_labels_create_computed) : var.issue_labels_create
branch_protections_v3 = var.branch_protections_v3 == null ? var.branch_protections : var.branch_protections_v3

squash_merge_commit_title = var.squash_merge_commit_title == null ? try(var.defaults.squash_merge_commit_title, "COMMIT_OR_PR_TITLE") : var.squash_merge_commit_title
squash_merge_commit_message = var.squash_merge_commit_message == null ? try(var.defaults.squash_merge_commit_message, "COMMIT_MESSAGES") : var.squash_merge_commit_message
merge_commit_title = var.merge_commit_title == null ? try(var.defaults.merge_commit_title, "MERGE_MESSAGE") : var.merge_commit_title
merge_commit_message = var.merge_commit_message == null ? try(var.merge_commit_message, "PR_TITLE") : var.merge_commit_message

issue_labels_create_computed = local.has_issues || length(var.issue_labels) > 0

# for readability
Expand All @@ -37,7 +42,8 @@ locals {

issue_labels_merge_with_github_labels = local.gh_labels
# Per default, GitHub activates vulnerability alerts for public repositories and disables it for private repositories
vulnerability_alerts = var.vulnerability_alerts != null ? var.vulnerability_alerts : local.private ? false : true
vulnerability_alerts = var.vulnerability_alerts != null ? var.vulnerability_alerts : local.private ? false : true
ignore_vulnerability_alerts_during_read = var.ignore_vulnerability_alerts_during_read == null ? try(var.defaults.ignore_vulnerability_alerts_during_read, null) : var.ignore_vulnerability_alerts_during_read
}

locals {
Expand Down Expand Up @@ -113,6 +119,11 @@ resource "github_repository" "repository" {
archive_on_destroy = var.archive_on_destroy
vulnerability_alerts = local.vulnerability_alerts

squash_merge_commit_title = local.squash_merge_commit_title
squash_merge_commit_message = local.squash_merge_commit_message
merge_commit_title = local.merge_commit_title
merge_commit_message = local.merge_commit_message

dynamic "template" {
for_each = local.template

Expand Down
2 changes: 1 addition & 1 deletion test/unit-complete/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 5.0, !=5.3.0, !=5.4.0, !=5.5.0"
version = "~> 5.0, !=5.3.0, !=5.4.0, !=5.5.0, !=5.6.0, !=5.7.0"
}
tls = {
source = "hashicorp/tls"
Expand Down
2 changes: 1 addition & 1 deletion test/unit-complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ variable "allow_auto_merge" {
default = true
}


variable "has_downloads" {
description = "Set to true to enable the (deprecated) downloads features on the repository."
type = bool
Expand Down Expand Up @@ -156,6 +155,7 @@ variable "repository_defaults" {
homepage_url = "https://github.com/mineiros-io"
visibility = "private"
allow_merge_commit = true
allow_squash_merge = false
gitignore_template = "Terraform"
license_template = "mit"
topics = ["terraform", "integration-test"]
Expand Down
Loading