Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanth0525 committed Oct 30, 2024
2 parents bb22739 + 9bc4c22 commit e7a0ea6
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 11 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/addSubscriber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,41 @@ jobs:
run: |
echo "GIST_ID=${{ secrets.GIST_ID }}" >> $GITHUB_ENV
echo "GIST_TOKEN=${{ secrets.GIST_TOKEN }}" >> $GITHUB_ENV
- name: Add new subscriber
run: |
email="${{ github.event.inputs.email }}"
# Fetch the existing Gist content
gist_response=$(curl -s -X GET "https://api.github.com/gists/$GIST_ID" \
-H "Authorization: token $GIST_TOKEN" \
-H "Accept: application/vnd.github.v3+json")
# Extract the current email list
if [[ $(echo "$gist_response" | jq -r '.files["subscribers.json"] | .content // empty') == "" ]]; then
echo "subscribers.json not found or is empty."
email_list="[]"
else
email_list=$(echo "$gist_response" | jq -r '.files["subscribers.json"].content | fromjson | .emailList')
fi
# Convert existing email list to an array
email_array=($(echo "$email_list" | jq -r '.[]'))
# Check if the email already exists
if [[ " ${email_array[@]} " =~ " $email " ]]; then
echo "Email already exists in the notification list."
exit 1
fi
# Add the new email to the list
updated_email_list=$(echo "$email_list" | jq --arg email "$email" '. += [$email]')
# Prepare the JSON payload for updating the Gist
payload=$(jq -n --argjson list "$updated_email_list" '{ emailList: $list }')
# Prepare the content for subscribers.json as a string
content_string=$(echo "$payload" | jq '.')
# Properly escape the JSON string for the curl command
content_string_escaped=$(echo "$content_string" | jq -sRr @json | sed 's/^"\(.*\)"$/\1/')
# Update Gist with the new list
response=$(curl -s -X PATCH "https://api.github.com/gists/$GIST_ID" \
-H "Authorization: token $GIST_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
-d "{\"files\": {\"subscribers.json\": {\"content\": \"$content_string_escaped\"}}}")
# Output response and subscription confirmation
echo "$response"
if [[ $(echo "$response" | jq -r '.message // empty') == "" ]]; then
Expand Down
Binary file modified public/walls/github-gitignore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/walls/golang-go.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e7a0ea6

Please sign in to comment.