11# Post a string or the contents of a file to a Discourse topic
22
33This repository provides a GitHub Action to post a string or the contents of a
4- given file to a specific Discourse topic.
4+ given file to a specific Discourse topic, either adding a new reply or replacing
5+ a single post's content.
56
67We use it as part of our API documentation management suite:
78[ Rapidoc] ( https://rapidocweb.com/ ) as a [ Discourse] ( https://discourse.org/ )
@@ -17,10 +18,17 @@ finally upload the changelogs with the action from this repository.
1718
1819- ` discourse_url ` - your discourse instance domain, e.g.
1920 "community.developer.gridx.de
20- - ` discourse_topic_id ` - the ID of the Discourse post to reply to. You can find
21- the ID, e.g., by inspecting your post in the browser and looking for
22- ` data-topic-id="<n>" ` in the ` article ` element. (XPath ` //h1/@data-topic-id ` )
23- ![ Discourse Topic ID] ( doc-topic-id.png )
21+ - ` discourse_topic_id ` - Use this to reply to a topic: the ID of the Discourse
22+ topic to reply to. You can find the ID, e.g., by inspecting your post in the
23+ browser and looking for ` data-topic-id="<n>" ` in the ` article ` element. (XPath
24+ ` //h1/@data-topic-id ` ). ** If both topic and post ID are given, topic ID takes
25+ precedence and a new reply is added** . ![ Discourse Topic ID] ( doc-topic-id.png )
26+ - ` discourse_post_id ` - Use this to replace the contents of a post: the ID of
27+ the Discourse post to reply to. You can find the ID, e.g., by inspecting your
28+ post in the browser and looking for ` data-post-id="<n>" ` in the ` article `
29+ element. (XPath ` //article/@data-post-id ` ). If there are multiple posts in the
30+ topic, make sure to find the correct one to replace. ** If both topic and post
31+ ID are given, topic ID takes precedence and a new reply is added** .
2432- ` discourse_api_key ` - your discourse API key. It needs ` topics:write `
2533 permissions. ![ Discourse API Key] ( doc-discourse-api-key.png )
2634- ` discourse_user ` - the discourse user on whose behalf the action should be
@@ -29,9 +37,11 @@ finally upload the changelogs with the action from this repository.
2937 obtained using ` $GITHUB_SHA ` when running in an action or with
3038 ` git rev-parse --short HEAD `
3139- ` content_file ` - the (text) file containing the contents to be posted,
32- relative to the repositories root. Use either this or ` content ` directly.
40+ relative to the repositories root. Use either this or ` content ` directly. ** If
41+ both are present, content file takes precedence.**
3342- ` content ` - the contents to be posted. Use either this or ` content_file ` to
34- load the content from a file. D'uh.
43+ load the content from a file. D'uh. ** If both are present, content file takes
44+ precedence.**
3545
3646## Instructions
3747
@@ -40,19 +50,36 @@ finally upload the changelogs with the action from this repository.
40501 . Get the required parameters as described above
41511 . Configure the action in your GH workflow, preferably on release
4252
53+ Example: Adding a reply from a file
54+
4355``` yaml
4456- name : Test Action against gridX community example post
4557 uses : ./
4658 with :
4759 discourse_url : ${{secrets.DISCOURSE_URL}}
4860 discourse_topic_id : <n>
61+ # OR discourse_post_id: <n>
4962 discourse_api_key : ${{secrets.DISCOURSE_API_KEY}}
5063 discourse_user : ${{secrets.DISCOURSE_USER}}
5164 github_sha : ${{env.SHORT_SHA}}
5265 content_file : ./changelog.md
5366 # OR content: "content as string"
5467```
5568
69+ Example: Replacing a single post with a fixed string
70+
71+ ``` yaml
72+ - name : Test Action against gridX community example post
73+ uses : ./
74+ with :
75+ discourse_url : ${{secrets.DISCOURSE_URL}}
76+ discourse_post_id : <n>
77+ discourse_api_key : ${{secrets.DISCOURSE_API_KEY}}
78+ discourse_user : ${{secrets.DISCOURSE_USER}}
79+ github_sha : ${{env.SHORT_SHA}}
80+ content : ' Post <n> will be replaced by this'
81+ ` ` `
82+
5683## Development
5784
5885- You can run the action locally using ` npm run test:run`, providing the
0 commit comments