-
-
Notifications
You must be signed in to change notification settings - Fork 41
176 lines (154 loc) · 7.17 KB
/
ocwm-issue-collector.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: Search for issues and PR labeled 'agenda' and add them to the agenda
on:
schedule:
- cron: '0 1 * * 1' # Runs at 1:00 AM every Monday
repository_dispatch:
types: add-issues-ocwm
jobs:
search_and_add:
runs-on: ubuntu-latest
steps:
- 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: Adding Issues
id: add-issues
if: steps.check-third-monday.outputs.is-third-monday == 'true'
uses: actions/github-script@v7
env:
PLACEHOLDER: '<!-- | [TOPIC] [IssuePRDiscussion] | [owner] | -->'
OWNER: ${{ vars.ORGANISATION }}
REPO: 'community'
REPO_NAMES: ${{ vars.REPOSITORIES }}
AGENDA_LABEL: ${{ vars.AGENDA_LABEL }}
OCWM_LABEL: ${{ vars.OCWM_LABEL }}
MY_TOKEN: ${{ steps.get_workflow_token.outputs.token }}
with:
script: |
const octokit = require('@octokit/core').Octokit
const mygithub = new octokit({
request: { fetch: fetch,},
auth: process.env.MY_TOKEN
});
const repoNames = process.env.REPO_NAMES;
const placeholder = process.env.PLACEHOLDER;
console.log("Placeholder:" + placeholder);
let repositories = repoNames.split(",")
let targetLabel = encodeURIComponent(process.env.OCWM_LABEL);
let appendLabel = encodeURIComponent(process.env.AGENDA_LABEL);
console.log("Repositories:" + repositories);
console.log(`GET /repos/${process.env.OWNER}/${process.env.REPO}/issues?labels=${targetLabel}&per_page=1`);
const { data: workMeetings } = await mygithub.request(`GET /repos/${process.env.OWNER}/${process.env.REPO}/issues?labels=${targetLabel}&per_page=1`, {
})
console.log("workMeetings:" + JSON.stringify(workMeetings));
for (let r = 0; r < repositories.length; r++) {
const { data: items2add } = await mygithub.request(`GET /repos/${process.env.OWNER}/${repositories[r]}/issues?labels=${appendLabel}`);
console.log("Issues to add:" + JSON.stringify(items2add));
const query = `
query {
search(query: "repo:${process.env.OWNER}/${repositories[r]} is:open label:${appendLabel}", type: DISCUSSION, first: 5) {
edges {
node {
... on Discussion {
id
title
body
resourcePath
author {
login
}
}
}
}
}
}`;
const response = await mygithub.graphql(query, {});
console.log("Response:" + JSON.stringify(response));
const discussions = response.search.edges;
console.log("Discussions to add:" + JSON.stringify(discussions));
try {
let body = workMeetings[0].body;
let changesFlag = false;
// Loop through issues to add them to the agenda
for (let i = 0; i < items2add.length; i++) {
let url = items2add[i].html_url;
let author = "@" + items2add[i].user.login;
let title = items2add[i].title;
let search = parseInt(JSON.stringify(body).search(url));
if (search === -1) {
let startIndex = parseInt(JSON.stringify(body.indexOf(placeholder)))
let json_text = JSON.stringify(body.substring(0, startIndex - 1) + `\n| ${url} - ${title} | ${author} |\r\n` + body.substring(startIndex, body.length));
body = JSON.parse(json_text);
changesFlag = true;
await mygithub.request(`DELETE /repos/${process.env.OWNER}/${repositories[r]}/issues/${items2add[i].number}/labels/${appendLabel}`);
}
}
// Loop through discussions to add them to the agenda
for (let i = 0; i < discussions.length; i++) {
let url = "https://github.com/" + discussions[i].node.resourcePath;
let author = "@" + discussions[i].node.author.login;
let title = discussions[i].node.title;
let search = parseInt(JSON.stringify(body).search(url));
if (search === -1) {
let startIndex = parseInt(JSON.stringify(body.indexOf(placeholder)))
let json_text = JSON.stringify(body.substring(0, startIndex - 1) + `\n| ${url} - ${title} | ${author} |\r\n` + body.substring(startIndex, body.length));
body = JSON.parse(json_text);
changesFlag = true;
}
}
if (changesFlag){
let template = JSON.stringify(JSON.stringify(body));
let parsed = JSON.parse(JSON.parse(template));
console.log(`PATCH /repos/${process.env.OWNER}/${process.env.REPO}/issues/${workMeetings[0].number}`);
const { data: label } = await mygithub.request(`GET /repos/${process.env.OWNER}/${process.env.REPO}/labels/${process.env.AGENDA_LABEL}`);
await mygithub.request(`PATCH /repos/${process.env.OWNER}/${process.env.REPO}/issues/${workMeetings[0].number}`, {
body: parsed,
milestone: null,
state: 'open',
})
for (let i = 0; i < discussions.length; i++) {
await mygithub.graphql(`
mutation {
removeLabelsFromLabelable(input: {labelIds: ["${label.node_id}"], labelableId: "${discussions[i].node.id}"}) {
clientMutationId
}
}
`);
}
}
}
catch (err) {
console.error("Error:"+err.message);
console.log("There is no OCWM available");
}
}