From c27677bda67bf97810bd06a12e863a3da458c3eb Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Thu, 24 Oct 2024 15:21:59 -0400 Subject: [PATCH 1/2] Add comprehensive testscript for `gh ruleset` --- acceptance/acceptance_test.go | 9 +++ acceptance/testdata/ruleset/commandset.txtar | 62 ++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 acceptance/testdata/ruleset/commandset.txtar diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 25ae91d77..24cb083c9 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -117,6 +117,15 @@ func TestRepo(t *testing.T) { testscript.Run(t, testScriptParamsFor(tsEnv, "repo")) } +func TestRulesets(t *testing.T) { + var tsEnv testScriptEnv + if err := tsEnv.fromEnv(); err != nil { + t.Fatal(err) + } + + testscript.Run(t, testScriptParamsFor(tsEnv, "ruleset")) +} + func TestSearches(t *testing.T) { var tsEnv testScriptEnv if err := tsEnv.fromEnv(); err != nil { diff --git a/acceptance/testdata/ruleset/commandset.txtar b/acceptance/testdata/ruleset/commandset.txtar new file mode 100644 index 000000000..99be3683c --- /dev/null +++ b/acceptance/testdata/ruleset/commandset.txtar @@ -0,0 +1,62 @@ +# Setup environment variables used for testscript +env REPO=${SCRIPT_NAME}-${RANDOM_STRING} + +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$REPO --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$REPO + +# Clone the repo +exec gh repo clone $ORG/$REPO +cd $REPO + +# Verify repository ruleset does not exist +env LIST_MATCH=testscript\s+$ORG/$REPO (repo) +exec gh ruleset list +! stdout $LIST_MATCH + +# Verify no repository ruleset applies to default branch +exec gh ruleset check +stdout '0 rules apply' + +# Create a repository ruleset +exec gh api /repos/{owner}/{repo}/rulesets -X POST --input ../create-repo-ruleset.json + +# Verify repository ruleset does exist +exec gh ruleset list +stdout $LIST_MATCH + +# Verify repository ruleset associated with branch +exec gh ruleset check +stdout '- pull_request:.+dismiss_stale_reviews_on_push: false.+require_code_owner_review: true.+require_last_push_approval: false.+required_approving_review_count: 1.+required_review_thread_resolution: false' + +-- create-repo-ruleset.json -- +{ + "name": "testscript", + "target": "branch", + "enforcement": "active", + "conditions": { + "ref_name": { + "include": [ + "~DEFAULT_BRANCH" + ], + "exclude": [] + } + }, + "rules": [ + { + "type": "pull_request", + "parameters": { + "dismiss_stale_reviews_on_push": false, + "require_code_owner_review": true, + "require_last_push_approval": false, + "required_approving_review_count": 1, + "required_review_thread_resolution": false + } + } + ] +} From 6dc86e5f40c5b4ee55f5675398ed54c17ac3f4ed Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Fri, 25 Oct 2024 08:58:16 -0400 Subject: [PATCH 2/2] Rename testscript for consistency Similar to `gpg-key`, `label`, `ssh-key`, this coarse grained testscript should be named after the commandset given it isn't a collection of targeted scenarios. --- acceptance/testdata/ruleset/{commandset.txtar => ruleset.txtar} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename acceptance/testdata/ruleset/{commandset.txtar => ruleset.txtar} (100%) diff --git a/acceptance/testdata/ruleset/commandset.txtar b/acceptance/testdata/ruleset/ruleset.txtar similarity index 100% rename from acceptance/testdata/ruleset/commandset.txtar rename to acceptance/testdata/ruleset/ruleset.txtar