chore(workflow): employ @pkgforge-bot to auto respond to Issues & Discussions #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 🤖 Auto Respond [Discussions|Issues|PRs] ℹ️ | |
env: | |
GITHUB_TOKEN: "${{ secrets.BOT_TOKEN }}" | |
on: | |
issues: | |
types: [opened] | |
pull_request: | |
types: [opened] | |
discussion: | |
types: [created] | |
workflow_dispatch: #will fail | |
jobs: | |
auto-respond: | |
runs-on: ubuntu-latest | |
#permissions: | |
# issues: write | |
# pull-requests: write | |
# discussions: write | |
steps: | |
- name: Get GitHub context | |
env: | |
EVENT_JSON: ${{ toJson(github.event) }} | |
run: | | |
#Presets | |
set +x ; set +e | |
#--------------# | |
printf '%s\n' "$EVENT_JSON" | jq . | |
continue-on-error: true | |
- name: Set GitHub ENV | |
run: | | |
#Presets | |
set +x ; set +e | |
#--------------# | |
echo "Repository: ${{ github.repository }}" | |
echo "Branch: ${{ github.ref }}" | |
echo "Actor: ${{ github.actor }}" | |
echo "Event: ${{ github.event_name }}" | |
if [[ "${{ github.event_name }}" == "discussion" ]]; then | |
#DISCUSSION_ID="${{ github.event.discussion.id }}" | |
DISCUSSION_ID="${{ github.event.discussion.node_id }}" | |
echo "DISCUSSION_ID=${DISCUSSION_ID}" >> "${GITHUB_ENV}" | |
echo "New Discussion! [Discussion ID: ${DISCUSSION_ID}]" | |
echo -e "🤖 **Automated Response** \nThanks for starting this discussion! \n**Quick Details:** \n- 💬 We're excited to hear your thoughts \n- 🕒 Typical response time is 12-24 hours \n*Want to connect more with our team and community?* \n**Join Our Discord:** https://discord.gg/djJUs48Zbu \nDive deeper with us and get involved!" > "/tmp/DISCUSSION.md" | |
#DISCUSSION_MESSAGE="$(cat '/tmp/DISCUSSION.md')" ; export DISCUSSION_MESSAGE | |
echo "MESSAGE=/tmp/DISCUSSION.md" >> "${GITHUB_ENV}" | |
elif [[ "${{ github.event_name }}" == "issues" ]]; then | |
COMMENT_URL="$(echo ${{ github.event.issue.comments_url }} | tr -d '[:space:]')" | |
echo "COMMENT_URL=${COMMENT_URL}" >> "${GITHUB_ENV}" | |
echo "New Issue! [Comments URL: ${COMMENT_URL}]" | |
echo -e "🤖 **Automated Response** \nThanks for opening this issue! \n**Quick Details:** \n- 📋 We'll review it shortly \n- 🕒 Typical response time is 12-24 hours \n*Want faster resolution or more community support?* \n**Join Our Discord:** https://discord.gg/djJUs48Zbu \nConnect directly with our team, get quicker responses, and engage with our community!" > "/tmp/ISSUE.md" | |
#ISSUE_MESSAGE="$(cat '/tmp/ISSUE.md')" ; export ISSUE_MESSAGE | |
echo "MESSAGE=/tmp/ISSUE.md" >> "${GITHUB_ENV}" | |
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
COMMENT_URL="$(echo ${{ github.event.pull_request.comments_url }} | tr -d '[:space:]')" | |
echo "COMMENT_URL=${COMMENT_URL}" >> "${GITHUB_ENV}" | |
echo "New Pull Request! [Comments URL: ${COMMENT_URL}]" | |
echo -e "🤖 **Automated Response** \nThanks for opening this pull request! \n**Quick Details:** \n- 📋 We'll review it shortly \n- 🕒 Typical response time is 12-24 hours \n*Want faster resolution or more community support?* \n**Join Our Discord:** https://discord.gg/djJUs48Zbu \nConnect directly with our team, get quicker responses, and engage with our community!" > "/tmp/PR.md" | |
#PR_MESSAGE="$(cat '/tmp/PR.md')" ; export PR_MESSAGE | |
echo "MESSAGE=/tmp/PR.md" >> "${GITHUB_ENV}" | |
else | |
echo "Unsupported event: ${{ github.event_name }}" | |
fi | |
continue-on-error: true | |
- name: Reply (Discussion) | |
run: | | |
#Presets | |
set +x ; set +e | |
#--------------# | |
set -x | |
if [ -n "${DISCUSSION_ID}" ]; then | |
#https://docs.github.com/en/graphql/guides/using-the-graphql-api-for-discussions | |
COMMENT_BODY="$(cat ${MESSAGE})" | |
QUERY=$(jq -n --arg discussionId "${DISCUSSION_ID}" --arg body "${COMMENT_BODY}" '{"query":"mutation AddDiscussionComment($discussionId: ID!, $body: String!) { addDiscussionComment(input: {discussionId: $discussionId, body: $body}) { comment { id body } } }","variables":{"discussionId":$discussionId,"body":$body}}') | |
curl -qfsSL -X 'POST' "https://api.github.com/graphql" -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | |
-d "$QUERY" | |
fi | |
continue-on-error: true | |
- name: Reply (Issues|PRs) | |
run: | | |
#Presets | |
set +x ; set +e | |
#--------------# | |
if [ -n "${COMMENT_URL}" ]; then | |
curl -qfsSL -X 'POST' "${COMMENT_URL}" -H "Authorization: Bearer ${GITHUB_TOKEN}" \ | |
-d "{\"body\": $(cat "${MESSAGE}" | jq -Rs .)}" | |
fi | |
continue-on-error: true |