Skip to content

Commit

Permalink
[GitHub] Add new actions to connect GitHub and Discord (#4445)
Browse files Browse the repository at this point in the history
* [GitHub] Add a script to post list of pending topics on GHD

* add yml action file to post pending discussions

* rename env var for discuord  using detailed name

* add new script to post announcements in dedicated channel

* fix typo

* minor cosmetic improvements

* add action for release announcement

* move all discord script in a dedicated folder

* create a single python script to send messages from yml files and create a new action for dev meeting agenda

* cosmetic changes

* add warning message before SOFA dev meeting + cosmetic change

* Rename actions for readibility

* Add new action forwarding all GH activities
  • Loading branch information
hugtalbot committed Jan 24, 2024
1 parent 7e45178 commit 2e3a104
Show file tree
Hide file tree
Showing 10 changed files with 455 additions and 3 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/post-agenda-sofa-dev-meeting.yml
@@ -0,0 +1,49 @@
name: Post - SOFA dev meeting agenda/reminder

on:
schedule:
- cron: '30 7 * * 1' # 9:30 am CET every Monday
- cron: '0 6 * * 3' # 8:00 am CET on Wednesdays
jobs:
run:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
run: |
pip install python-graphql-client
pip install python-dateutil
pip install requests
working-directory: ${{ github.workspace }}

# Monday message : agenda
- name: Run script post-discord-message.py
if: ${{ github.event_name == 'schedule' && github.event.scheduled_time | date('%-u') == '1' }}
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE : ":sunrise: Morning, dear SOFA community! Next Wednesday takes place the weekly SOFA dev meeting:\n**_Any specific topic to share or to discuss?_** If so, please reply in this thread :speech_balloon: *Remember you can use the tag \"pr: dev meeting topic\" for your PRs*"
BOT_NAME: "Meeting reminder"
EMBEDS_TITLE: "Label \"pr: dev-meeting topic\""
EMBEDS_URL: "https://github.com/sofa-framework/sofa/labels/pr%3A%20dev%20meeting%20topic"
EMBEDS_DESCRIPTION: ""

# Wednesday message : get ready
- name: Run script post-discord-message.py
if: ${{ github.event_name == 'schedule' && github.event.scheduled_time | date('%-u') == '3' }}
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: "SOFA dev meeting is about to get started :tv: See you online!"
BOT_NAME: "Meeting reminder"
EMBEDS_TITLE: "SOFA dev visio link"
EMBEDS_URL: "https://www.sofa-framework.org/sofa-dev-meeting"
EMBEDS_DESCRIPTION: ""

34 changes: 34 additions & 0 deletions .github/workflows/post-announcements.yml
@@ -0,0 +1,34 @@
name: Post - Announcement GHD topics

on:
discussion:
types: [created]

jobs:
run:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
if: ( context.payload.discussion.category.name == 'Announcement' ) || ( context.payload.discussion.category.name == 'Share your achievements' )
run: |
pip install python-graphql-client
pip install python-dateutil
pip install requests
working-directory: ${{ github.workspace }}

- name: Run script post-discord-message.py
if: ( context.payload.discussion.category.name == 'Announcement' ) || ( context.payload.discussion.category.name == 'Share your achievements' )
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_ANNOUNCEMENTS_WEBHOOK_URL }}
MESSAGE: ":loudspeaker: New post \"${{context.payload.discussion.category.name}}\" :arrow_right: **[${{context.payload.discussion.title}}](https://github.com/sofa-framework/sofa/discussions/${{context.payload.discussion.number}})** by [${{context.payload.discussion.author.login}}](https://github.com/${{context.payload.discussion.author.login}})"
BOT_NAME: "Discussion announcement"
EMBEDS_TITLE: ${{context.payload.discussion.title}}
EMBEDS_URL: "https://github.com/sofa-framework/sofa/discussions/${{context.payload.discussion.number}}"

95 changes: 95 additions & 0 deletions .github/workflows/post-github-activity.yml
@@ -0,0 +1,95 @@
name: Post - Github activity (PRs, issues, stars)

on:
watch:
types: [started]
issues:
types: [opened]
pull_request:
types: [opened,review_requested,closed]

jobs:
run:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
run: |
pip install python-graphql-client
pip install python-dateutil
pip install requests
working-directory: ${{ github.workspace }}

# PR opened
- name: Run script post-discord-message.py for PR opened (main)
if: (github.event_name == 'pull_request') && (github.pull_request.action == 'opened')
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ":new: PR opened:"
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: "#${{context.payload.pull_request.number}} ${{context.payload.pull_request.title}}"
EMBEDS_URL: "https://github.com/sofa-framework/sofa/pull/${{context.payload.pull_request.number}}"
EMBEDS_DESCRIPTION: "Authored by @${{context.payload.pull_request.author.login}}\nLabels: ${{context.payload.pull_request.labels.name}}"

# PR merged
- name: Run script post-discord-message.py for PR merged
if: (github.event_name == 'pull_request') && (github.pull_request.action == 'closed') && (github.event.pull_request.merged == true)
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ":raised_hands: Thanks @${{context.payload.pull_request.merged_by.login}} for merging PR [#${{context.payload.pull_request.number}}](https://github.com/sofa-framework/sofa/pull/${{context.payload.pull_request.number}}) ${{context.payload.pull_request.title}} (author: @${{context.payload.pull_request.author.login}})"
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: ""
EMBEDS_URL: ""
EMBEDS_DESCRIPTION: ""

# PR review requested event
- name: Run script post-discord-message.py for PR review request
if: (github.event_name == 'pull_request') && (github.pull_request.action == 'review_requested')
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ""
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: ""
EMBEDS_URL: ""
EMBEDS_DESCRIPTION: ":eyeglasses: Review requested: ${{context.payload.pull_request.requested_reviewers}} would you please review [#${{context.payload.pull_request.number}}](https://github.com/sofa-framework/sofa/pull/${{context.payload.pull_request.number}})?"

# Issue related event
- name: Run script post-discord-message.py for Issue opened
if: github.event_name == 'issues'
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ":space_invader: New issue raised"
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: "\"${{context.payload.issue.title}}\" by @${{context.payload.issue.user.login}}"
EMBEDS_URL: "https://github.com/sofa-framework/sofa/issues/${{context.payload.issue.number}}"
EMBEDS_DESCRIPTION: ""

# Star/watch related event
- name: Run script post-discord-message.py for stars
if: github.event_name == 'watch'
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
MESSAGE: ":fire: :fire: Come ON! :fire: :fire: \nOne new :star: for SOFA on Github"
BOT_NAME: "SOFA Github bot"
EMBEDS_TITLE: ""
EMBEDS_URL: ""
EMBEDS_DESCRIPTION: ""

34 changes: 34 additions & 0 deletions .github/workflows/post-pending-discussions.yml
@@ -0,0 +1,34 @@
name: Post - List pending GHD

on:
workflow_dispatch:
schedule:
- cron: '0 6 * * 2,5' # 8 am CET on Tuesday and Friday

jobs:
run:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10' # Use the desired Python version

- name: Install dependencies
run: |
pip install python-graphql-client
pip install python-dateutil
pip install requests
working-directory: ${{ github.workspace }}

- name: Run script post-pending-discussions.py
run: |
python scripts/discord/post-pending-discussions.py
working-directory: ${{ github.workspace }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DISCORD_MAIN_WEBHOOK_URL: ${{ secrets.DISCORD_MAIN_WEBHOOK_URL }}
35 changes: 35 additions & 0 deletions .github/workflows/post-release.yml
@@ -0,0 +1,35 @@
name: Post - Release highlight

on:
release:
types:
- created

jobs:
run:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Install dependencies
run: |
pip install python-graphql-client
pip install python-dateutil
pip install requests
working-directory: ${{ github.workspace }}

- name: Run script post-discord-message.py
run: |
python scripts/discord/post-discord-message.py
working-directory: ${{ github.workspace }}
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_ANNOUNCEMENTS_WEBHOOK_URL }}
MESSAGE: ":loudspeaker: **New SOFA release** :loudspeaker: \n > SOFA ${{context.payload.release.name}} is now available, [check it out](https://github.com/sofa-framework/sofa/releases/tag/${{context.payload.release.tag_name}})! \n > For more, see the [ChangeLog](https://github.com/sofa-framework/sofa/blob/${{context.payload.release.tag_name}}/CHANGELOG.md) \n \n Thanks to all contributors!"
BOT_NAME: "Release announcement"
EMBEDS_TITLE: "SOFA ${{context.payload.release.name}}"
EMBEDS_URL: "https://github.com/sofa-framework/sofa/releases/tag/${{context.payload.release.tag_name}}"
EMBEDS_DESCRIPTION: "New source and binary release of SOFA"


2 changes: 1 addition & 1 deletion .github/workflows/pr-label-checker.yml
@@ -1,5 +1,5 @@
---
name: Label Checker
name: PR check - Labels
on:
pull_request:
types:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-timing-checker.yml
@@ -1,4 +1,4 @@
name: Check PR Age
name: PR check - Age
on:
pull_request:
types:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-title-checker.yml
@@ -1,4 +1,4 @@
name: Pull Request Title Check
name: PR check - Title
on:
pull_request:
types: [opened, synchronize, edited, reopened]
Expand Down
35 changes: 35 additions & 0 deletions scripts/discord/post-discord-message.py
@@ -0,0 +1,35 @@
#!python
import os
import requests


# Recover all info as env var
discord_token = os.environ['DISCORD_WEBHOOK_URL']
message = os.environ['MESSAGE']
bot_name = os.environ['BOT_NAME']
embeds_title = os.environ['EMBEDS_TITLE']
embeds_url = os.environ['EMBEDS_URL']
embeds_description = os.environ['EMBEDS_DESCRIPTION']


# Format message
data = {
"content" : message,
"username" : bot_name
}

#leave this out if you dont want an embed
data["embeds"] = [
{
"description" : embeds_description,
"title" : embeds_title,
"type" : "rich",
"url" : embeds_url,
"color" : "15224347"
}
]

# Send message to Discord
response = requests.post(discord_token, json=data)
print("Status: "+str(response.status_code)+"\nReason: "+str(response.reason)+"\nText: "+str(response.text))

0 comments on commit 2e3a104

Please sign in to comment.