Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions add-users-to-a-cost-center.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
. ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin/billing?apiVersion=2022-11-28#add-users-to-a-cost-center
# POST /enterprises/{enterprise}/settings/billing/cost-centers/{cost_center_id}/resource




# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
cost_center_id=$(./get-all-cost-centers-for-an-enterprise.sh | jq -r '.costCenters[-1].id')
else
cost_center_id=$1
fi

users="[$(printf '"%s"' "$default_committer")]"

json_file=tmp/add-users-to-a-cost-center.json
jq -n \
--argjson users "${users}" \
'{
users : $users
}' > ${json_file}

cat $json_file | jq -r >&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}/enterprises/${enterprise}/settings/billing/cost-centers/${cost_center_id}/resource" --data @${json_file}

11 changes: 10 additions & 1 deletion get-all-cost-centers-for-an-enterprise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@
# GET /enterprises/{enterprise}/settings/billing/cost-centers


# If the script is passed an argument $1 use that as the name
if [ -z "$1" ]
then
enterprise=$enterprise
else
enterprise=$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}/enterprises/${enterprise}/settings/billing/cost-centers"
"${GITHUB_API_BASE_URL}/enterprises/${enterprise}/settings/billing/cost-centers"