Skip to content

Commit b547df5

Browse files
committed
fix: improve echo messages and formatting for better readability in scripts
1 parent 5aa10f7 commit b547df5

4 files changed

Lines changed: 29 additions & 33 deletions

File tree

‎github-add-repo-admin/github-add-repo-admin.sh‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,14 @@ limit_repo_pagination () {
4545

4646
process_repos () {
4747
for PAGE in $(limit_repo_pagination); do
48-
4948
for i in $(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "${API_URL_PREFIX}/orgs/${ORG}/repos?page=${PAGE}&per_page=100&sort=full_name" | jq -r 'sort_by(.name) | .[] | .name'); do
50-
51-
echo "processing repo ${i}"
49+
echo "Processing repo ${i}"
5250

5351
# Give internal repo admin team permissions on the repo
54-
curl -s -X PUT -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/orgs/${ORG}/teams/${REPO_ADMIN}/repos/${ORG}/${i}" -d '{"permission":"admin"}';
55-
56-
# Add delay to prevent hitting github rate limit
57-
sleep 5
52+
curl -s -X PUT -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/orgs/${ORG}/teams/${REPO_ADMIN}/repos/${ORG}/${i}" -d '{"permission":"admin"}'
5853

54+
# Add delay to prevent hitting GitHub rate limit
55+
sleep 5
5956
done
6057
done
6158
}

‎github-import-repo/github-import-repo.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fi
5151
# Create repo
5252
curl -s -X POST -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.nebula-preview+json" "${API_URL_PREFIX}/orgs/${ORG}/repos" -d '{"name":"'"${DEST_REPO}"'", "visibility":"internal"}'
5353

54-
# Grant Admin permissions on new repo
54+
# Grant admin permissions on new repo
5555
curl -s -X PUT -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/repos/${ORG}/${DEST_REPO}/collaborators/${OWNER_USERNAME}" -d '{"permission":"admin"}'
5656

5757
# Clone old repo locally

‎github-monthly-issues-report/github-monthly-issues-report.sh‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,51 +59,48 @@ limit_issue_pagination () {
5959

6060
repo_issues () {
6161
for PAGE in $(limit_issue_pagination); do
62-
for i in $(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "${API_URL_PREFIX}/repos/${ORG}/${REPO}/issues?state=all&labels=Linked%20[AC]&page=${PAGE}&per_page=100" | jq -r 'map(select(.created_at | . >= "'"${MONTH_START}"'T00:00" and . <= "'"${MONTH_END}"'T23:59")) | sort_by(.number) | .[] | .number'); do
63-
ISSUE_PAYLOAD=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "${API_URL_PREFIX}/repos/${ORG}/${REPO}/issues/${i}" -H "Accept: application/vnd.github.mercy-preview+json")
64-
ISSUE_TIMELINE_PAYLOAD=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "${API_URL_PREFIX}/repos/${ORG}/${REPO}/issues/${i}/timeline" -H "Accept: application/vnd.github.mockingbird-preview+json" | jq -r '.[] | select(.label.name=="Linked [AC]" or .label.name=="linked")')
65-
66-
ISSUE_AUTHOR=$(echo "${ISSUE_PAYLOAD}" | jq -r .user.login)
67-
ISSUE_TITLE=$(echo "${ISSUE_PAYLOAD}" | jq -r .title | tr '"' "'")
68-
ISSUE_HTML_URL=$(echo "${ISSUE_PAYLOAD}" | jq -r .html_url)
62+
for i in $(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "${API_URL_PREFIX}/repos/${ORG}/${REPO}/issues?state=all&labels=Linked%20[AC]&page=${PAGE}&per_page=100" | jq -r 'map(select(.created_at | . >= "'"${MONTH_START}"'T00:00" and . <= "'"${MONTH_END}"'T23:59")) | sort_by(.number) | .[] | .number'); do
63+
ISSUE_PAYLOAD=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "${API_URL_PREFIX}/repos/${ORG}/${REPO}/issues/${i}" -H "Accept: application/vnd.github.mercy-preview+json")
64+
ISSUE_TIMELINE_PAYLOAD=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" "${API_URL_PREFIX}/repos/${ORG}/${REPO}/issues/${i}/timeline" -H "Accept: application/vnd.github.mockingbird-preview+json" | jq -r '.[] | select(.label.name=="Linked [AC]" or .label.name=="linked")')
65+
66+
ISSUE_AUTHOR=$(echo "${ISSUE_PAYLOAD}" | jq -r .user.login)
67+
ISSUE_TITLE=$(echo "${ISSUE_PAYLOAD}" | jq -r .title | tr '"' "'")
68+
ISSUE_HTML_URL=$(echo "${ISSUE_PAYLOAD}" | jq -r .html_url)
6969

70-
ISSUE_TIMELINE_LABELED_BY=$(echo "${ISSUE_TIMELINE_PAYLOAD}" | jq -s 'first(.[]| .actor.login)' | jq -r)
70+
ISSUE_TIMELINE_LABELED_BY=$(echo "${ISSUE_TIMELINE_PAYLOAD}" | jq -s 'first(.[]| .actor.login)' | jq -r)
7171

72-
cat >> test.json << EOF
72+
cat >> test.json << EOF
7373
{
7474
"author": "${ISSUE_AUTHOR}",
7575
"title": "${ISSUE_TITLE}",
7676
"issue_url": "${ISSUE_HTML_URL}",
7777
"contributor": "${ISSUE_TIMELINE_LABELED_BY}"
7878
}
7979
EOF
80-
81-
done
80+
done
8281
done
8382
}
8483

8584
author_json () {
8685
AUTHORS=$(cat test.json | jq -r '.author' | sort | uniq -c | awk -F " " '{print "{\"author\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .author)
87-
for AUTHOR in ${AUTHORS}; do
86+
for AUTHOR in ${AUTHORS}; do
8887
TEST_PAYLOAD=$(cat test.json | jq -r '.author' | sort | uniq -c | awk -F " " '{print "{\"author\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .)
8988
TEST_PAYLOAD_AUTHOR=$(echo "${TEST_PAYLOAD}" | jq -r --arg AUTHOR "${AUTHOR}" 'select(.author==$AUTHOR) | .author')
9089
TEST_PAYLOAD_AUTHOR_COUNT=$(echo "${TEST_PAYLOAD}" | jq -r --arg AUTHOR "${AUTHOR}" 'select(.author==$AUTHOR) | .count')
91-
#TEST_PAYLOAD_AUTHOR_ISSUE_TITLE=$(cat test.json | jq -r --arg AUTHOR "${AUTHOR}" 'select(.author==$AUTHOR) | .title')
9290
TEST_PAYLOAD_AUTHOR_ISSUE_URL=$(cat test.json | jq -r --arg AUTHOR "${AUTHOR}" 'select(.author==$AUTHOR) | .title, .issue_url')
9391
echo -e "<a href=\"https://github.com/${TEST_PAYLOAD_AUTHOR}\">${TEST_PAYLOAD_AUTHOR}</a> - ${TEST_PAYLOAD_AUTHOR_COUNT}"
94-
done | sort -n -k 4,4 -r >> output.txt
92+
done | sort -n -k 4,4 -r >> output.txt
9593
}
9694

9795
contributor_json () {
9896
CONTRIBUTORS=$(cat test.json | jq -r '.contributor' | sort | uniq -c | awk -F " " '{print "{\"contributor\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .contributor)
99-
for CONTRIBUTOR in ${CONTRIBUTORS}; do
97+
for CONTRIBUTOR in ${CONTRIBUTORS}; do
10098
TEST_PAYLOAD=$(cat test.json | jq -r '.contributor' | sort | uniq -c | awk -F " " '{print "{\"contributor\":""\""$2"\""",\"count\":" $1"}"}' | jq -r .)
10199
TEST_PAYLOAD_CONTRIBUTOR=$(echo "${TEST_PAYLOAD}" | jq -r --arg CONTRIBUTOR "${CONTRIBUTOR}" 'select(.contributor==$CONTRIBUTOR) | .contributor')
102100
TEST_PAYLOAD_CONTRIBUTOR_COUNT=$(echo "${TEST_PAYLOAD}" | jq -r --arg CONTRIBUTOR "${CONTRIBUTOR}" 'select(.contributor==$CONTRIBUTOR) | .count')
103-
#TEST_PAYLOAD_CONTRIBUTOR_ISSUE_TITLE=$(cat test.json | jq -r --arg CONTRIBUTOR "${CONTRIBUTOR}" 'select(.contributor==$CONTRIBUTOR) | .title' )
104101
TEST_PAYLOAD_CONTRIBUTOR_ISSUE_URL=$(cat test.json | jq -r --arg CONTRIBUTOR "${CONTRIBUTOR}" 'select(.contributor==$CONTRIBUTOR) | .issue_url')
105102
echo -e "<a href=\"https://github.com/${TEST_PAYLOAD_CONTRIBUTOR}\">${TEST_PAYLOAD_CONTRIBUTOR}</a> - ${TEST_PAYLOAD_CONTRIBUTOR_COUNT}"
106-
done | sort -n -k 4,4 -r >> output.txt
103+
done | sort -n -k 4,4 -r >> output.txt
107104
rm -Rf test.json
108105
}
109106

‎github-repo-from-template/github-repo-from-template.sh‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,23 @@ curl -s -X POST -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: applicatio
7070

7171
# Give internal teams permissions on the new repo
7272
for ADMIN_TEAM in ${REPO_ADMIN}; do
73-
curl -s -X PUT -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/orgs/${ORG}/teams/${ADMIN_TEAM}/repos/${ORG}/${REPO_NAME}" -d '{"permission":"admin"}'
74-
# Add delay to prevent hitting github rate limit
75-
sleep 5
73+
curl -s -X PUT -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/orgs/${ORG}/teams/${ADMIN_TEAM}/repos/${ORG}/${REPO_NAME}" -d '{"permission":"admin"}'
74+
75+
# Add delay to prevent hitting GitHub rate limit
76+
sleep 5
7677
done
7778

7879
for WRITE_TEAM in ${REPO_WRITE}; do
79-
curl -s -X PUT -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/orgs/${ORG}/teams/${WRITE_TEAM}/repos/${ORG}/${REPO_NAME}" -d '{"permission":"push"}'
80-
# Add delay to prevent hitting github rate limit
81-
sleep 5
80+
curl -s -X PUT -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/orgs/${ORG}/teams/${WRITE_TEAM}/repos/${ORG}/${REPO_NAME}" -d '{"permission":"push"}'
81+
82+
# Add delay to prevent hitting GitHub rate limit
83+
sleep 5
8284
done
8385

84-
# Give cd user write permissions on the new repo
86+
# Give CD user write permissions on the new repo
8587
curl -s -X PUT -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/repos/${ORG}/${REPO_NAME}/collaborators/${CD_USERNAME}" -d '{"permission":"push"}'
8688

87-
# Accept the invite automatically
89+
# Accept the invite automatically
8890
CD_INVITES=$(curl -s -H "Authorization: token ${CD_GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/user/repository_invitations")
8991
CD_INVITES_INVITE_ID=$(echo "${CD_INVITES}" | jq -r --arg REPO_NAME "${REPO_NAME}" 'select(.[].repository.name==$REPO_NAME) | .[].id')
9092
curl -s -X PATCH -H "Authorization: token ${CD_GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "${API_URL_PREFIX}/user/repository_invitations/${CD_INVITES_INVITE_ID}"

0 commit comments

Comments
 (0)