-
-
Notifications
You must be signed in to change notification settings - Fork 40
129 lines (107 loc) · 4.4 KB
/
ocwm-creator.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Create OCWM Monthly
on:
schedule:
- cron: "0 23 * * 1" # Runs at 11:00 PM every Monday
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: |
# Get the first day of the next month
next_month=$(date -u -d "$(date +%Y-%m-01) +1 month" +%Y-%m-01)
# Find the first Monday of the next month
first_monday=$(date -u -d "$next_month +$(( (8 - $(date -u -d "$next_month" +%u)) % 7 )) days" +%Y-%m-%d)
# Calculate the third Monday by adding 14 days to the first Monday
third_monday=$(date -u -d "$first_monday +14 days" +%Y-%m-%d)
# Output the issue title with the third Monday's date
echo "title=Open Community Working Meeting ${third_monday} - 12:00 PT" >> "$GITHUB_OUTPUT"
# Step to check if it's the third Tuesday of the month
- name: Check if today is the third Tuesday
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: Create Issue using Template
id: create-issue
if: steps.check-third-tuesday.outputs.is-third-monday == 'true'
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
if: steps.check-third-tuesday.outputs.is-third-tuesday == 'true'
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,
});