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

Fix GitHub CLI sample code about 'create a ruleset for a repository' #33821

Closed
1 task done
yasuhiroki opened this issue Jul 5, 2024 · 4 comments
Closed
1 task done
Labels
content This issue or pull request belongs to the Docs Content team fix-internally Triggers a workflow to copy the issue internally and close the current issue rest Content related to rest - overview.

Comments

@yasuhiroki
Copy link

Code of Conduct

What article on docs.github.com is affected?

https://docs.github.com/en/rest/repos/rules?apiVersion=2022-11-28#create-a-repository-ruleset

What part(s) of the article would you like to see updated?

The current GitHub CLI sample code for creating a ruleset in a repository does not work correctly. The conditions field for targeting branches cannot be defined properly.

Currently, it is written as follows:

gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/OWNER/REPO/rulesets \
   -f "name=super cool ruleset" -f "target=branch" -f "enforcement=active" -F "bypass_actors[][actor_id]=234" -f "bypass_actors[][actor_type]=Team" -f "bypass_actors[][bypass_mode]=always" -f "ref_name[include[]]=refs/heads/main" -f "ref_name[include[]]=refs/heads/master" -f "ref_name[exclude[]]=refs/heads/dev*" -f "rules[][type]=commit_author_email_pattern" -f "rules[][parameters][operator]=contains" -f "rules[][parameters][pattern]=github"

Problem

With this configuration, the conditions field remains empty, making it impossible to specify target branches in the created ruleset.

The correct way to write this is as follows:

gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/OWNER/REPO/rulesets \
   -f "name=super cool ruleset" -f "target=branch" -f "enforcement=active" -F "bypass_actors[][actor_id]=234" -f "bypass_actors[][actor_type]=Team" -f "bypass_actors[][bypass_mode]=always" -f "conditions[ref_name][include][]=refs/heads/main" -f "conditions[ref_name][include][]=refs/heads/master" -f "conditions[ref_name][exclude][]=refs/heads/dev*" -f "rules[][type]=commit_author_email_pattern" -f "rules[][parameters][operator]=contains" -f "rules[][parameters][pattern]=github"

changes:

  • ref_name[include[]]=refs/heads/mainconditions[ref_name][include][]=refs/heads/main
  • ref_name[include[]]=refs/heads/masterconditions[ref_name][include][]=refs/heads/master
  • ref_name[exclude[]]=refs/heads/dev*conditions[ref_name][exclude][]=refs/heads/dev*

Additional information

My GitHub CLI version is gh version 2.52.0 (2024-06-24)

@yasuhiroki yasuhiroki added the content This issue or pull request belongs to the Docs Content team label Jul 5, 2024
Copy link

welcome bot commented Jul 5, 2024

Thanks for opening this issue. A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines.

@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team label Jul 5, 2024
@Savannaha83

This comment was marked as spam.

@nguyenalex836 nguyenalex836 added rest Content related to rest - overview. fix-internally Triggers a workflow to copy the issue internally and close the current issue and removed triage Do not begin working on this issue until triaged by the team labels Jul 5, 2024
@docs-bot
Copy link
Collaborator

docs-bot commented Jul 5, 2024

Thank you for opening this issue! Updates to this documentation must be made internally. I have copied your issue to an internal issue, so I will close this issue.

@docs-bot docs-bot closed this as completed Jul 5, 2024
@nguyenalex836
Copy link
Contributor

@yasuhiroki Thank you so much for raising the flag on this! ✨ This portion of the docs will need to be fixed internally, and I have transferred this issue to our internal teams. I'll go ahead and close this issue 💛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content This issue or pull request belongs to the Docs Content team fix-internally Triggers a workflow to copy the issue internally and close the current issue rest Content related to rest - overview.
4 participants