17
17
with :
18
18
node-version : ' 18'
19
19
- name : Install dependencies
20
- run : npm install @octokit/core
20
+ run : npm install @octokit/core
21
21
- name : Adding Issues
22
22
uses : actions/github-script@v6
23
23
env :
@@ -30,23 +30,25 @@ jobs:
30
30
MY_TOKEN : ${{ secrets.AUTH_TOKEN }}
31
31
with :
32
32
script : |
33
-
34
33
const octokit = require('@octokit/core').Octokit
35
34
const mygithub = new octokit({
36
35
request: { fetch: fetch,},
37
36
auth: process.env.MY_TOKEN
38
37
});
39
-
38
+
40
39
const repoNames = process.env.REPO_NAMES;
41
40
const placeholder = process.env.PLACEHOLDER;
42
41
console.log("Placeholder:" + placeholder);
43
42
43
+ const octokit = require('@octokit/core').Octokit
44
+ const mygithub = new octokit({ auth: process.env.MY_TOKEN })
45
+
44
46
let repositories = repoNames.split(",")
45
47
let targetLabel = encodeURIComponent(process.env.OCWM_LABEL);
46
48
let appendLabel = encodeURIComponent(process.env.AGENDA_LABEL);
47
49
48
50
console.log("Repositories:" + repositories);
49
-
51
+
50
52
console.log(`GET /repos/${process.env.OWNER}/${process.env.REPO}/issues?labels=${targetLabel}&per_page=1`);
51
53
52
54
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:
56
58
57
59
for (let r = 0; r < repositories.length; r++) {
58
60
console.log(`GET /repos/${process.env.OWNER}/${repositories[r]}/issues?labels=${appendLabel}`);
59
-
60
61
const { data: items2add } = await mygithub.request(`GET /repos/${process.env.OWNER}/${repositories[r]}/issues?labels=${appendLabel}`, {
61
62
});
63
+ console.log("Issues to add:" + JSON.stringify(items2add));
62
64
63
- console.log("Items to add:" + JSON.stringify(items2add));
64
65
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) {
73
95
let startIndex = parseInt(JSON.stringify(body.indexOf(placeholder)))
74
96
let json_text = JSON.stringify(body.substring(0, startIndex - 1) + `\n| ${url} - ${title} | ${author} |\r\n` + body.substring(startIndex, body.length));
75
97
body = JSON.parse(json_text);
76
98
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
+ })
77
113
}
78
114
}
79
115
80
- if (changesFlag){
81
- let template = JSON.stringify(JSON.stringify(body));
82
- let parsed = JSON.parse(JSON.parse(template));
83
116
84
- console.log(`PATCH /repos/${process.env.OWNER}/${process.env.REPO}/issues/${workMeetings[0].number}`);
85
117
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");
91
121
}
92
- }
122
+
123
+ }
0 commit comments