Create OCWM Monthly #71
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: Create OCWM Monthly | |
on: | |
schedule: | |
- cron: "0 9 15-21 * 2" # Runs at 9:00 AM on the 3rd Tuesday of the month | |
repository_dispatch: | |
types: ocwm-creator | |
jobs: | |
create-issue: | |
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: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.8' | |
- name: Generate Issue Title | |
id: create-title | |
run: | | |
date=$(date -u -d "6 days" +%Y-%m-%d) | |
echo "title=Open Community Working Meeting ${date} - 12:00 PT" >> "$GITHUB_OUTPUT" | |
- name: Create Issue using Template | |
id: create-issue | |
uses: peter-evans/create-issue-from-file@v5 | |
with: | |
title: ${{ steps.create-title.outputs.title }} | |
content-filepath: .github/ISSUE_TEMPLATE/open_community_working_meeting.md | |
labels: 'Working Meeting' | |
token: ${{ steps.get_workflow_token.outputs.token }} | |
- name: Install dependencies | |
run: npm install @octokit/[email protected] | |
- name: Update Issue Body | |
uses: actions/github-script@v7 | |
env: | |
MY_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | |
SLACK_WEBHOOK: ${{ vars.SLACK_WEBHOOK }} | |
with: | |
script: | | |
const octokit = require('@octokit/core').Octokit; | |
const mygithub = new octokit({ | |
request: { fetch: fetch,}, | |
auth: process.env.MY_TOKEN | |
}); | |
console.log("Token:" + process.env.MY_TOKEN); | |
const ocwmnumber = ${{ steps.create-issue.outputs.issue-number }}; | |
const { data: ocwmissue } = await mygithub.request(`GET /repos/${context.repo.owner}/${context.repo.repo}/issues/${ ocwmnumber }`, { | |
}) | |
console.log("OCWM Issue:" + JSON.stringify(ocwmissue)); | |
const newBody = `## ${ocwmissue.title}\n\n${ocwmissue.body.split('\n').slice(6).join('\n')}`; | |
await mygithub.request(`PATCH /repos/${context.repo.owner}/${context.repo.repo}/issues/${ ocwmnumber }`, { | |
body: newBody, | |
milestone: null, | |
state: 'open', | |
}) | |
const newTitle = ocwmissue.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/${context.repo.owner}/${context.repo.repo}/issues/${ocwmnumber}", | |
"date": "${issueDate}" | |
}`; | |
await fetch(SLACK_WEBHOOK_URL, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: SLACK_MESSAGE, | |
}); |