Skip to content

Commit 3d13e7c

Browse files
committed
feat: support github discussions
Signed-off-by: Sebastian Beltran <[email protected]>
1 parent 9cbb57c commit 3d13e7c

File tree

3 files changed

+151
-8
lines changed

3 files changed

+151
-8
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@actions/github": "^6.0.1",
2828
"@hackmd/api": "^2.5.0",
2929
"@js-temporal/polyfill": "^0.5.1",
30+
"@octokit/graphql": "^9.0.1",
3031
"ejs": "^3.1.10",
3132
"safe-parse-list": "^0.1.1"
3233
},

run.js

Lines changed: 66 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')
@@ -97,6 +98,71 @@ const pkg = require('./package.json')
9798
}
9899

99100
const agendaIssues = await agenda.fetchAgendaItems(client, repos, agendaLabel)
101+
102+
for (const r of repos) {
103+
let hasNextPage = true
104+
let endCursor = null
105+
do {
106+
const query = `
107+
query($owner: String!, $name: String!, $after: String) {
108+
repository(owner: $owner, name: $name) {
109+
discussions(first: 100, after: $after) {
110+
pageInfo {
111+
endCursor
112+
hasNextPage
113+
}
114+
edges {
115+
cursor
116+
node {
117+
id
118+
title
119+
url
120+
labels(first: 10) {
121+
nodes {
122+
color
123+
name
124+
}
125+
}
126+
}
127+
}
128+
}
129+
}
130+
}
131+
`
132+
const variables = {
133+
owner: r.owner,
134+
name: r.repo,
135+
after: endCursor
136+
}
137+
const _agendaDiscussions = await graphql(query, {
138+
...variables,
139+
headers: {
140+
authorization: `token ${token}`
141+
}
142+
})
143+
const discussions = _agendaDiscussions?.repository?.discussions
144+
if (discussions) {
145+
const { edges, pageInfo } = discussions
146+
for (const edge of edges) {
147+
const labels = edge.node?.labels.nodes
148+
if (Array.isArray(labels) && labels.some(label => label.name === agendaLabel)) {
149+
console.log(`Adding Discussion: ${edge.node.url}`)
150+
agendaIssues.push({
151+
id: edge.node.id,
152+
html_url: edge.node.url,
153+
title: edge.node.title
154+
})
155+
}
156+
}
157+
hasNextPage = pageInfo.hasNextPage
158+
endCursor = pageInfo.endCursor
159+
} else {
160+
hasNextPage = false
161+
}
162+
} while (hasNextPage)
163+
}
164+
165+
console.log(`Found ${agendaIssues.length} total issues for agenda`)
100166

101167
const opts = {
102168
...repo,

0 commit comments

Comments
 (0)