Skip to content

Commit

Permalink
Merge pull request #276 from gm3dmo/fixyfixy
Browse files Browse the repository at this point in the history
Updating files with docs and removing rm command"
  • Loading branch information
gm3dmo authored Feb 8, 2025
2 parents ab1b762 + a8a3c68 commit fc36dac
Show file tree
Hide file tree
Showing 99 changed files with 346 additions and 511 deletions.
17 changes: 8 additions & 9 deletions archive-a-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@
# https://docs.github.com/en/rest/reference/repos#update-a-repository
# PATCH /repos/{owner}/{repo}

json_file=tmp/update-a-repo.json
datestamp=$(date +%s)
description="archived by an archiving script at timestamp: ${datestamp}"

rm -f ${json_file}

jq -n \
--arg description "${description}" \
--arg archived "true" \
'{
json_file=tmp/update-a-repo.json
jq -n \
--arg description "${description}" \
--arg archived "true" \
'{
description: $description,
archived: $archived
}' > ${json_file}
}' > ${json_file}


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} --data @${json_file}
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}" --data @${json_file}

rm -f ${json_file}
14 changes: 6 additions & 8 deletions create-a-commit-comment.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/repos#create-a-commit-comment
# https://docs.github.com/en/enterprise-cloud@latest/rest/commits/comments?apiVersion=2022-11-28#create-a-commit-comment
# POST /repos/{owner}/{repo}/commits/{commit_sha}/comments

commit_sha=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/ref/heads/${base_branch}| jq -r '.object.sha')

commit_sha=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/ref/heads/${base_branch}| jq -r '.object.sha')
lorem=$(cat test-data/lorem.txt)

json_file=tmp/create-a-commit-comment.json
rm -f ${json}

body="${lorem}"


json_file=tmp/create-a-commit-comment.json
jq -n \
--arg body "${body}" \
'{ body: $body
}' > ${json_file}


curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/commits/${commit_sha}/comments --data @${json_file}
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/commits/${commit_sha}/comments" --data @${json_file}

rm -f ${json_file}
12 changes: 6 additions & 6 deletions create-a-commit.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/git#create-a-commit
# POST /repos/:owner/:repo/git/commits
# https://docs.github.com/en/enterprise-cloud@latest/rest/git/commits?apiVersion=2022-11-28#create-a-commit
# POST /repos/{owner}/{repo}/git/commits


if [ -z "$1" ]
then
Expand All @@ -10,11 +11,10 @@ if [ -z "$1" ]
tree_sha=$1
fi

json_file=tmp/create-commit.json
rm -f ${json_file}

last_commit_sha=$(curl --silent -H "Authorization: Bearer ${GITHUB_TOKEN}" ${GITHUB_API_BASE_URL}/repos/${org}/${repo}/branches/${base_branch} | jq -r '.commit.sha')

json_file=tmp/create-commit.json
jq -n \
--arg name "${default_committer}" \
--arg message "test commit message ${RANDOM}" \
Expand All @@ -24,9 +24,9 @@ jq -n \
--arg last_commit_sha "${last_commit_sha}" \
'{message: $message, "author":{ "name" : $name, "email": $email , "date": $date}, "parents": [ $last_commit_sha ], "tree": $tree_sha }' > ${json_file}


curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/commits --data @${json_file}
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/git/commits" --data @${json_file}

rm -f ${json_file}
8 changes: 4 additions & 4 deletions create-a-deployment-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ if [ -z "$1" ]
deployment_id=$1
fi

json_file=tmp/deployment.json
rm -f ${json_file}

state="success"

json_file=tmp/deployment.json
jq -n \
--arg state "${state}" \
--arg target_url "http://example.com/target-url" \
Expand All @@ -29,7 +27,9 @@ jq -n \
environment: $environment
}' > ${json_file}


curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/deployments/${deployment_id}/statuses --data @${json_file}
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/deployments/${deployment_id}/statuses" --data @${json_file}

10 changes: 3 additions & 7 deletions create-a-deployment.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/repos#create-a-deployment
# 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

json_file=tmp/deployment.json
rm -f ${json_file}

jq -n \
--arg ref "${ref}" \
--arg environment "${default_environment_name}" \
Expand All @@ -16,11 +14,9 @@ jq -n \
environment: $environment
}' > ${json_file}

cat $json_file | jq -r



curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/deployments --data @${json_file}
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/deployments" --data @${json_file}

8 changes: 2 additions & 6 deletions create-a-repository-for-the-authenticated-user.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/repos/repos#create-a-repository-for-the-authenticated-user
# https://docs.github.com/en/enterprise-cloud@latest/rest/repos/repos?apiVersion=2022-11-28#create-a-repository-for-the-authenticated-user
# POST /user/repos


Expand All @@ -19,10 +19,7 @@ else
p="false"
fi


json_file=tmp/create-a-repository-for-the-authenticated-user.json
rm -f ${json_file}

jq -n \
--arg name "${repo}" \
--arg private $p \
Expand All @@ -34,9 +31,8 @@ jq -n \
}' > ${json_file}


set -x
curl ${curl_custom_flags} \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/user/repos --data @${json_file}
"${GITHUB_API_BASE_URL}/user/repos" --data @${json_file}

7 changes: 4 additions & 3 deletions create-a-self-hosted-runner-group-for-an-enterprise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# https://docs.github.com/rest/reference/actions#create-a-self-hosted-runner-group-for-an-enterprise
# POST /enterprises/{enterprise}/actions/runner-groups


allowed_actions="all"
allows_public_repositories="false"

json_file=tmp/create-a-self-hosted-runner-group-for-an-enterprise.json
rm -f ${json_file}

json_file=tmp/create-a-self-hosted-runner-group-for-an-enterprise.json
jq -n \
--arg name "${enterprise_shr_group_name}" \
--arg allowed_actions ${allowed_actions} \
Expand All @@ -23,4 +23,5 @@ curl ${curl_custom_flags} \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/enterprises/${enterprise}/actions/runner-groups --data @${json_file}
"${GITHUB_API_BASE_URL}/enterprises/${enterprise}/actions/runner-groups" --data @${json_file}

1 change: 0 additions & 1 deletion create-a-self-hosted-runner-group-for-an-organization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
name=${org_self_hosted_runner_group_name:-org_runner_group}

json_file=tmp/create-a-self-hosted-runner-group-for-an-organization.json

jq -n \
--arg name "${name}" \
'{
Expand Down
10 changes: 4 additions & 6 deletions create-an-environment-secret.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
# https://docs.github.com/en/rest/reference/actions#create-or-update-an-environment-secret
# PUT /repositories/{repository_id}/environments/{environment_name}/secrets/{secret_name}

json_file=tmp/environment-secret.json
rm -f ${json_file}

environment_name=${default_environment_name}
secret_name=${environment_secret_name}

key_id=$(./get-an-environment-public-key.sh | jq -r '.key_id')
environment_public_key=$(./get-an-environment-public-key.sh | jq -r '.key')

encrypted_value=$(ruby create-an-environment-secret-helper.rb ${environment_public_key})
repository_id=$(./list-repo.sh $repo | jq -r '.id')

json_file=tmp/environment-secret.json
jq -n \
--arg secret_name "${secret_name}" \
--arg key_id "${key_id}" \
Expand All @@ -24,10 +22,10 @@ jq -n \
encrypted_value: $encrypted_value
}' > ${json_file}

repository_id=$(./list-repo.sh $repo | jq -r '.id')

curl ${curl_custom_flags} \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repositories/${repository_id}/environments/${environment_name}/secrets/${secret_name} --data @${json_file}
"${GITHUB_API_BASE_URL}/repositories/${repository_id}/environments/${environment_name}/secrets/${secret_name}" --data @${json_file}

8 changes: 3 additions & 5 deletions create-an-organization-secret-for-app-private-key.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/actions#create-or-update-an-organization-secret
# https://docs.github.com/en/enterprise-cloud@latest/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
# PUT /orgs/{org}/actions/secrets/{secret_name}

json_file=tmp/organization-secret.json
rm -f ${json_file}

secret_name=${app_cert_secret_name}
visibility="all"
key_id=$(./get-an-organization-public-key.sh | jq -r '.key_id')
org_public_key=$(./get-an-organization-public-key.sh | jq -r '.key')
export private_pem_file
#echo $private_pem_file
encrypted_value=$(ruby create-an-organization-secret-for-app-private-key.rb ${org_public_key})

json_file=tmp/create-or-update-an-organization-secret.sh
jq -n \
--arg secret_name "${secret_name}" \
--arg key_id "${key_id}" \
Expand All @@ -26,6 +23,7 @@ jq -n \
encrypted_value: $encrypted_value
}' > ${json_file}


curl ${curl_custom_flags} \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
Expand Down
9 changes: 5 additions & 4 deletions create-an-organization-secret.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/actions#create-or-update-an-organization-secret
# https://docs.github.com/en/enterprise-cloud@latest/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
# PUT /orgs/{org}/actions/secrets/{secret_name}

json_file=tmp/organization-secret.json
rm -f ${json_file}

secret_name=${org_secret_name}
visibility="all"
key_id=$(./get-an-organization-public-key.sh | jq -r '.key_id')
org_public_key=$(./get-an-organization-public-key.sh | jq -r '.key')
encrypted_value=$(ruby create-an-organization-secret-helper.rb ${org_public_key})

json_file=tmp/organization-secret.json
jq -n \
--arg secret_name "${secret_name}" \
--arg key_id "${key_id}" \
Expand All @@ -24,8 +23,10 @@ jq -n \
encrypted_value: $encrypted_value
}' > ${json_file}


curl ${curl_custom_flags} \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/orgs/${org}/actions/secrets/${secret_name} --data @${json_file}
"${GITHUB_API_BASE_URL}/orgs/${org}/actions/secrets/${secret_name}" --data @${json_file}

8 changes: 4 additions & 4 deletions create-an-organization-webhook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

if [ -z "$1" ]
then
org=$org
org=${org}
else
org=$1
fi

json_file=tmp/create-an-organization-webhook.json
rm -f ${json_file}

jq -n \
--arg name "web" \
--arg webhook_url "${webhook_url}" \
Expand All @@ -30,8 +28,10 @@ jq -n \
}
}' > ${json_file}


curl ${curl_custom_flags} \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
${GITHUB_API_BASE_URL}/orgs/${org}/hooks --data @${json_file}
"${GITHUB_API_BASE_URL}/orgs/${org}/hooks" --data @${json_file}

13 changes: 6 additions & 7 deletions create-commit-anyfile.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents
# PUT /repos/:owner/:repo/contents/:path
# https://docs.github.com/en/enterprise-cloud@latest/rest/repos/contents?apiVersion=2022-11-28#create-or-update-file-contents
# PUT /repos/{owner}/{repo}/contents/{path}


if [ -z "$1" ]
then
Expand All @@ -26,13 +27,10 @@ fi
template_file=$(printf "${filename_in_repo}%s" "_")
base64_string=$(./base64encode.py ${template_file})
comment="Adding ${filename_in_repo}"
json_file="tmp/create-commit.json"

rm ${json_file}

content="woo"


json_file="tmp/create-commit.json"
jq -n \
--arg nm "${default_committer}" \
--arg ms "${comment}" \
Expand All @@ -44,4 +42,5 @@ curl ${curl_custom_flags} \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/contents/${filename_in_repo} --data @${json_file}
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/contents/${filename_in_repo}" --data @${json_file}

6 changes: 3 additions & 3 deletions create-environment.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/rest/reference/repos#create-or-update-an-environment
# https://docs.github.com/en/rest/deployments/environments?apiVersion=2022-11-28#create-or-update-an-environment
# PUT /repos/{owner}/{repo}/environments/{environment_name}

environment_name=${default_environment_name}
Expand All @@ -11,7 +11,6 @@ deployment_branch_policy=protected_branches
reviewer_id=$(./list-user.sh ${default_committer} | jq -r '.id')

json_file=tmp/create-an-environment.json

jq -n \
--argjson reviewer_id "${reviewer_id}" \
--argjson wait_timer "${wait_timer}" \
Expand All @@ -27,4 +26,5 @@ curl ${curl_custom_flags} \
-X PUT \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
${GITHUB_API_BASE_URL}/repos/${org}/${repo}/environments/${environment_name} --data @$json_file
"${GITHUB_API_BASE_URL}/repos/${org}/${repo}/environments/${environment_name}" --data @$json_file

Loading

0 comments on commit fc36dac

Please sign in to comment.