Skip to content

Commit

Permalink
feat: unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
leemhoon00 committed Jul 20, 2024
1 parent d8ac900 commit 0a90432
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/subscribe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
run: sudo apt-get install jq

- name: Set execute permission for script
run: chmod +x ./subscribe.sh
run: chmod +x ./scripts/subscribe.sh

- name: subscribe
continue-on-error: false
run: |
./subscribe.sh "${{ github.event.issue.body}}" "${{ secrets.API_GATEWAY_URL }}"
./scripts/subscribe.sh "${{ github.event.issue.body}}" "${{ secrets.API_GATEWAY_URL }}"
- name: Add comment
run: gh issue comment "$NUMBER" --body "$BODY"
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/unsubscribe.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: unsubscribe
on:
issues:
types: [closed]
permissions:
issues: write
jobs:
unsubscribe:
if: contains(github.event.issue.labels.*.name, '구독신청')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install jq
run: sudo apt-get install jq

- name: Set execute permission for script
run: chmod +x ./scripts/unsubscribe.sh

- name: unsubscribe
continue-on-error: false
run: |
./scripts/unsubscribe.sh "${{ github.event.issue.body}}" "${{ secrets.API_GATEWAY_URL }}"
- name: Add comment
run: gh issue comment "$NUMBER" --body "$BODY"
env:
NUMBER: ${{ github.event.issue.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
BODY: |
구독이 취소되었습니다.
**다시 이메일 알림을 받고 싶다면?**
> Close된 Issue를 다시 Open 해주세요. 자동화된 프로세스로 구독을 신청합니다.
File renamed without changes.
34 changes: 34 additions & 0 deletions scripts/unsubscribe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
INPUT_TEXT="$1"
API_URL="$2"

# 이메일 주소 추출
EMAIL=$(echo "$INPUT_TEXT" | grep -oP '[\w.+-]+@[\w-]+\.[\w.-]+')

if [ -z "$EMAIL" ]; then
echo "Error: 입력 텍스트에서 이메일 주소를 찾을 수 없습니다."
exit 1
fi

JSON_DATA=$(jq -n \
--arg email "$EMAIL" \
'{email: $email}')

FULL_URL="${API_URL}/unsubscribe"

# Post 요청
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST -H "Content-Type: application/json" -d "$JSON_DATA" "$FULL_URL")

# 응답 본문과 상태 코드 분리
HTTP_BODY=$(echo "$RESPONSE" | sed '$d')
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1)

# 상태 코드에 따른 처리
if [ "$HTTP_STATUS" == "204" ]; then
echo "Success: 구독 취소가 성공적으로 완료되었습니다."
echo "응답 본문: $HTTP_BODY"
exit 0
else
echo "Error: 구독 취소 요청이 실패했습니다. HTTP 상태 코드: $HTTP_STATUS"
echo "응답 본문: $HTTP_BODY"
exit 1
fi

0 comments on commit 0a90432

Please sign in to comment.