-
Notifications
You must be signed in to change notification settings - Fork 3
91 lines (87 loc) · 4.69 KB
/
auto_respond.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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