diff --git a/create-a-deployment.sh b/create-a-deployment.sh index 37b4ab21..52b40fd8 100755 --- a/create-a-deployment.sh +++ b/create-a-deployment.sh @@ -3,9 +3,16 @@ # https://docs.github.com/en/enterprise-cloud@latest/rest/deployments/deployments?apiVersion=2022-11-28#create-a-deployment # POST /repos/{owner}/{repo}/deployments -ref=$1 +# If the script is passed an argument $1 use that as the name +if [ -z "$1" ] + then + ref=${branch_name} + else + ref=$1 +fi -json_file=tmp/deployment.json + +json_file=tmp/create-a-deployment.json jq -n \ --arg ref "${ref}" \ --arg environment "${default_environment_name}" \ diff --git a/create-a-review-comment-for-a-pull-request.sh b/create-a-review-comment-for-a-pull-request.sh index 55b08bd6..27c39fdd 100755 --- a/create-a-review-comment-for-a-pull-request.sh +++ b/create-a-review-comment-for-a-pull-request.sh @@ -1,6 +1,6 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/pulls#create-a-review-comment-for-a-pull-request +# https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request # POST /repos/{owner}/{repo}/pulls/{pull_number}/comments @@ -12,19 +12,18 @@ if [ -z "$1" ] pull_number=$1 fi -json_file=tmp/create-a-review-comment-for-a-pull-request.json - # Beware. We are extracting the first commit in the pull request here. # you may wan to do something else: commit_id=$(./list-commits-on-a-pull-request.sh | jq -r '.[0].sha') -pull_request_review_body_comment="Great Stuff" +pull_request_review_body_comment="The Power pull request review body comment Stuff" path="docs/new-file-for-pull-request-txt" start_line=1 start_side=RIGHT line=2 side=RIGHT +json_file=tmp/create-a-review-comment-for-a-pull-request.json jq -n \ --arg body "${pull_request_review_body_comment}" \ --arg commit_id "$commit_id" \ @@ -43,9 +42,8 @@ jq -n \ GITHUB_TOKEN=${pr_approver_token} curl -v ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}/comments --data @${json_file} - - + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}/comments --data @${json_file}" diff --git a/create-a-review-for-a-pull-request.sh b/create-a-review-for-a-pull-request.sh index e6dd17fe..0beb66fa 100755 --- a/create-a-review-for-a-pull-request.sh +++ b/create-a-review-for-a-pull-request.sh @@ -1,6 +1,6 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request +# https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request # POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews # If the script is passed an argument $1 use that as the pull number @@ -13,11 +13,11 @@ fi event=${default_pr_event} -body="create-a-review-for-a-pull-request.sh ${event} Review for a pull request @${org}/${team_slug}. Demonstrates [create a review for a pull request](https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request)" +body="create-a-review-for-a-pull-request.sh ${event} Review for a pull request @${org}/${team_slug}. Demonstrates [create a review for a pull request](https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-requestt)" -json_file="tmp/create-a-review-for-a-pull-request.json" +json_file="tmp/create-a-review-for-a-pull-request.json" jq -n \ --arg event "$event" \ --arg body "$body" \ @@ -35,6 +35,7 @@ fi curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}/reviews" --data @${json_file} diff --git a/create-approving-review-for-a-pull-request.sh b/create-approving-review-for-a-pull-request.sh index 4c6f2a39..da37fcde 100755 --- a/create-approving-review-for-a-pull-request.sh +++ b/create-approving-review-for-a-pull-request.sh @@ -1,6 +1,6 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/pulls#create-a-review-for-a-pull-request +# https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request # POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews @@ -21,6 +21,7 @@ jq -n \ GITHUB_TOKEN=${pr_approver_token} curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}/reviews --data @${json_file} + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}/reviews" --data @${json_file} diff --git a/get-a-branch.sh b/get-a-branch.sh index 0e434e68..1180ffca 100755 --- a/get-a-branch.sh +++ b/get-a-branch.sh @@ -1,9 +1,9 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/repos#get-a-branch +# https://docs.github.com/en/enterprise-cloud@latest/rest/branches/branches?apiVersion=2022-11-28 # GET /repos/{owner}/{repo}/branches/{branch} -# If the script is passed an argument $1 use that as the name + if [ -z "$1" ] then branch=${base_branch} @@ -13,8 +13,8 @@ fi curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch} - + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${branch}" diff --git a/get-a-check-run.sh b/get-a-check-run.sh index 4d11a29a..194f06ff 100755 --- a/get-a-check-run.sh +++ b/get-a-check-run.sh @@ -1,10 +1,11 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/checks/runs#get-a-check-run +# https://docs.github.com/en/enterprise-cloud@latest/rest/checks/runs?apiVersion=2022-11-28#get-a-check-run # GET /repos/{owner}/{repo}/check-runs/{check_run_id} # Check run id's can be seen at: # https://github.com/{owner}/{repo}/pull/2/checks + if [ -z "$1" ] then check_run_id=$(./list-check-runs-for-a-git-reference.sh $target_branch | jq -r '.check_runs | last | .id') @@ -16,3 +17,4 @@ curl ${curl_custom_flags} \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/check-runs/${check_run_id}" + diff --git a/get-a-code-scanning-analysis-for-a-repository.sh b/get-a-code-scanning-analysis-for-a-repository.sh index 395ef3e0..d7ac7b79 100755 --- a/get-a-code-scanning-analysis-for-a-repository.sh +++ b/get-a-code-scanning-analysis-for-a-repository.sh @@ -3,6 +3,7 @@ # https://docs.github.com/en/rest/code-scanning#get-a-code-scanning-analysis-for-a-repository # GET /repos/{owner}/{repo}/code-scanning/analyses/{analysis_id} + # If the script is passed an argument $1 use that as the name if [ -z "$1" ] then @@ -11,8 +12,10 @@ if [ -z "$1" ] analysis_id=$1 fi -set -x + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/code-scanning/analyses/${analysis_id} + "${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/code-scanning/analyses/${analysis_id}" + diff --git a/get-a-code-scanning-default-setup-configuration.sh b/get-a-code-scanning-default-setup-configuration.sh index 270bd6c4..f8aaa297 100755 --- a/get-a-code-scanning-default-setup-configuration.sh +++ b/get-a-code-scanning-default-setup-configuration.sh @@ -1,13 +1,13 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/code-scanning/code-scanning?apiVersion=2022-11-28#get-a-code-scanning-default-setup-configuration +# https://docs.github.com/en/enterprise-cloud@latest/rest/code-scanning/code-scanning?apiVersion=2022-11-28#get-a-code-scanning-default-setup-configuration # GET /repos/{owner}/{repo}/code-scanning/default-setup # If the script is passed an argument $1 use that as the name if [ -z "$1" ] then - repo=$repo + repo=${repo} else repo=$1 fi diff --git a/get-a-code-security-configuration.sh b/get-a-code-security-configuration.sh index 93381e0d..7c4e6847 100755 --- a/get-a-code-security-configuration.sh +++ b/get-a-code-security-configuration.sh @@ -4,10 +4,9 @@ # GET /orgs/{org}/code-security/configurations/{configuration_id} -# If the script is passed an argument $1 use that as the name if [ -z "$1" ] then - org=$org + org=${org} else org=$1 fi @@ -21,3 +20,4 @@ curl ${curl_custom_flags} \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ "${GITHUB_API_BASE_URL}/orgs/${org}/code-security/configurations/${configuration_id}" + diff --git a/get-a-codeql-database-for-a-repository.sh b/get-a-codeql-database-for-a-repository.sh index e6235592..bcbd3ce5 100755 --- a/get-a-codeql-database-for-a-repository.sh +++ b/get-a-codeql-database-for-a-repository.sh @@ -1,6 +1,6 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/code-scanning#get-a-codeql-database-for-a-repository +# https://docs.github.com/en/enterprise-cloud@latest/rest/code-scanning/code-scanning?apiVersion=2022-11-28#get-a-codeql-database-for-a-repository # GET /repos/{owner}/{repo}/code-scanning/codeql/databases/{language} @@ -16,4 +16,5 @@ fi curl ${curl_custom_flags} \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/code-scanning/codeql/databases/${language} + "${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/code-scanning/codeql/databases/${language}" + diff --git a/get-a-codespaces-for-authenticated-user.sh b/get-a-codespaces-for-authenticated-user.sh index c2a75802..a53c9a56 100755 --- a/get-a-codespaces-for-authenticated-user.sh +++ b/get-a-codespaces-for-authenticated-user.sh @@ -1,9 +1,9 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/codespaces/codespaces#get-a-codespace-for-the-authenticated-user +# https://docs.github.com/en/enterprise-cloud@latest/rest/codespaces/codespaces?apiVersion=2022-11-28#get-a-codespace-for-the-authenticated-user # GET /user/codespaces/{codespace_name} -# If the script is passed an argument $1 use that as the codespace name + if [ -z "$1" ] then codespace_name=$(./list-codespaces-for-authenticated-user.sh | jq '.codespaces[0].name') @@ -11,7 +11,10 @@ if [ -z "$1" ] codespace_name=$1 fi + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/user/codespaces/${codespace_name} + "${GITHUB_API_BASE_URL}/user/codespaces/${codespace_name}" + diff --git a/get-a-commit.sh b/get-a-commit.sh index 6c46f10f..4b6b74fa 100755 --- a/get-a-commit.sh +++ b/get-a-commit.sh @@ -1,6 +1,6 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#get-a-commit +# https://docs.github.com/en/enterprise-cloud@latest/rest/commits/commits?apiVersion=2022-11-28#get-a-commit # GET /repos/{owner}/{repo}/commits/{ref} ref=$1 diff --git a/get-a-delivery-for-a-repository-webhook.sh b/get-a-delivery-for-a-repository-webhook.sh index 5b8c2ba0..21e90c77 100755 --- a/get-a-delivery-for-a-repository-webhook.sh +++ b/get-a-delivery-for-a-repository-webhook.sh @@ -1,21 +1,24 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/repos#get-a-delivery-for-a-repository-webhook +# https://docs.github.com/en/enterprise-cloud@latest/rest/repos/webhooks?apiVersion=2022-11-28#get-a-delivery-for-a-repository-webhook # GET /repos/{owner}/{repo}/hooks/{hook_id}/deliveries/{delivery_id} + # If the script is passed an argument $1 use that as the hook_id if [ -z "$1" ] then # we get the first delivery_id the list repo here: hook_id=$(./list-repo-webhooks.sh | jq -r '.[0] .id') - echo "hook_id: $hook_id" delivery_id=$(./list-deliveries-for-repository-webhook.sh | jq -r '.[0] .id') else hook_id=$1 delivery_id=$2 fi + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/hooks/${hook_id}/deliveries/${delivery_id} + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/hooks/${hook_id}/deliveries/${delivery_id}" + diff --git a/get-a-delivery-for-a-webhook.sh b/get-a-delivery-for-a-webhook.sh index 5b8c2ba0..28ecce4c 100755 --- a/get-a-delivery-for-a-webhook.sh +++ b/get-a-delivery-for-a-webhook.sh @@ -1,8 +1,9 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/repos#get-a-delivery-for-a-repository-webhook +# https://docs.github.com/en/enterprise-cloud@latest/rest/repos/webhooks?apiVersion=2022-11-28#get-a-delivery-for-a-repository-webhook # GET /repos/{owner}/{repo}/hooks/{hook_id}/deliveries/{delivery_id} + # If the script is passed an argument $1 use that as the hook_id if [ -z "$1" ] then @@ -16,6 +17,8 @@ if [ -z "$1" ] fi curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/hooks/${hook_id}/deliveries/${delivery_id} + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/hooks/${hook_id}/deliveries/${delivery_id}" + diff --git a/get-a-deployment.sh b/get-a-deployment.sh index 3ca49951..57a391a3 100755 --- a/get-a-deployment.sh +++ b/get-a-deployment.sh @@ -1,8 +1,9 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/repos#get-a-deployment +# https://docs.github.com/en/enterprise-cloud@latest/rest/deployments/deployments?apiVersion=2022-11-28#get-a-deployment # GET /repos/{owner}/{repo}/deployments/{deployment_id} + if [ -z "$1" ] then deployment_id=${default_deployment_id} @@ -11,6 +12,8 @@ if [ -z "$1" ] fi curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/deployments/${deployment_id} + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/deployments/${deployment_id}" + diff --git a/get-a-diff-of-the-dependencies-between-commits.sh b/get-a-diff-of-the-dependencies-between-commits.sh index f3a0c0a8..8704a1cb 100755 --- a/get-a-diff-of-the-dependencies-between-commits.sh +++ b/get-a-diff-of-the-dependencies-between-commits.sh @@ -1,6 +1,6 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/dependency-graph/dependency-review?apiVersion=2022-11-28#get-a-diff-of-the-dependencies-between-commits +# https://docs.github.com/en/enterprise-cloud@latest/rest/dependency-graph/dependency-review?apiVersion=2022-11-28#get-a-diff-of-the-dependencies-between-commits # GET /repos/{owner}/{repo}/dependency-graph/compare/{basehead} @@ -21,4 +21,3 @@ curl ${curl_custom_flags} \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ "${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/dependency-graph/compare/${basehead}" - diff --git a/get-notifications.sh b/get-notifications.sh deleted file mode 100755 index 8931bc53..00000000 --- a/get-notifications.sh +++ /dev/null @@ -1,9 +0,0 @@ -. ./.gh-api-examples.conf - -# https://docs.github.com/en/rest/reference/activity#notifications -# GET /users/{username}/received_events - -curl ${curl_custom_flags} \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/users/${U}/received_events diff --git a/get-release-tarball.sh b/get-release-tarball.sh index f5b42607..74b57dc0 100755 --- a/get-release-tarball.sh +++ b/get-release-tarball.sh @@ -1,7 +1,8 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/repos#get-a-release-asset -# GET /repos/:owner/:repo/releases/assets/:asset_id +# https://docs.github.com/en/enterprise-cloud@latest/rest/releases/assets?apiVersion=2022-11-28#get-a-release-asset +# GET /repos/{owner}/{repo}/releases/assets/{asset_id} + release_tarball_name=$(./list-releases.sh | jq -r '.[] | .tarball_url') @@ -11,4 +12,5 @@ curl ${curl_custom_flags} \ -L \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${release_tarball_name} --output ${output_file} + "${release_tarball_name}" --output ${output_file} + diff --git a/get-repository-clones.sh b/get-repository-clones.sh index 19739f58..abfb43b2 100755 --- a/get-repository-clones.sh +++ b/get-repository-clones.sh @@ -1,9 +1,12 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/repos#get-repository-clones +# https://docs.github.com/en/enterprise-cloud@latest/rest/metrics/traffic?apiVersion=2022-11-28#get-repository-clones # GET /repos/{owner}/{repo}/traffic/clones + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/traffic/clones + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/traffic/clones" + diff --git a/get-repository-page-views.sh b/get-repository-page-views.sh index 9c02f49c..60be2f01 100755 --- a/get-repository-page-views.sh +++ b/get-repository-page-views.sh @@ -1,9 +1,12 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/repos#get-page-views +# https://docs.github.com/en/enterprise-cloud@latest/rest/metrics/traffic?apiVersion=2022-11-28#get-page-views # GET /repos/{owner}/{repo}/traffic/views + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/traffic/views + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/traffic/views" + diff --git a/get-repository-referral-paths.sh b/get-repository-referral-paths.sh index 76d4a92d..e2367372 100755 --- a/get-repository-referral-paths.sh +++ b/get-repository-referral-paths.sh @@ -1,9 +1,11 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/repos#get-top-referral-paths +# https://docs.github.com/en/enterprise-cloud@latest/rest/metrics/traffic?apiVersion=2022-11-28#get-top-referral-paths # GET /repos/{owner}/{repo}/traffic/popular/paths + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/traffic/popular/paths + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/traffic/popular/paths" diff --git a/get-repository-referral-sources.sh b/get-repository-referral-sources.sh index 60be8382..892c1fbc 100755 --- a/get-repository-referral-sources.sh +++ b/get-repository-referral-sources.sh @@ -1,9 +1,11 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/repos#get-top-referral-sources +# https://docs.github.com/en/enterprise-cloud@latest/rest/metrics/traffic?apiVersion=2022-11-28#get-top-referral-sources # GET /repos/{owner}/{repo}/traffic/popular/referrers curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/traffic/popular/referrers + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/traffic/popular/referrers" + diff --git a/get-team-by-name.sh b/get-team-by-name.sh index 8904ed66..c17f5e90 100755 --- a/get-team-by-name.sh +++ b/get-team-by-name.sh @@ -1,9 +1,20 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/teams#get-a-team-by-name -# GET /orgs/:org/teams/:team_slug +# https://docs.github.com/en/enterprise-cloud@latest/rest/teams/teams?apiVersion=2022-11-28#get-a-team-by-name +# GET /orgs/{org}/teams/{team_slug} + + +if [ -z "$1" ] + then + team_slug=$team_slug + else + team_slug=$1 +fi + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/orgs/${org}/teams/${team_slug} + "${GITHUB_API_BASE_URL}/orgs/${org}/teams/${team_slug}" + diff --git a/list-a-reference.sh b/list-a-reference.sh index a963319b..2b6ca53c 100755 --- a/list-a-reference.sh +++ b/list-a-reference.sh @@ -1,10 +1,9 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/git#get-a-reference +# https://docs.github.com/en/enterprise-cloud@latest/rest/git/refs?apiVersion=2022-11-28#get-a-reference # GET /repos/{owner}/{repo}/git/ref/{ref} -# If the script is passed an argument $1 use that as the ref if [ -z "$1" ] then ref="heads/$base_branch" @@ -12,7 +11,10 @@ if [ -z "$1" ] ref="heads/$1" fi + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/ref/${ref} + ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/ref/${ref}" + diff --git a/list-all-auto-links-of-a-repository.sh b/list-all-auto-links-of-a-repository.sh index 0d006914..29817958 100755 --- a/list-all-auto-links-of-a-repository.sh +++ b/list-all-auto-links-of-a-repository.sh @@ -4,6 +4,8 @@ # GET /repos/{owner}/{repo}/autolinks curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/autolinks" + diff --git a/list-events-received-by-the-authenticated-user.sh b/list-events-received-by-the-authenticated-user.sh new file mode 100755 index 00000000..ea181e62 --- /dev/null +++ b/list-events-received-by-the-authenticated-user.sh @@ -0,0 +1,11 @@ +. ./.gh-api-examples.conf + +# https://docs.github.com/en/enterprise-cloud@latest/rest/activity/events?apiVersion=2022-11-28#list-events-received-by-the-authenticated-user +# GET /users/{username}/received_events + +curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + "${GITHUB_API_BASE_URL}/users/${username}/received_events" + diff --git a/list-pull-request-files.sh b/list-pull-request-files.sh index 44df3d3c..20285322 100755 --- a/list-pull-request-files.sh +++ b/list-pull-request-files.sh @@ -1,11 +1,20 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/pulls#list-pull-requests-files -# GET /repos/:owner/:repo/pulls/:pull_number/files +# https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/pulls?apiVersion=2022-11-28#list-pull-requests-files +# GET /repos/{owner}/{repo}/pulls/{pull_number}/files + + +if [ -z "$1" ] + then + pull_number=${default_pull_request_id} + else + pull_number=$1 +fi -pull_number=${1:-2} curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}/files" + diff --git a/list-pull-request-review.sh b/list-pull-request-review.sh index 1ef5f996..bfe9cc31 100755 --- a/list-pull-request-review.sh +++ b/list-pull-request-review.sh @@ -1,12 +1,14 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/pulls#get-a-review-for-a-pull-request -# GET /repos/:owner/:repo/pulls/:pull_number/reviews/:review_id +# https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/reviews?apiVersion=2022-11-28#get-a-review-for-a-pull-request +# GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id} -pull=2 +pull=${default_request_id} review_id=$1 curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull}/reviews/${review_id}" + diff --git a/list-repository-collaborators.sh b/list-repository-collaborators.sh index 8930bd0a..f8ad7011 100755 --- a/list-repository-collaborators.sh +++ b/list-repository-collaborators.sh @@ -1,13 +1,21 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/collaborators#list-repository-collaborators +# https://docs.github.com/en/enterprise-cloud@latest/rest/collaborators/collaborators?apiVersion=2022-11-28 # GET /repos/{owner}/{repo}/collaborators -#affiliation="all" -#affiliation="direct" -affiliation="outside" + +if [ -z "$1" ] + then + affiliation="outside" + #affiliation="all" + #affiliation="direct" + else + affiliation=$1 +fi + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/collaborators?affiliation=${affiliation}" diff --git a/list-repository-events.sh b/list-repository-events.sh index 5f67accf..1dcb5118 100755 --- a/list-repository-events.sh +++ b/list-repository-events.sh @@ -1,10 +1,11 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/activity#list-repository-events +# https://docs.github.com/en/enterprise-cloud@latest/rest/activity/events?apiVersion=2022-11-28#list-repository-events # GET /repos/{owner}/{repo}/events curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/events + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/events" diff --git a/list-user-gists.sh b/list-user-gists.sh index 90682c82..f7a0355f 100755 --- a/list-user-gists.sh +++ b/list-user-gists.sh @@ -1,7 +1,8 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/gists#list-gists-for-a-user -# GET /users/:username/gists +# https://docs.github.com/en/enterprise-cloud@latest/rest/gists/gists?apiVersion=2022-11-28#list-gists-for-a-user +# GET /users/{username}/gists + if [ -z "$1" ] then @@ -10,7 +11,10 @@ if [ -z "$1" ] username=$1 fi + curl ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/users/${username}/gists + "${GITHUB_API_BASE_URL}/users/${username}/gists" + diff --git a/pull-request-branch-change.sh b/pull-request-branch-change.sh index 1d41056f..25ad0713 100755 --- a/pull-request-branch-change.sh +++ b/pull-request-branch-change.sh @@ -1,7 +1,7 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/pulls#update-a-pull-request -# PATCH /repos/:owner/:repo/pulls/:pull_number +# https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request +# PATCH /repos/{owner}/{repo}/pulls/{pull_number} echo echo "Enter pull request number (or numbers) to change" @@ -16,6 +16,6 @@ do -X PATCH \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_request} \ + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_request}" \ --data '{ "base": "main" }' done diff --git a/pull-request-close.sh b/pull-request-close.sh index 7383cdc2..9a4c83ee 100755 --- a/pull-request-close.sh +++ b/pull-request-close.sh @@ -1,13 +1,31 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/pulls#update-a-pull-request -# PATCH /repos/:owner/:repo/pulls/:pull_number +# https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request +# PATCH /repos/{owner}/{repo}/pulls/{pull_number} + + +# If the script is passed an argument $1 use that as the name +if [ -z "$1" ] + then + pull_number=${default_pull_request_id} + else + pull_nmber=$1 +fi + +state="closed" + +json_file=tmp/update-a-pull-request.json +jq -n \ + --arg state "${state}" \ + '{ + state: $state, + }' > ${json_file} -pull_number=2 curl ${curl_custom_flags} \ -X PATCH \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number} \ - --data '{ "state": "closed" }' + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}" --data @${json_file} + diff --git a/pull-request-reopen.sh b/pull-request-reopen.sh index 247219f5..400a0a1f 100755 --- a/pull-request-reopen.sh +++ b/pull-request-reopen.sh @@ -1,13 +1,29 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/pulls#update-a-pull-request -# PATCH /repos/:owner/:repo/pulls/:pull_number +# https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request +# PATCH /repos/{owner}/{repo}/pulls/{pull_number} + + +if [ -z "$1" ] + then + pull_number=${default_pull_request_id} + else + pull_number=$1 +fi + +state=open + +json_file=tmp/update-a-pull-request.json +jq -n \ + --arg state "${state}" \ + '{ + state: $state, + }' > ${json_file} -pull_number=2 curl ${curl_custom_flags} \ -X PATCH \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number} \ - --data '{ "state": "open" }' + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}" --data @${json_file} + diff --git a/remove-an-organization-member.sh b/remove-an-organization-member.sh index 65f628f9..cd7c39f1 100755 --- a/remove-an-organization-member.sh +++ b/remove-an-organization-member.sh @@ -1,6 +1,6 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/orgs#remove-an-organization-member +# https://docs.github.com/en/enterprise-cloud@latest/rest/orgs/members?apiVersion=2022-11-28#remove-an-organization-member # DELETE /orgs/{org}/members/{username} if [ -z "$1" ] @@ -13,6 +13,9 @@ fi curl ${curl_custom_flags} \ -X DELETE \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/orgs/${org}/member/${username} + "${GITHUB_API_BASE_URL}/orgs/${org}/member/${username}" + + diff --git a/request-reviewers-for-a-pull-request.sh b/request-reviewers-for-a-pull-request.sh index fca96183..754e3173 100755 --- a/request-reviewers-for-a-pull-request.sh +++ b/request-reviewers-for-a-pull-request.sh @@ -1,9 +1,9 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/pulls/review-requests#request-reviewers-for-a-pull-request +# https://docs.github.com/en/enterprise-cloud@latest/rest/pulls/review-requests?apiVersion=2022-11-28#request-reviewers-for-a-pull-request # POST /repos/{owner}/{repo}/pulls/{pull_number}/requested_reviewers -# If the script is passed an argument $1 use that as the name + if [ -z "$1" ] then repo=$repo @@ -15,17 +15,17 @@ reviewer=${default_committer} pull_number=${default_pull_request_id} json_file=tmp/request-reviewers-for-a-pull-request.json - jq -n \ --arg reviewer "${reviewer}" \ '{ reviewers : [ $reviewer ] }' > ${json_file} -set -x + curl -v ${curl_custom_flags} \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}/requested_reviewers --data @${json_file} + "${GITHUB_API_BASE_URL}/repos/${org}/${repo}/pulls/${pull_number}/requested_reviewers" --data @${json_file} diff --git a/search-api-code.sh b/search-api-code.sh index df930ce3..62f30ac3 100755 --- a/search-api-code.sh +++ b/search-api-code.sh @@ -1,8 +1,9 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/search#search-code +# https://docs.github.com/en/enterprise-cloud@latest/rest/search/search?apiVersion=2022-11-28#search-code # GET /search/code + search_string="addClass" language="js" @@ -13,7 +14,6 @@ repo="jquery" search_query="${search_string}+in:file+language:${language}+repo:${org}/${repo}" -set -x curl ${curl_custom_flags} \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ diff --git a/search-api-issues-pull-requests.sh b/search-api-issues-pull-requests.sh index 6928db2b..3a93d9f1 100755 --- a/search-api-issues-pull-requests.sh +++ b/search-api-issues-pull-requests.sh @@ -1,6 +1,6 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/reference/search#search-issues-and-pull-requests +# https://docs.github.com/en/enterprise-cloud@latest/rest/search/search?apiVersion=2022-11-28#search-issues-and-pull-requests # GET /search/issues @@ -14,7 +14,6 @@ repo="jquery" search_query="${search_string}+in:file+language:${language}+repo:${org}/${repo}" -set -x curl ${curl_custom_flags} \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ diff --git a/update-a-reference.sh b/update-a-reference.sh index 925545d3..95329b70 100755 --- a/update-a-reference.sh +++ b/update-a-reference.sh @@ -10,12 +10,13 @@ if [ -z "$1" ] sha=$1 fi -json_file=tmp/update-a-reference.json +json_file=tmp/update-a-reference.json jq -n \ --arg sha "${sha}" \ '{ sha: $sha }' > ${json_file} + curl ${curl_custom_flags} \ -X PATCH \ -H "Accept: application/vnd.github.v3+json" \ diff --git a/update-ldap-mapping-for-a-team.sh b/update-ldap-mapping-for-a-team.sh index f824b5c6..9f8316c8 100755 --- a/update-ldap-mapping-for-a-team.sh +++ b/update-ldap-mapping-for-a-team.sh @@ -1,18 +1,19 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/enterprise-server@3.6/rest/enterprise-admin/ldap#update-ldap-mapping-for-a-team +# https://docs.github.com/en/enterprise-server/rest/enterprise-admin/ldap?apiVersion=2022-11-28#update-ldap-mapping-for-a-team # PATCH /admin/ldap/teams/{team_id}/mapping -team_id=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/orgs/${org}/teams/$team_slug | jq '.id') -json_file=tmp/update-ldap-mapping-for-a-team.json +team_id=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/orgs/${org}/teams/${team_slug} | jq '.id') +json_file=tmp/update-ldap-mapping-for-a-team.json jq -n \ --arg ldap_dn "${ldap_dn}" \ '{ ldap_dn : $ldap_dn, }' > ${json_file} + curl ${curl_custom_flags} \ -X PATCH \ -H "X-GitHub-Api-Version: ${github_api_version}" \ diff --git a/update-repository-preferences-for-check-suites.sh b/update-repository-preferences-for-check-suites.sh index fa743f84..70a50457 100755 --- a/update-repository-preferences-for-check-suites.sh +++ b/update-repository-preferences-for-check-suites.sh @@ -3,10 +3,10 @@ # https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#update-repository-preferences-for-check-suites # PATCH /repos/{owner}/{repo}/check-suites/preferences -json_file=tmp/skeleton.json auto_trigger_checks=false +json_file=tmp/update-repository-preferences-for-check-suites.json jq -n \ --arg auto_trigger_checks "${auto_trigger_checks}" \ --argjson app_id "${default_app_id}" \ @@ -14,10 +14,11 @@ jq -n \ auto_trigger_checks : [ {app_id: $app_id, "setting": $auto_trigger_checks | test("true")}] }' > ${json_file} + curl ${curl_custom_flags} \ -X PATCH \ -H "X-GitHub-Api-Version: ${github_api_version}" \ -H "Accept: application/vnd.github.v3+json" \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/check-suites/preferences --data @${json_file} + "${GITHUB_API_BASE_URL}/repos/${owner}/${repo}/check-suites/preferences" --data @${json_file} diff --git a/update-username.sh b/update-username.sh index 89491c90..e3634038 100755 --- a/update-username.sh +++ b/update-username.sh @@ -1,22 +1,23 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/enterprise-server/rest/reference/enterprise-admin#update-the-username-for-a-user -# PATCH /admin/users/:username +# https://docs.github.com/en/enterprise-server/rest/enterprise-admin/users?apiVersion=2022-11-28#update-the-username-for-a-user +# PATCH /admin/users/{username} -old_username=${1} -new_username=${2} -json=tmp/new_username.json +old_username=${1} +username=${2} -rm -f ${json} +json=tmp/update-the-username-for-a-user.json jq -n \ --arg new_username "${new_username}" \ '{ "login" : $new_username }' > ${json} -cat $json -set -x -curl -v -X PATCH \ +curl ${curl_custom_flags} \ +-X PATCH \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_API_BASE_URL}/admin/users/${old_username} --data @$json + -H "Accept: application/vnd.github.v3+json" \ + -H "X-GitHub-Api-Version: ${github_api_version}" \ + "${GITHUB_API_BASE_URL}/admin/users/${username} --data @$json" + diff --git a/upload-an-analysis-as-sarif-data.sh b/upload-an-analysis-as-sarif-data.sh index 39b23aca..8d2dae67 100755 --- a/upload-an-analysis-as-sarif-data.sh +++ b/upload-an-analysis-as-sarif-data.sh @@ -1,6 +1,6 @@ . ./.gh-api-examples.conf -# https://docs.github.com/en/rest/code-scanning#upload-an-analysis-as-sarif-data +# https://docs.github.com/en/enterprise-cloud@latest/rest/code-scanning/code-scanning?apiVersion=2022-11-28#upload-an-analysis-as-sarif-data # POST /repos/{owner}/{repo}/code-scanning/sarifs # Data sourced from: