0

Is there a way to store my github repo's settings "as-code" rather than interacting with the settings via UI? Aka these things:

enter image description here

I would like to do this so that:

  1. We can keep a history of changes
  2. Changes can be PR reviewed

Right now our team has several admins and people frequently update settings. This makes it hard to understand why settings are setup a certain way. This is paticularly an issue with branch protection rules:

enter image description here

I would like some way to store all of these settings in a text file, either in YAML or Terraform or something else. Is this possible?

2
  • 1
    It would be nice if you could put a file in .github/, but I don't believe there's anything like that. Many settings can be queried and set with the Github API. You could write those as a configuration file, plus a program to apply changes via the API. Commented Oct 28, 2024 at 21:01
  • 1
    An Infrastructure as Code tool such as OpenTofu (a fork of Terraform) with a GitHub provider should let you keep your configuration outside of GitHub and have it sync stats to the definition you've written instead: search.opentofu.org/provider/opentofu/github/latest - see the documentation for the types of resources you can configure. Commented Oct 28, 2024 at 21:07

1 Answer 1

1

There are mainly 3 options that I've found. I haven't tried either of them myself yet though.

  1. https://github.com/github/safe-settings

    an app to manage policy-as-code and apply repository settings across an organization.

  2. Custom script with GH CLI similar to https://github.com/adamchainz/scripts/blob/main/myrepos/0000-repo-settings.sh

  3. Terraform https://registry.terraform.io/providers/integrations/github/latest/docs

P.S. .github/ (even euphemeral) approach doesn't seem adequate as it would allow anybody having commit access to update repo settings, which effectively hijacks GH permissions model.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.