-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (49 loc) · 2.07 KB
/
discourse_post.yml
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
name: Discourse Update
on:
issues:
types: [opened, edited]
jobs:
update_discourse:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Fetch CSRF Token
id: csrf_token
run: |
CSRF_TOKEN=$(curl -s https://goodbids.discourse.group/session/csrf.json | jq -r .csrf)
echo "CSRF_TOKEN=$CSRF_TOKEN" >> $GITHUB_OUTPUT
- name: Post New Issue to Discourse
if: ${{ github.event.action == 'opened' }}
run: |
curl -X POST "https://goodbids.discourse.group/posts.json" \
-H "Content-Type: application/json" \
-H "Api-Key: ${{ secrets.DISCOURSE_UPDATE_SECRET }}" \
-H "Api-Username: jaspercroome" \
-H "X-CSRF-Token: ${{ steps.csrf_token.outputs.CSRF_TOKEN }}" \
-d '{
"title": "Github issue #${{github.event.issue.number}} - ${{ github.event.issue.title }}",
"raw": "${{ github.event.issue.html_url }}",
"category": 22
}'
- name: Update Discourse Post
if: ${{ github.event.action == 'edited' }}
run: |
# Find the topic ID from the issue body or comments
SLUGIFIED_TITLE=$(echo "$original_string" | tr ' ' '-')
TOPIC_ID="github-issue-${{github.event.issue.number}}-$SLUGIFIED_TITLE"
echo "TOPIC_ID: $TOPIC_ID"
# Get the post ID from the Discourse API
POST_ID=$(curl -s "https://goodbids.discourse.group/t/$TOPIC_ID.json" \
-H "Api-Key: ${{ secrets.DISCOURSE_UPDATE_SECRET }}" \
-H "Api-Username: jaspercroome" \
| jq '.post_stream.posts[0].id')
echo "POST_ID: $POST_ID"
curl -X PUT "https://goodbids.discourse.group/posts/$POST_ID.json" \
-H "Content-Type: application/json" \
-H "Api-Key: ${{ secrets.DISCOURSE_UPDATE_SECRET }}" \
-H "Api-Username: jaspercroome" \
-H "X-CSRF-Token: ${{ steps.csrf_token.outputs.CSRF_TOKEN }}" \
-d '{
"raw": "${{ github.event.issue.html_url }}"
}'