Skip to content

Commit

Permalink
[add] Discussion event actions (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery authored Oct 6, 2024
1 parent 9cdba43 commit 1276034
Show file tree
Hide file tree
Showing 2 changed files with 266 additions and 22 deletions.
258 changes: 236 additions & 22 deletions .github/workflows/Lark.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
name: Lark notification

# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
on:
push:
issues:
issue_comment:
pull_request:
discussion:
issue_comment:
discussion_comment:

jobs:
send-Lark-message:
runs-on: ubuntu-latest
steps:
- name: Commit message cleaning
id: commit_message
run: |
echo "${{ github.event.head_commit.message }}" | sed 's/"/\\"/g' > commit_message.txt
body=$(cat commit_message.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "commit_message=$body" >> $GITHUB_OUTPUT
- name: Commits pushed
uses: foxundermoon/feishu-action@v2
if: github.event_name == 'push'
Expand Down Expand Up @@ -38,12 +52,21 @@ jobs:
- - tag: text
text: 提交信息:
- tag: text
text: |
${{ github.event.head_commit.message }}
text: "${{ steps.commit_message.outputs.commit_message }}"
- name: Issue/PR opened
- name: Issue body cleaning
id: issue_body
run: |
echo "${{ github.event.issue.body }}" | sed 's/"/\\"/g' > issue_body.txt
body=$(cat issue_body.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "issue_body=$body" >> $GITHUB_OUTPUT
- name: Issue opened
uses: foxundermoon/feishu-action@v2
if: (github.event_name == 'issues' || github.event_name == 'pull_request') && (github.event.action == 'opened' || github.event.action == 'reopened')
if: github.event_name == 'issues' && (github.event.action == 'opened' || github.event.action == 'reopened')
with:
url: ${{ secrets.LARK_CHATBOT_HOOK_URL }}
msg_type: post
Expand Down Expand Up @@ -72,14 +95,13 @@ jobs:
- - tag: text
text: 里程碑:${{ github.event.issue.milestone.title }}
- - tag: text
text: 内容
text: 描述
- tag: text
text: |
${{ github.event.issue.body }}
text: "${{ steps.issue_body.outputs.issue_body }}"
- name: Issue edited
uses: foxundermoon/feishu-action@v2
if: (github.event_name == 'issues' || github.event_name == 'pull_request') && (github.event.action == 'edited' || github.event.action == 'transferred' || github.event.action == 'labeled' || github.event.action == 'unlabeled' || github.event.action == 'assigned' || github.event.action == 'unassigned')
if: github.event_name == 'issues' && (github.event.action == 'edited' || github.event.action == 'transferred' || github.event.action == 'labeled' || github.event.action == 'unlabeled' || github.event.action == 'assigned' || github.event.action == 'unassigned')
with:
url: ${{ secrets.LARK_CHATBOT_HOOK_URL }}
msg_type: post
Expand Down Expand Up @@ -108,14 +130,13 @@ jobs:
- - tag: text
text: 里程碑:${{ github.event.issue.milestone.title }}
- - tag: text
text: 内容
text: 描述
- tag: text
text: |
${{ github.event.issue.body }}
text: "${{ steps.issue_body.outputs.issue_body }}"
- name: Issue closed
uses: foxundermoon/feishu-action@v2
if: (github.event_name == 'issues' || github.event_name == 'pull_request') && github.event.action == 'closed'
if: github.event_name == 'issues' && github.event.action == 'closed'
with:
url: ${{ secrets.LARK_CHATBOT_HOOK_URL }}
msg_type: post
Expand Down Expand Up @@ -144,21 +165,215 @@ jobs:
- - tag: text
text: 里程碑:${{ github.event.issue.milestone.title }}
- - tag: text
text: 内容:
text: 描述:
- tag: text
text: "${{ steps.issue_body.outputs.issue_body }}"
- name: PR body cleaning
id: PR_body
run: |
echo "${{ github.event.pull_request.body }}" | sed 's/"/\\"/g' > PR_body.txt
body=$(cat PR_body.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "PR_body=$body" >> $GITHUB_OUTPUT
- name: PR opened
uses: foxundermoon/feishu-action@v2
if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened')
with:
url: ${{ secrets.LARK_CHATBOT_HOOK_URL }}
msg_type: post
content: |
post:
zh_cn:
title: GitHub PR 打开:${{ github.event.pull_request.title }}
content:
- - tag: text
text: 链接:
- tag: a
text: ${{ github.event.pull_request.html_url }}
href: ${{ github.event.pull_request.html_url }}
- - tag: text
text: 作者:
- tag: a
text: ${{ github.event.pull_request.user.login }}
href: ${{ github.event.pull_request.user.html_url }}
- - tag: text
text: 指派:
- tag: a
text: ${{ github.event.pull_request.assignee.login }}
href: ${{ github.event.pull_request.assignee.html_url }}
- - tag: text
text: "标签:${{ github.event.pull_request.labels }}"
- - tag: text
text: 里程碑:${{ github.event.pull_request.milestone.title }}
- - tag: text
text: 描述:
- tag: text
text: "${{ steps.PR_body.outputs.PR_body }}"
- name: PR edited
uses: foxundermoon/feishu-action@v2
if: github.event_name == 'pull_request' && (github.event.action == 'edited' || github.event.action == 'labeled' || github.event.action == 'unlabeled' || github.event.action == 'assigned' || github.event.action == 'unassigned')
with:
url: ${{ secrets.LARK_CHATBOT_HOOK_URL }}
msg_type: post
content: |
post:
zh_cn:
title: GitHub PR 编辑:${{ github.event.pull_request.title }}
content:
- - tag: text
text: 链接:
- tag: a
text: ${{ github.event.pull_request.html_url }}
href: ${{ github.event.pull_request.html_url }}
- - tag: text
text: 作者:
- tag: a
text: ${{ github.event.pull_request.user.login }}
href: ${{ github.event.pull_request.user.html_url }}
- - tag: text
text: 指派:
- tag: a
text: ${{ github.event.pull_request.assignee.login }}
href: ${{ github.event.pull_request.assignee.html_url }}
- - tag: text
text: "标签:${{ github.event.pull_request.labels }}"
- - tag: text
text: 里程碑:${{ github.event.pull_request.milestone.title }}
- - tag: text
text: 描述:
- tag: text
text: "${{ steps.PR_body.outputs.PR_body }}"
- name: PR closed
uses: foxundermoon/feishu-action@v2
if: github.event_name == 'pull_request' && github.event.action == 'closed'
with:
url: ${{ secrets.LARK_CHATBOT_HOOK_URL }}
msg_type: post
content: |
post:
zh_cn:
title: GitHub PR 关闭:${{ github.event.pull_request.title }}
content:
- - tag: text
text: 链接:
- tag: a
text: ${{ github.event.pull_request.html_url }}
href: ${{ github.event.pull_request.html_url }}
- - tag: text
text: 作者:
- tag: a
text: ${{ github.event.pull_request.user.login }}
href: ${{ github.event.pull_request.user.html_url }}
- - tag: text
text: 指派:
- tag: a
text: ${{ github.event.pull_request.assignee.login }}
href: ${{ github.event.pull_request.assignee.html_url }}
- - tag: text
text: "标签:${{ github.event.pull_request.labels }}"
- - tag: text
text: 里程碑:${{ github.event.pull_request.milestone.title }}
- - tag: text
text: 描述:
- tag: text
text: "${{ steps.PR_body.outputs.PR_body }}"
- name: Discussion body cleaning
id: discussion_body
run: |
echo "${{ github.event.discussion.body }}" | sed 's/"/\\"/g' > discussion_body.txt
body=$(cat discussion_body.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "discussion_body=$body" >> $GITHUB_OUTPUT
- name: Discussion created
uses: foxundermoon/feishu-action@v2
if: github.event_name == 'discussion' && github.event.action == 'created'
with:
url: ${{ secrets.LARK_CHATBOT_HOOK_URL }}
msg_type: post
content: |
post:
zh_cn:
title: GitHub 帖子发布:${{ github.event.discussion.title }}
content:
- - tag: text
text: 链接:
- tag: a
text: ${{ github.event.discussion.html_url }}
href: ${{ github.event.discussion.html_url }}
- - tag: text
text: 作者:
- tag: a
text: ${{ github.event.discussion.user.login }}
href: ${{ github.event.discussion.user.html_url }}
- - tag: text
text: "分类:${{ github.event.discussion.category }}"
- - tag: text
text: "标签:${{ github.event.discussion.labels }}"
- - tag: text
text: 描述:
- tag: text
text: "${{ steps.discussion_body.outputs.discussion_body }}"
- name: Discussion edited
uses: foxundermoon/feishu-action@v2
if: github.event_name == 'discussion' && (github.event.action == 'edited' || github.event.action == 'transferred' || github.event.action == 'category_changed' || github.event.action == 'labeled' || github.event.action == 'unlabeled')
with:
url: ${{ secrets.LARK_CHATBOT_HOOK_URL }}
msg_type: post
content: |
post:
zh_cn:
title: GitHub 帖子修改:${{ github.event.discussion.title }}
content:
- - tag: text
text: 链接:
- tag: a
text: ${{ github.event.discussion.html_url }}
href: ${{ github.event.discussion.html_url }}
- - tag: text
text: 作者:
- tag: a
text: ${{ github.event.discussion.user.login }}
href: ${{ github.event.discussion.user.html_url }}
- - tag: text
text: "分类:${{ github.event.discussion.category }}"
- - tag: text
text: "标签:${{ github.event.discussion.labels }}"
- - tag: text
text: 描述:
- tag: text
text: |
${{ github.event.issue.body }}
text: "${{ steps.discussion_body.outputs.discussion_body }}"
- name: Comment body cleaning
id: comment_body
run: |
echo "${{ github.event.comment.body }}" | sed 's/"/\\"/g' > comment_body.txt
body=$(cat comment_body.txt)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo "comment_body=$body" >> $GITHUB_OUTPUT
- name: Issue commented
- name: Issue/Discussion commented
uses: foxundermoon/feishu-action@v2
if: github.event_name == 'issue_comment' && (github.event.action == 'created' || github.event.action == 'edited')
if: (github.event_name == 'issue_comment' || github.event_name == 'discussion_comment') && (github.event.action == 'created' || github.event.action == 'edited')
with:
url: ${{ secrets.LARK_CHATBOT_HOOK_URL }}
msg_type: post
content: |
post:
zh_cn:
title: GitHub issue 评论:${{ github.event.issue.title }}
title: GitHub 帖子评论:${{ github.event.issue.title }}
content:
- - tag: text
text: 链接:
Expand All @@ -171,7 +386,6 @@ jobs:
text: ${{ github.event.comment.user.login }}
href: ${{ github.event.comment.user.html_url }}
- - tag: text
text: 内容
text: 描述
- tag: text
text: |
${{ github.event.comment.body }}
text: "${{ steps.comment_body.outputs.comment_body }}"
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@

[![Lark notification](https://github.com/idea2app/Lark-GitHub-bot/actions/workflows/Lark.yml/badge.svg)][5]

## Supported events

1. Push
2. Issues
1. opened
2. reopened
3. edited
4. transferred
5. labeled
6. unlabeled
7. assigned
8. unassigned
9. closed
3. Pull request
1. opened
2. reopened
3. edited
4. labeled
5. unlabeled
6. assigned
7. unassigned
8. closed
4. Issue comment
1. created
2. edited

## Usage

First, set the Web hook URL of your Lark custom bot to `LARK_CHATBOT_HOOK_URL` secret variable in your GitHub repository settings, then:
Expand All @@ -23,6 +49,10 @@ cd .github/workflows
pnpx get-git-folder https://github.com/idea2app/Lark-GitHub-bot main .github/workflows
```

## Acknowledgement

- https://github.com/foxundermoon/feishu-action

[1]: https://www.larksuite.com/
[2]: https://www.feishu.cn/
[3]: https://github.com/features/actions
Expand Down

0 comments on commit 1276034

Please sign in to comment.