You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the feature or problem you’d like to solve
I have built a ruleset for a repository in one owner (for testing) and would like to copy it to another repository (in this case, a fork-related repository, although as my rules are fairly generic, i'd probably like to be able to copy it generally).
For some context, a create subcommand was originally not added because creating a ruleset is just too complex of an operation to really support interactively. You'd essentially have to pass the API endpoint's raw JSON payload into the subcommand, at which point there's no real benefit over using gh api. There was some discussion about accepting YAML input that's transformed into the correct JSON, but that would likely end up too complex for no major benefit.
My gut reaction is that this feature request would probably be simple enough to do:
import subcommand accepts a file path, destination (either org or repo), and name, then grabs the JSON in the file, tweaks it as needed, and passes it directly to the "Create a ruleset" REST API endpoint
This would limit the CLI's role to just transforming the JSON from one endpoint to the other, which shouldn't be too large of a scope.
My only concern is that rulesets are still in active development and more features are in the works, so the API shape will likely change enough that the CLI has to be updated when these new features roll out. This isn't inherently a problem, but it's just something to keep in mind because it ties the CLI to the shape of the feature a bit more tightly than the other CLI features I'm familiar with.
Thanks for the explanation and historical context.
My only concern is that rulesets are still in active development and more features are in the works, so the API shape will likely change enough that the CLI has to be updated when these new features roll out. This isn't inherently a problem, but it's just something to keep in mind because it ties the CLI to the shape of the feature a bit more tightly than the other CLI features I'm familiar with.
Can you describe some of the changes the API might make that might require a CLI change? I'm thinking these APIs are versioned and shouldn't be introducing breaking changes right? If it is a problem, perhaps an extension would be a natural place for this to live until things stabilise.
I checked with the rulesets team, and they're actually currently working on import/export via the UI. There are tentative plans for API endpoints to support this as well, but those are still in the earlier stages so no promises on a timeline.
The CLI could add support now using the process I put above and swap over to the new endpoints if/when they're added, but it probably makes more sense to wait a bit to see what happens.
I could see this feature being necessary for duplicating organization repository rulesets across enterprises with 100s of organizations. Otherwise, I would configure select repositories at the organizational repository ruleset.
Assuming ruleset patterns only include repository names and not the owners, I don't see a problem in including that in the output or consumed input.
My starting point is a repository (jsoref/check-spelling) that's a fork of an upstream (check-spelling/check-spelling). Before I deploy changes to the upstream, I try to test them in my fork.
Beyond that, I control a handful of organizations and being able to copy rulesets across them seems incredibly handy.
I would really like this, it would help me automate initial setups of repos that we internally create from templates(they're not forks so they don't inherit this)
Currently it's still a manual setup
Reacted by Elliot Maincourt, Andy Barilla and ZHANG Yuntian
Activity
williammartin commentedon Sep 19, 2023
@vaindil can I get your 👀 on this please? It seems like an interesting use case to me but I'm not particularly familiar with the ruleset offering.
vaindil commentedon Sep 19, 2023
For some context, a
createsubcommand was originally not added because creating a ruleset is just too complex of an operation to really support interactively. You'd essentially have to pass the API endpoint's raw JSON payload into the subcommand, at which point there's no real benefit over usinggh api. There was some discussion about accepting YAML input that's transformed into the correct JSON, but that would likely end up too complex for no major benefit.My gut reaction is that this feature request would probably be simple enough to do:
exportsubcommand dumps the full body of the "Get a repository ruleset" REST API endpointimportsubcommand accepts a file path, destination (either org or repo), and name, then grabs the JSON in the file, tweaks it as needed, and passes it directly to the "Create a ruleset" REST API endpointThis would limit the CLI's role to just transforming the JSON from one endpoint to the other, which shouldn't be too large of a scope.
My only concern is that rulesets are still in active development and more features are in the works, so the API shape will likely change enough that the CLI has to be updated when these new features roll out. This isn't inherently a problem, but it's just something to keep in mind because it ties the CLI to the shape of the feature a bit more tightly than the other CLI features I'm familiar with.
williammartin commentedon Sep 20, 2023
Thanks for the explanation and historical context.
Can you describe some of the changes the API might make that might require a CLI change? I'm thinking these APIs are versioned and shouldn't be introducing breaking changes right? If it is a problem, perhaps an extension would be a natural place for this to live until things stabilise.
vaindil commentedon Sep 20, 2023
I checked with the rulesets team, and they're actually currently working on import/export via the UI. There are tentative plans for API endpoints to support this as well, but those are still in the earlier stages so no promises on a timeline.
The CLI could add support now using the process I put above and swap over to the new endpoints if/when they're added, but it probably makes more sense to wait a bit to see what happens.
williammartin commentedon Sep 21, 2023
Ok I'm going to keep this open so that it is visible, and label it with
coreuntil we get more clarity on what the team are going to do.andyfeller commentedon Sep 25, 2023
@jsoref : How would this request work with organizational repository rulesets?
I could see this feature being necessary for duplicating organization repository rulesets across enterprises with 100s of organizations. Otherwise, I would configure select repositories at the organizational repository ruleset.
jsoref commentedon Sep 26, 2023
Assuming ruleset patterns only include repository names and not the owners, I don't see a problem in including that in the output or consumed input.
My starting point is a repository (jsoref/check-spelling) that's a fork of an upstream (check-spelling/check-spelling). Before I deploy changes to the upstream, I try to test them in my fork.
Beyond that, I control a handful of organizations and being able to copy rulesets across them seems incredibly handy.
jsoref commentedon Sep 26, 2023
For example, I could definitely see the value in writing a ruleset that applied to
.githuband.github-private.macel94 commentedon Nov 28, 2024
I would really like this, it would help me automate initial setups of repos that we internally create from templates(they're not forks so they don't inherit this)
Currently it's still a manual setup
RadxaYuntian commentedon Mar 27, 2025
Example bash script for how we update exported ruleset with
gh api:feat: add gh ruleset create, update, and delete commands (#3)
Upstream sync 2026-05-29 (#16)
Upstream sync 2026-05-29 (#19)
feat: add gh ruleset create, update, and delete commands (#3)
feat: add gh ruleset create, update, and delete commands (#3)
feat: add gh ruleset create, update, and delete commands (#3)
feat: add gh ruleset create, update, and delete commands (#3)