Send reminders to join the OCWM the same day #53
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Send reminders to join the OCWM the same day | |
on: | |
schedule: | |
- cron: '0 15 * * 1' # Runs every Monday at 15:00 | |
repository_dispatch: | |
types: ocwm-reminders | |
jobs: | |
ocwm-reminders: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up Node 20 | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Get Token | |
uses: actions/create-github-app-token@v1 | |
id: get_workflow_token | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.PRIVATE_KEY }} | |
- name: Install dependencies | |
run: npm install @octokit/[email protected] | |
# Step to check if today is the third Monday | |
- name: Check if today is the third Monday | |
id: check-third-monday | |
run: | | |
day=$(date +%d) | |
dow=$(date +%u) # Day of the week (1 = Monday, ..., 7 = Sunday) | |
# Check if the day is between 15th and 21st, and if it's Monday (1) | |
if [ "$dow" -ne 1 ]; then | |
echo "Not a Monday, exiting..." | |
echo "::set-output name=is-third-monday::false" | |
exit 0 | |
fi | |
if [ "$day" -ge 15 ] && [ "$day" -le 21 ]; then | |
echo "This is the third Monday of the month!" | |
echo "::set-output name=is-third-monday::true" | |
else | |
echo "Not the third Monday, exiting..." | |
echo "::set-output name=is-third-monday::false" | |
exit 0 | |
fi | |
- name: Send reminders | |
if: steps.check-third-monday.outputs.is-third-monday == 'true' | |
uses: actions/github-script@v7 | |
env: | |
MY_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | |
OWNER: ${{ vars.ORGANISATION }} | |
REPO: 'community' | |
OCWM_LABEL: ${{ vars.OCWM_LABEL }} | |
SLACK_WEBHOOK: ${{ vars.SLACK_WEBHOOK_REMINDER }} | |
with: | |
script: | | |
const octokit = require('@octokit/core').Octokit; | |
const mygithub = new octokit({ | |
request: { fetch: fetch,}, | |
auth: process.env.MY_TOKEN | |
}); | |
let targetLabel = encodeURIComponent(process.env.OCWM_LABEL); | |
const { data: workMeetings } = await mygithub.request(`GET /repos/${process.env.OWNER}/${process.env.REPO}/issues?labels=${targetLabel}&per_page=1`, { | |
}) | |
const issueNumber = workMeetings[0].number | |
const newTitle = workMeetings[0].title; | |
const issueDate = newTitle.replace(/Open Community Working Meeting /g, ""); | |
// Notify Slack | |
const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK; | |
const SLACK_MESSAGE = `{ | |
"issue": "https://github.com/${process.env.OWNER}/${process.env.REPO}/issues/${issueNumber}", | |
"date": "${issueDate}" | |
}`; | |
await fetch(SLACK_WEBHOOK_URL, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: SLACK_MESSAGE, | |
}); |