Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Windows Git Bash #99

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Changes from 2 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
24 changes: 14 additions & 10 deletions gh-repo-stats
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
# Validate we can hit the endpoint by getting the current user #
################################################################
if [[ ${GITHUB_TOKEN_TYPE} == "user" ]]; then
USER_DATA=$(gh api /user)
USER_DATA=$(gh api user)
ERROR_CODE=$?

#######################
Expand All @@ -249,7 +249,7 @@
# Check GHE version #
#####################
if [[ "$(isCloud)" -eq 0 ]]; then
META_DATA=$(gh api /meta)
META_DATA=$(gh api meta)
ERROR_CODE=$?

#######################
Expand Down Expand Up @@ -471,7 +471,7 @@
##################
# Get membership #
##################
MEMBERSHIP_DATA=$(gh api "/orgs/${ORG_NAME}/memberships/${USER_LOGIN}")
MEMBERSHIP_DATA=$(gh api orgs/${ORG_NAME}/memberships/${USER_LOGIN})
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
ERROR_CODE=$?

if [ "${ERROR_CODE}" -ne 0 ]; then
Expand All @@ -493,7 +493,13 @@
################################################################################
#### Function isGHEC ###########################################################
isCloud() {
ROOT_DATA=$(gh api /)
if [[ "$OSTYPE" == "msys" ]]; then
Fixed Show fixed Hide fixed
# If the operating system is Windows escape leading slash
ROOT_DATA=$(gh api //)
else
# If the operating system is Unix-like (e.g., Linux, macOS)
ROOT_DATA=$(gh api /)
fi
USER_URL=$(echo -n "${ROOT_DATA}" | jq -r '.current_user_url')

if [[ "${USER_URL}" != "https://api.github.com/user" ]]; then
Expand Down Expand Up @@ -560,7 +566,7 @@
##############################################################
# Check what is remaining, and if 0, we need to sleep it off #
##############################################################
API_REMAINING_REQUEST=$(gh api /rate_limit)
API_REMAINING_REQUEST=$(gh api rate_limit)
API_REMAINING_MESSAGE=$(echo "${API_REMAINING_REQUEST}" | jq -r '.message' 2>&1)

if [[ "${API_REMAINING_MESSAGE}" != "Rate limiting is not enabled." ]]; then
Expand Down Expand Up @@ -1071,7 +1077,7 @@
echo "ERROR --- Errors occurred while retrieving issues for repo: ${REPO_NAME}"
echo "${ERROR_MESSAGE}" | jq '.'
fi

ISSUE_REPO=$(echo -n "${ISSUE_DATA}" | jq -r '.data.repository | @base64')

######################
Expand All @@ -1084,7 +1090,6 @@
#### Function AnalyzePullRequests ##############################################
AnalyzePullRequests() {
PR_REPO=$1

_pr_repo_jq() {
echo -n "${PR_REPO}" | base64 --decode | jq -r "${1}"
}
Expand All @@ -1102,10 +1107,9 @@
# Get the Current End Cursor #
##############################
PR_NEXT_PAGE=$(_pr_repo_jq '.pullRequests.pageInfo.endCursor')

for PR in $(echo -n "${PRS}" | jq -r '.[] | @base64'); do
_pr_jq() {
echo -n "${PR}" | base64 --decode | jq -r "${1}"
echo -n "${PR}" | base64 --decode | jq -r "${1}"
}

PR_NUMBER=$(_pr_jq '.number')
Expand Down Expand Up @@ -1425,7 +1429,7 @@
# Get the Current End Cursor #
##############################
TEAM_NEXT_PAGE=$(echo "${TEAM_DATA}" | jq -r '.data.organization.teams.pageInfo.endCursor')

for TEAM in $(echo -n "${TEAMS}" | jq -r '.[] | @base64'); do
_team_jq() {
echo -n "${TEAM}" | base64 --decode | jq -r "${1}"
Expand Down
Loading