Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GitHub] Add new actions to connect GitHub and Discord #4445

Merged
merged 14 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/post-agenda-sofa-dev-meeting.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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))

Loading
Loading