Skip to content

Commit

Permalink
refactor: update fetchers to include org column in csv
Browse files Browse the repository at this point in the history
  • Loading branch information
sjungling committed Nov 19, 2024
1 parent f176817 commit 4a8004c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions bitbucket-cloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [ -z "$username" -o -z "$app_password" -o -z "$workspace" ]; then
usage
fi

echo "cloneUrl,branch"
echo "cloneUrl,branch,org"

next_page="https://api.bitbucket.org/2.0/repositories/$workspace"

Expand All @@ -44,11 +44,13 @@ while [ "$next_page" ]; do
.values[] |
(.links.clone[] | select(.name=="https") | .href) as $cloneUrl |
.mainbranch.name as $branchName |
"\($cloneUrl),\($branchName)"' |
while IFS=, read -r cloneUrl branchName; do
.workspace.name as $organization |
"\($cloneUrl),\($branchName),\($organization)"' |
while IFS=, read -r cloneUrl branchName organization; do
cleanUrl=$(echo "$cloneUrl" | sed -E 's|https://[^@]+@|https://|')
echo "$cleanUrl,$branchName"
echo "$cleanUrl,$branchName,$organization"
done


next_page=$(echo "$response" | sed -e "s:${username}@::g" | jq -r '.next // empty')
done
4 changes: 2 additions & 2 deletions bitbucket-data-center.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ if [ $? -ne 0 ]; then
exit 1
fi

echo "cloneUrl,branch"
echo "cloneUrl,branch,org"
for REPO in $ALL_REPOS; do
IFS=',' read -r repo project cloneUrl <<< "$REPO"
repo="${repo//\"/}"
project="${project//\"/}"
cloneUrl="${cloneUrl//\"/}"
branch=$(curl -s -X GET -H "Content-Type: application/json" -H "$auth_header" "$bitbucket_url/rest/api/latest/projects/$project/repos/$repo/default-branch" | jq -r '.displayId')

echo "$cloneUrl,$branch"
echo "$cloneUrl,$branch,$project"
done
2 changes: 1 addition & 1 deletion github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ organization=$1
# JQ
gh repo list "$organization" \
--json url,defaultBranchRef \
--jq '["cloneUrl","branch"], (.[] | [.url, .defaultBranchRef.name]) | @csv'
--jq '["cloneUrl","branch","org"], (.[] | [.url, .defaultBranchRef.name, "'"$organization"'"]) | @csv'
4 changes: 2 additions & 2 deletions gitlab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fi
page=1
per_page=100

echo '"cloneUrl","branch"'
echo '"cloneUrl","branch","org"'
while :; do
# Construct the request URL with pagination parameters
request_url="${base_request_url}&page=${page}&per_page=${per_page}"
Expand All @@ -47,7 +47,7 @@ while :; do
fi

# Process and output data
echo "$response" | jq -r '(.[] | [.http_url_to_repo, .default_branch]) | @csv'
echo "$response" | jq -r '(.[] | [.http_url_to_repo, .default_branch, .namespace.path]) | @csv'

# Increment page counter
((page++))
Expand Down

0 comments on commit 4a8004c

Please sign in to comment.