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

Invalid defaults for merge_commit_message, merge_commit_title #1541

Open
guineveresaenger opened this issue Feb 9, 2023 · 4 comments
Open
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Stale Used by stalebot to clean house Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@guineveresaenger
Copy link

I run terraform import on a github repository with ☑️ Allow Merge Commits and set to "Default to pull request title and description".

Pulling out the resulting state into my main.tf:

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "~> 5.0"
    }
  }
}

# Configure the GitHub Provider
provider "github" {
    token = xxx
    owner = pulumi
}

resource "github_repository" "myrepo" {
    name = "myrepo"
    description = "A test repo"
    has_downloads = true
    has_issues= true
    has_projects= true
    has_wiki= true
    merge_commit_message= "PR_BODY"
    merge_commit_title= "PR_TITLE"
    delete_branch_on_merge = true
}

No changes when running terraform apply.

Now, I would like to disable merge commits, so I set allow_merge_commit to false and remove merge_commit_message and merge_commit_title:

resource "github_repository" "myrepo" {
    name = "myrepo"
    description = "A test repo"
    has_downloads = true
    has_issues= true
    has_projects= true
    has_wiki= true
#     merge_commit_message= "PR_BODY"
#     merge_commit_title= "PR_TITLE"
    delete_branch_on_merge = true
    allow_merge_commit =  false
}

And I get the following output, which tells me that somehow the defaults for the message and title fields are wrong.

Plan:

Terraform will perform the following actions:

  # github_repository.myrepo will be updated in-place
  ~ resource "github_repository" "myrepo" {
      ~ allow_merge_commit          = true -> false
        id                          = "myrepo"
      ~ merge_commit_message        = "PR_BODY" -> "PR_TITLE"
      ~ merge_commit_title          = "PR_TITLE" -> "MERGE_MESSAGE"
        name                        = "myrepo"
        # (30 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Apply:

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

github_repository.myrepo: Modifying... [id=myrepo]
╷
│ Error: PATCH https://api.github.com/repos/pulumi/myrepo: 422 Validation Failed [{Resource:Repository Field:merge_commit_allowed Code:invalid Message:Sorry, you need to allow the merge commit strategy in order to set the default merge commit message title and message. (no_merge_strategy)}]
│ 
│   with github_repository.myrepo,
│   on main.tf line 16, in resource "github_repository" "myrepo":
│   16: resource "github_repository" "myrepo" {
│ 
╵

I thought it was a little odd that the value for merge_commit_message wanted to update "PR_BODY" -> "PR_TITLE"
and likewise merge_commit_title to "PR_BODY" -> "MERG_MESSAGE". It looks like someone confused those two defaults? I went looking and found the go-client is confused as well:
https://github.com/google/go-github/blob/master/github/repos.go#L75

Regardless, this provider should not attempt to re-set these two fields at the same time as disabling merge commits altogether.

@github-project-automation github-project-automation bot moved this to 🆕 Triage in 🧰 Octokit Active Feb 9, 2023
@nickfloyd nickfloyd moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Feb 10, 2023
@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone Priority: Normal Type: Bug Something isn't working as documented labels Feb 17, 2023
@tuwid
Copy link

tuwid commented Mar 3, 2023

experiencing same issue with the merge strategies, regardless of the tittle

@juicybaba
Copy link

same issue.
quick workaround.

  1. enable allow_merge_commit in the code and apply.
  2. disable allow_merge_commit in the code and apply.

@meliamzz
Copy link

meliamzz commented Apr 7, 2024

I have the same issue, and it's seems more related to the github API. I raised a ticket, they are investigating.
I found out a workaround :

  • Go on the Pull request settings of the repo (in the UI)
  • Enable merge commit
  • And set the default commit message to -> Default message
  • Disable merge commit

It should be fixed.

Copy link

github-actions bot commented Jan 3, 2025

👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!

@github-actions github-actions bot added the Status: Stale Used by stalebot to clean house label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Stale Used by stalebot to clean house Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
None yet
Development

No branches or pull requests

6 participants