Skip to content

Commit 2f3e343

Browse files
committed
feat: support github discussions
Signed-off-by: Sebastian Beltran <[email protected]>
1 parent a97125a commit 2f3e343

File tree

3 files changed

+167
-8
lines changed

3 files changed

+167
-8
lines changed

package-lock.json

Lines changed: 100 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
"@actions/core": "^1.11.1",
2525
"@actions/github": "^6.0.1",
2626
"@hackmd/api": "^2.5.0",
27-
"ejs": "^3.1.10",
2827
"@js-temporal/polyfill": "^0.5.1",
28+
"@octokit/graphql": "^9.0.1",
29+
"ejs": "^3.1.10",
2930
"safe-parse-list": "^0.1.1"
3031
},
3132
"devDependencies": {

run.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22
const core = require('@actions/core')
33
const { getOctokit, context } = require('@actions/github')
4+
const { graphql } = require('@octokit/graphql')
45
const list = require('safe-parse-list')
56
const ejs = require('ejs')
67
const meetings = require('./lib/meetings')
@@ -103,14 +104,78 @@ const pkg = require('./package.json')
103104
state: 'open',
104105
labels: agendaLabel
105106
})
107+
106108
console.log(`Fetching issues for ${r.owner}/${r.repo}: Found ${_agendaIssues.length}`)
109+
107110
for (const i of _agendaIssues) {
108111
console.log(`Adding Issue: ${i.url}`)
109112
if (!agendaIssues.find((ii) => ii.url === i.url)) {
110113
agendaIssues.push(i)
111114
}
112115
}
116+
117+
let hasNextPage = true
118+
let endCursor = null
119+
do {
120+
const query = `
121+
query($owner: String!, $name: String!, $after: String) {
122+
repository(owner: $owner, name: $name) {
123+
discussions(first: 100, after: $after) {
124+
pageInfo {
125+
endCursor
126+
hasNextPage
127+
}
128+
edges {
129+
cursor
130+
node {
131+
id
132+
title
133+
url
134+
labels(first: 10) {
135+
nodes {
136+
color
137+
name
138+
}
139+
}
140+
}
141+
}
142+
}
143+
}
144+
}
145+
`
146+
const variables = {
147+
owner: r.owner,
148+
name: r.repo,
149+
after: endCursor
150+
}
151+
const _agendaDiscussions = await graphql(query, {
152+
...variables,
153+
headers: {
154+
authorization: `token ${token}`
155+
}
156+
})
157+
const discussions = _agendaDiscussions?.repository?.discussions
158+
if (discussions) {
159+
const { edges, pageInfo } = discussions
160+
for (const edge of edges) {
161+
const labels = edge.node?.labels.nodes
162+
if (Array.isArray(labels) && labels.some(label => label.name === agendaLabel)) {
163+
console.log(`Adding Discussion: ${edge.node.url}`)
164+
agendaIssues.push({
165+
id: edge.node.id,
166+
html_url: edge.node.url,
167+
title: edge.node.title
168+
})
169+
}
170+
}
171+
hasNextPage = pageInfo.hasNextPage
172+
endCursor = pageInfo.endCursor
173+
} else {
174+
hasNextPage = false
175+
}
176+
} while (hasNextPage)
113177
}
178+
114179
console.log(`Found ${agendaIssues.length} total issues for agenda`)
115180

116181
const opts = {

0 commit comments

Comments
 (0)