Skip to content

Commit

Permalink
Merge pull request #21 from creative-commoners/pulls/1.0/no-branches
Browse files Browse the repository at this point in the history
FIX Use github token for curl request
  • Loading branch information
GuySartorelli authored Aug 22, 2023
2 parents daf8139 + 9f3e0f7 commit 1bb638c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,35 @@ runs:
env:
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
JSON=$(curl https://api.github.com/repos/$GITHUB_REPOSITORY/branches)
BRANCHES=$(echo $JSON | jq -r '.[] | .name | select(.|test("^pulls\/[0-9]\/update-js-[0-9]{10}$"))')
# Gets all branches from GitHub API
# https://docs.github.com/en/rest/branches/branches?apiVersion=2022-11-28#list-branches
RESP_CODE=$(curl -w %{http_code} -s -o __branches.json \
-X GET "https://api.github.com/repos/$GITHUB_REPOSITORY/branches?per_page=100" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
)
if [[ $RESP_CODE != "200" ]]; then
echo "Unable to read list of branches - HTTP response code was $RESP_CODE"
cat __branches.json
exit 1
fi
BRANCHES=$(cat __branches.json | jq -r '.[] | .name | select(.|test("^pulls\/[0-9]\/update-js-[0-9]{10}$"))')
for BRANCH in $BRANCHES; do
if [[ "$BRANCH" =~ ^pulls/[0-9\.]+/update\-js\-[0-9]+$ ]]; then
git push origin --delete "$BRANCH"
echo "Deleted old branch $BRANCH"
fi
done
- name: Delete temporary files
shell: bash
if: always()
run: |
if [[ -f __branches.json ]]; then
rm __branches.json
fi
- name: Generate branch name
if: always()
id: generate-branch-name
Expand Down

0 comments on commit 1bb638c

Please sign in to comment.