OCWM Pre-Meeting Check #18
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: OCWM Pre-Meeting Check | |
on: | |
schedule: | |
- cron: '50 21 * * 1' # Runs at 11:50 AM PT on the 3rd Monday of the month | |
jobs: | |
check_agenda: | |
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 GitHub 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: Check Latest OCWM Issue | |
id: check_issue | |
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 }} | |
TEMPLATE_PATH: '.github/ISSUE_TEMPLATE/open_community_working_meeting.md' | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_GEN_NOTIF }} | |
with: | |
script: | | |
const fs = require('fs'); | |
const octokit = require('@octokit/core').Octokit; | |
const mygithub = new octokit({ | |
request: { fetch: fetch, }, | |
auth: process.env.MY_TOKEN | |
}); | |
// Read the template from the markdown file | |
const templateContent = fs.readFileSync(process.env.TEMPLATE_PATH, 'utf8'); | |
// Fetch the latest issue with OCWM_LABEL | |
const { data: issues } = await mygithub.request(`GET /repos/${process.env.OWNER}/${process.env.REPO}/issues?labels=${encodeURIComponent(process.env.OCWM_LABEL)}&per_page=1`); | |
if (issues.length === 0) { | |
console.log("No open community working meeting issues found."); | |
return; | |
} | |
const latestIssue = issues[0]; | |
const issueBody = latestIssue.body; | |
// Check if the issue body matches the template | |
if (issueBody.includes(templateContent)) { | |
console.log("Template matched, cancelling the meeting."); | |
// Add a comment to the issue | |
await mygithub.request(`POST /repos/${process.env.OWNER}/${process.env.REPO}/issues/${latestIssue.number}/comments`, { | |
body: "The meeting has been cancelled as there is no agenda for today. Thanks everyone!" | |
}); | |
// Send a notification to Slack | |
const slackPayload = { | |
text: `The meeting has been cancelled as there is no agenda for today. Thanks everyone!` | |
}; | |
await fetch(process.env.SLACK_WEBHOOK, { | |
method: 'POST', | |
headers: { 'Content-Type': 'application/json' }, | |
body: JSON.stringify(slackPayload) | |
}); | |
} else { | |
console.log("Agenda found. Meeting will proceed."); | |
} |