Skip to content

Commit

Permalink
update lib
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbtek committed Apr 13, 2022
1 parent 0d16b98 commit 9b2a4ec
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion libraries/util.bash
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,66 @@ function checkValidGitToken()
fi
}

function getGitOrgTeams()
function getGitOrganizationMembers()
{
local -r user="${1}"
local -r token="${2}"
local -r orgName="${3}"
local gitURL="${4}"

# Default Values

if [[ "$(isEmptyString "${gitURL}")" = 'true' ]]
then
gitURL='https://api.github.com'
fi

# Validation

checkValidGitToken "${user}" "${token}" "${gitURL}"

# Pagination

local members='[]'
local page=1
local exitCount=0

for ((page = 1; page > exitCount; page = page + 1))
do
local currentMembers=''
currentMembers="$(
curl \
-s \
-X 'GET' \
-u "${user}:${token}" \
-L "${gitURL}/orgs/${orgName}/members?page=${page}&per_page=100" \
--retry 12 \
--retry-delay 5 |
jq \
--compact-output \
--raw-output \
'. // empty'
)"

if [[ "${currentMembers}" = '[]' ]]
then
echo "${members}"
exitCount="$((page + 1))"
else
local members="$(
jq \
-S \
--compact-output \
--raw-output \
--argjson jqCurrentUsers "${currentMembers}" \
--argjson jqUsers "${members}" \
-n '$jqCurrentUsers + $jqUsers | unique_by(.["id"]) // empty'
)"
fi
done
}

function getGitOrganizationTeams()
{
local -r user="${1}"
local -r token="${2}"
Expand Down Expand Up @@ -1283,6 +1342,32 @@ function removeGitCollaboratorFromRepository()
--retry-delay 5
}

function removeGitMemberFromOrganization()
{
local -r user="${1}"
local -r token="${2}"
local gitURL="${3}"
local -r orgName="${4}"
local -r member="${5}"

# Default Values

if [[ "$(isEmptyString "${gitURL}")" = 'true' ]]
then
gitURL='https://api.github.com'
fi

# Remove Member

curl \
-s \
-X 'DELETE' \
-u "${user}:${token}" \
-L "${gitURL}/orgs/${orgName}/members/${member}" \
--retry 12 \
--retry-delay 5
}

function removeGitUserFromTeam()
{
local -r user="${1}"
Expand Down

0 comments on commit 9b2a4ec

Please sign in to comment.