diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 51e96778a..18757cda7 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -72,6 +72,14 @@ func TestReleases(t *testing.T) { testscript.Run(t, testScriptParamsFor(tsEnv, "release")) } +func TestRepo(t *testing.T) { + var tsEnv testScriptEnv + if err := tsEnv.fromEnv(); err != nil { + t.Fatal(err) + } + testscript.Run(t, testScriptParamsFor(tsEnv, "repo")) +} + func testScriptParamsFor(tsEnv testScriptEnv, command string) testscript.Params { var files []string if tsEnv.script != "" { diff --git a/acceptance/testdata/repo/repo-archive-unarchive.txtar b/acceptance/testdata/repo/repo-archive-unarchive.txtar new file mode 100644 index 000000000..33ff519f3 --- /dev/null +++ b/acceptance/testdata/repo/repo-archive-unarchive.txtar @@ -0,0 +1,23 @@ +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Check that the repo exists and isn't archived +exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json=isArchived --jq='.isArchived' +stdout 'false' + +# Archive the repo +exec gh repo archive $ORG/$SCRIPT_NAME-$RANDOM_STRING --yes + +# Check that the repo is archived +exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json=isArchived --jq='.isArchived' +stdout 'true' + +# Unarchive the repo +exec gh repo unarchive $ORG/$SCRIPT_NAME-$RANDOM_STRING --yes + +# Check that the repo is unarchived +exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json=isArchived --jq='.isArchived' +stdout 'false' diff --git a/acceptance/testdata/repo/repo-clone.txtar b/acceptance/testdata/repo/repo-clone.txtar new file mode 100644 index 000000000..b90a0894b --- /dev/null +++ b/acceptance/testdata/repo/repo-clone.txtar @@ -0,0 +1,11 @@ +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Ensure the repo was cloned +exists $SCRIPT_NAME-$RANDOM_STRING/README.md diff --git a/acceptance/testdata/repo/repo-create-view.txtar b/acceptance/testdata/repo/repo-create-view.txtar new file mode 100644 index 000000000..9774def35 --- /dev/null +++ b/acceptance/testdata/repo/repo-create-view.txtar @@ -0,0 +1,9 @@ +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Check that the repo exists +exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json=name --jq='.name' +stdout $SCRIPT_NAME-$RANDOM_STRING diff --git a/acceptance/testdata/repo/repo-delete.txtar b/acceptance/testdata/repo/repo-delete.txtar new file mode 100644 index 000000000..b82388068 --- /dev/null +++ b/acceptance/testdata/repo/repo-delete.txtar @@ -0,0 +1,13 @@ +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Check that the repo exists +exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json name --jq '.name' +stdout $SCRIPT_NAME-$RANDOM_STRING + +# Delete the repo +exec gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Ensure that the repo was deleted +! exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING +stderr 'Could not resolve to a Repository with the name' diff --git a/acceptance/testdata/repo/repo-deploy-key.txtar b/acceptance/testdata/repo/repo-deploy-key.txtar new file mode 100644 index 000000000..d93d07ee5 --- /dev/null +++ b/acceptance/testdata/repo/repo-deploy-key.txtar @@ -0,0 +1,31 @@ +# Create and clone a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private --clone + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# cd to the repo and list the deploy keys. There should be no keys +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh repo deploy-key list --json=title +! stdout title + +# Add a deploy key +exec gh repo deploy-key add ../deployKey.pub + +# Ensure the deploy key was added +exec gh repo deploy-key list --json=title --jq='.[].title' +stdout myTitle + +# Get the deploy key id +exec gh repo deploy-key list --json=title,id --jq='.[].title="myTitle" | .[].id' +stdout2env DEPLOY_KEY_ID + +# Delete the deploy key +exec gh repo deploy-key delete $DEPLOY_KEY_ID + +# Ensure the deploy key was deleted +exec gh repo deploy-key list --json=id --jq='.[].id' +! stdout $DEPLOY_KEY_ID + +-- deployKey.pub -- +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAZmdeRNskfpvYL5YHB/YJaW8hTEXpnvPMkx5Ri+YwUr myTitle diff --git a/acceptance/testdata/repo/repo-edit.txtar b/acceptance/testdata/repo/repo-edit.txtar new file mode 100644 index 000000000..00d3cdd2c --- /dev/null +++ b/acceptance/testdata/repo/repo-edit.txtar @@ -0,0 +1,16 @@ +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Check that the repo description is empty +exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json description --jq '.description' +! stdout '.' + +# Edit the repo description +exec gh repo edit $ORG/$SCRIPT_NAME-$RANDOM_STRING --description 'newDescription' + +# Check that the repo description is updated +exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING --json description --jq '.description' +stdout 'newDescription' diff --git a/acceptance/testdata/repo/repo-fork-sync.txtar b/acceptance/testdata/repo/repo-fork-sync.txtar new file mode 100644 index 000000000..6ed7b94e1 --- /dev/null +++ b/acceptance/testdata/repo/repo-fork-sync.txtar @@ -0,0 +1,42 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create and clone a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private --clone + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Fork and clone the repo +exec gh repo fork $ORG/$SCRIPT_NAME-$RANDOM_STRING --org $ORG --fork-name $SCRIPT_NAME-$RANDOM_STRING-fork --clone + +# Defer fork cleanup +defer gh repo delete $ORG/$SCRIPT_NAME-$RANDOM_STRING-fork --yes + +# Sleep so that the BE has time to sync +sleep 5 + +# Check that the repo was forked +exec gh repo view $ORG/$SCRIPT_NAME-$RANDOM_STRING-fork --json='isFork' --jq='.isFork' +stdout 'true' + +# Modify original repo +cd $SCRIPT_NAME-$RANDOM_STRING +mv ../asset.txt asset.txt +exec git add . +exec git commit -m 'Add asset.txt' +exec git push + +# Checkout the forked repo and ensure asset.txt is not present +cd ../$SCRIPT_NAME-$RANDOM_STRING-fork +exec git checkout main +! exists asset.txt + +# Sync the forked repo with the original repo +exec gh repo sync + +# Check that asset.txt now exists in the fork +exists asset.txt + +-- asset.txt -- +Hello, world! diff --git a/acceptance/testdata/repo/repo-list-rename.txtar b/acceptance/testdata/repo/repo-list-rename.txtar new file mode 100644 index 000000000..7f3ff1281 --- /dev/null +++ b/acceptance/testdata/repo/repo-list-rename.txtar @@ -0,0 +1,16 @@ +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# List the repos and check for the new repo +exec gh repo list $ORG --json=name --jq='.[].name' +stdout $SCRIPT_NAME-$RANDOM_STRING + +# Rename the repo +exec gh repo rename $SCRIPT_NAME-$RANDOM_STRING-renamed --repo=$ORG/$SCRIPT_NAME-$RANDOM_STRING --yes + +# Defer repo deletion +defer gh repo delete $ORG/$SCRIPT_NAME-$RANDOM_STRING-renamed --yes + +# List the repos and check for the renamed repo +exec gh repo list $ORG --json=name --jq='.[].name' +stdout $SCRIPT_NAME-$RANDOM_STRING-renamed diff --git a/acceptance/testdata/repo/repo-set-default.txtar b/acceptance/testdata/repo/repo-set-default.txtar new file mode 100644 index 000000000..4f7fa3273 --- /dev/null +++ b/acceptance/testdata/repo/repo-set-default.txtar @@ -0,0 +1,17 @@ +# Create and clone a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private --clone + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Ensure that no default is set +cd $SCRIPT_NAME-$RANDOM_STRING +exec gh repo set-default --view +stderr 'no default repository has been set; use `gh repo set-default` to select one' + +# Set the default +exec gh repo set-default $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Check that the default is set +exec gh repo set-default --view +stdout $ORG/$SCRIPT_NAME-$RANDOM_STRING