Skip to content

Commit 9cdd87d

Browse files
authored
Merge pull request #444 from json-schema-org/benjagm-update-issue-collector
Update ocwm-issue-collector to add support for github discussions
2 parents 65b6c37 + e6fdd76 commit 9cdd87d

File tree

1 file changed

+55
-24
lines changed

1 file changed

+55
-24
lines changed

.github/workflows/ocwm-issue-collector.yml

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
with:
1818
node-version: '18'
1919
- name: Install dependencies
20-
run: npm install @octokit/core
20+
run: npm install @octokit/core
2121
- name: Adding Issues
2222
uses: actions/github-script@v6
2323
env:
@@ -30,23 +30,25 @@ jobs:
3030
MY_TOKEN: ${{ secrets.AUTH_TOKEN }}
3131
with:
3232
script: |
33-
3433
const octokit = require('@octokit/core').Octokit
3534
const mygithub = new octokit({
3635
request: { fetch: fetch,},
3736
auth: process.env.MY_TOKEN
3837
});
39-
38+
4039
const repoNames = process.env.REPO_NAMES;
4140
const placeholder = process.env.PLACEHOLDER;
4241
console.log("Placeholder:" + placeholder);
4342
43+
const octokit = require('@octokit/core').Octokit
44+
const mygithub = new octokit({ auth: process.env.MY_TOKEN })
45+
4446
let repositories = repoNames.split(",")
4547
let targetLabel = encodeURIComponent(process.env.OCWM_LABEL);
4648
let appendLabel = encodeURIComponent(process.env.AGENDA_LABEL);
4749
4850
console.log("Repositories:" + repositories);
49-
51+
5052
console.log(`GET /repos/${process.env.OWNER}/${process.env.REPO}/issues?labels=${targetLabel}&per_page=1`);
5153
5254
const { data: workMeetings } = await mygithub.request(`GET /repos/${process.env.OWNER}/${process.env.REPO}/issues?labels=${targetLabel}&per_page=1`, {
@@ -56,37 +58,66 @@ jobs:
5658
5759
for (let r = 0; r < repositories.length; r++) {
5860
console.log(`GET /repos/${process.env.OWNER}/${repositories[r]}/issues?labels=${appendLabel}`);
59-
6061
const { data: items2add } = await mygithub.request(`GET /repos/${process.env.OWNER}/${repositories[r]}/issues?labels=${appendLabel}`, {
6162
});
63+
console.log("Issues to add:" + JSON.stringify(items2add));
6264
63-
console.log("Items to add:" + JSON.stringify(items2add));
6465
65-
let body = workMeetings[0].body;
66-
let changesFlag = false;
67-
for (let i = 0; i < items2add.length; i++) {
68-
let url = items2add[i].html_url;
69-
let author = "@" + items2add[i].user.login;
70-
let title = items2add[i].title;
71-
let search = parseInt(JSON.stringify(body).search(url));
72-
if (search === -1) {
66+
const { data: discussions } = await mygithub.request(`GET /repos/${process.env.OWNER}/${repositories[r]}/discussions?labels=${appendLabel}`, {
67+
});
68+
console.log("Discussions to add:" + JSON.stringify(discussions));
69+
70+
try {
71+
let body = workMeetings[0].body;
72+
let changesFlag = false;
73+
74+
// Loop through issues to add them to the agenda
75+
for (let i = 0; i < items2add.length; i++) {
76+
let url = items2add[i].html_url;
77+
let author = "@" + items2add[i].user.login;
78+
let title = items2add[i].title;
79+
let search = parseInt(JSON.stringify(body).search(url));
80+
if (search === -1) {
81+
let startIndex = parseInt(JSON.stringify(body.indexOf(placeholder)))
82+
let json_text = JSON.stringify(body.substring(0, startIndex - 1) + `\n| ${url} - ${title} | ${author} |\r\n` + body.substring(startIndex, body.length));
83+
body = JSON.parse(json_text);
84+
changesFlag = true;
85+
}
86+
}
87+
88+
// Loop through discussions to add them to the agenda
89+
for (let i = 0; i < discussions.length; i++) {
90+
let url = discussions[i].html_url;
91+
let author = "@" + discussions[i].user.login;
92+
let title = discussions[i].title;
93+
let search = parseInt(JSON.stringify(body).search(url));
94+
if (search === -1) {
7395
let startIndex = parseInt(JSON.stringify(body.indexOf(placeholder)))
7496
let json_text = JSON.stringify(body.substring(0, startIndex - 1) + `\n| ${url} - ${title} | ${author} |\r\n` + body.substring(startIndex, body.length));
7597
body = JSON.parse(json_text);
7698
changesFlag = true;
99+
}
100+
}
101+
102+
if (changesFlag){
103+
let template = JSON.stringify(JSON.stringify(body));
104+
let parsed = JSON.parse(JSON.parse(template));
105+
106+
console.log(`PATCH /repos/${process.env.OWNER}/${process.env.REPO}/issues/${workMeetings[0].number}`);
107+
108+
await mygithub.request(`PATCH /repos/${process.env.OWNER}/${process.env.REPO}/issues/${workMeetings[0].number}`, {
109+
body: parsed,
110+
milestone: null,
111+
state: 'open',
112+
})
77113
}
78114
}
79115
80-
if (changesFlag){
81-
let template = JSON.stringify(JSON.stringify(body));
82-
let parsed = JSON.parse(JSON.parse(template));
83116
84-
console.log(`PATCH /repos/${process.env.OWNER}/${process.env.REPO}/issues/${workMeetings[0].number}`);
85117
86-
await mygithub.request(`PATCH /repos/${process.env.OWNER}/${process.env.REPO}/issues/${workMeetings[0].number}`, {
87-
body: parsed,
88-
milestone: null,
89-
state: 'open',
90-
})
118+
catch (err) {
119+
console.error("Error:"+err.message);
120+
console.log("There is no OCWM available");
91121
}
92-
}
122+
123+
}

0 commit comments

Comments
 (0)