Skip to content

Commit

Permalink
Merge pull request #8700 from ministryofjustice/feature/update-defaul…
Browse files Browse the repository at this point in the history
…t-behaviour-for-repository-squash-merges

Added optional configuration to keep squash merges tidy
  • Loading branch information
dms1981 authored Dec 6, 2024
2 parents 962734e + 17087ee commit d59e027
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 41 deletions.
40 changes: 21 additions & 19 deletions terraform/github/modules/repository/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ locals {

# Repository basics
resource "github_repository" "default" {
name = var.name
description = join("", [var.description, "This repository is defined and managed in Terraform"])
allow_merge_commit = true
allow_squash_merge = true
allow_rebase_merge = true
allow_update_branch = true
archived = false
archive_on_destroy = true
auto_init = false
delete_branch_on_merge = true
has_issues = true
has_projects = true
has_wiki = var.type == "core" ? true : false
has_downloads = true
homepage_url = var.homepage_url
is_template = var.type == "template" ? true : false
topics = concat(local.topics, var.topics)
visibility = var.visibility
vulnerability_alerts = true
name = var.name
description = join("", [var.description, "This repository is defined and managed in Terraform"])
allow_merge_commit = true
allow_squash_merge = true
allow_rebase_merge = true
allow_update_branch = true
archived = false
archive_on_destroy = true
auto_init = false
delete_branch_on_merge = true
has_issues = true
has_projects = true
has_wiki = var.type == "core" ? true : false
has_downloads = true
homepage_url = var.homepage_url
is_template = var.type == "template" ? true : false
squash_merge_commit_title = var.squash_merge_commit_message == true ? "PR_TITLE" : null
squash_merge_commit_message = var.squash_merge_commit_title == true ? "COMMIT_MESSAGES" : null
topics = concat(local.topics, var.topics)
visibility = var.visibility
vulnerability_alerts = true

security_and_analysis {
dynamic "advanced_security" {
Expand Down
48 changes: 30 additions & 18 deletions terraform/github/modules/repository/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,48 @@ variable "description" {
description = "Repository description"
}

variable "dismissal_restrictions" {
type = list(string)
description = "The list of actor Names/IDs with dismissal access e.g. 'exampleorganization/exampleteam' or '/exampleuser'"
default = []
}

variable "homepage_url" {
type = string
description = "Repository homepage URL"
default = ""
}

variable "required_checks" {
type = list(string)
description = "List of required checks"
default = []
}

variable "restrict_dismissals" {
type = bool
description = "Restrict pull request review dismissals"
default = false
}

variable "secrets" {
type = map(any)
description = "key:value map for GitHub actions secrets"
default = {}
}

variable "squash_merge_commit_message" {
type = bool
description = "Should squash merge commit message be set to MERGE_MESSAGE?"
default = true
}

variable "squash_merge_commit_title" {
type = bool
description = "Should squash merge commit title be set to PR_TITLE?"
default = true
}

variable "topics" {
type = list(string)
description = "Repository topics, in addition to 'modernisation-platform', 'terraform-module', 'civil-service'"
Expand All @@ -36,21 +66,3 @@ variable "visibility" {
description = "Visibility type: `public`, `internal`, `private`"
default = "public"
}

variable "required_checks" {
type = list(string)
description = "List of required checks"
default = []
}

variable "restrict_dismissals" {
type = bool
description = "Restrict pull request review dismissals"
default = false
}

variable "dismissal_restrictions" {
type = list(string)
description = "The list of actor Names/IDs with dismissal access e.g. 'exampleorganization/exampleteam' or '/exampleuser'"
default = []
}
10 changes: 6 additions & 4 deletions terraform/github/repositories.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ module "terraform-module-cross-account-access" {
}

module "terraform-module-environments" {
source = "./modules/repository"
name = "modernisation-platform-terraform-environments"
type = "module"
description = "Module for creating organizational units and accounts within AWS Organizations from JSON files"
source = "./modules/repository"
name = "modernisation-platform-terraform-environments"
type = "module"
description = "Module for creating organizational units and accounts within AWS Organizations from JSON files"
squash_merge_commit_message = false
squash_merge_commit_title = false
topics = [
"organizational-units",
"aws"
Expand Down

0 comments on commit d59e027

Please sign in to comment.