Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ inputs:
orgs:
description: 'An optional list of org in the format: <org>,<org>'
required: false
discussions:
description: 'Disable/Active discussions fetching'
default: 'true'
required: false
outputs:
issueNumber:
description: 'If an issue was created, this will be its number'
Expand Down
80 changes: 78 additions & 2 deletions lib/agenda.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const { graphql } = require('@octokit/graphql')

/**
* get agenda issues and PRs from repositories
* @param {Object} client - GitHub client
Expand Down Expand Up @@ -38,7 +40,7 @@ async function fetchAgendaItems (client, repos, agendaLabel) {
labels: agendaLabel,
per_page: 100
})).filter(pr => pr.labels.find(label => label.name === agendaLabel) &&
!(agendaIssues.find((i) => i.url === pr.url))) // workaround for flaky GH API/SDK behavior where sometimes the issue endpoint loads PRs
!(agendaIssues.find((i) => i.url === pr.url))) // workaround for flaky GH API/SDK behavior where sometimes the issue endpoint loads PRs

console.log(`Fetching PRs for ${r.owner}/${r.repo}: Found ${_agendaPrs.length}`)

Expand All @@ -52,6 +54,80 @@ async function fetchAgendaItems (client, repos, agendaLabel) {
return agendaIssues
}

async function fetchDiscussionsItems (repos, agendaLabel, token) {
const agendaDiscussions = []
for (const r of repos) {
let hasNextPage = true
let endCursor = null
do {
const query = `
query($owner: String!, $name: String!, $after: String) {
repository(owner: $owner, name: $name) {
discussions(first: 100, after: $after) {
pageInfo {
endCursor
hasNextPage
}
edges {
cursor
node {
id
title
url
labels(first: 10) {
nodes {
color
name
}
}
}
}
}
}
}
`
const variables = {
owner: r.owner,
name: r.repo,
after: endCursor
}

const _agendaDiscussions = await graphql(query, {
...variables,
headers: {
authorization: `token ${token}`
}
})

const discussions = _agendaDiscussions?.repository?.discussions

if (discussions) {
const { edges, pageInfo } = discussions
for (const edge of edges) {
const labels = edge.node?.labels.nodes
if (Array.isArray(labels) && labels.some(label => label.name === agendaLabel)) {
console.log(`Adding Discussion: ${edge.node.url}`)
agendaDiscussions.push({
id: edge.node.id,
html_url: edge.node.url,
title: edge.node.title
})
}
}
hasNextPage = pageInfo.hasNextPage
endCursor = pageInfo.endCursor
} else {
hasNextPage = false
}
} while (hasNextPage)
}

console.log(`Found ${agendaDiscussions.length} total discussions for agenda`)

return agendaDiscussions
}

module.exports = {
fetchAgendaItems
fetchAgendaItems,
fetchDiscussionsItems
}
105 changes: 99 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@actions/github": "^6.0.1",
"@hackmd/api": "^2.5.0",
"@js-temporal/polyfill": "^0.5.1",
"@octokit/graphql": "^7.0.2",
"ejs": "^3.1.10",
"safe-parse-list": "^0.1.1"
},
Expand Down
14 changes: 12 additions & 2 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const pkg = require('./package.json')
const issueTitle = core.getInput('issueTitle')
const issueTemplate = core.getInput('issueTemplate')

const discussions = core.getBooleanInput('discussions')

// variables we use for notes
const createNotes = core.getInput('createNotes')
const notesUserTemplate = core.getInput('notesTemplate')
Expand Down Expand Up @@ -96,7 +98,15 @@ const pkg = require('./package.json')
}
}

const agendaIssues = await agenda.fetchAgendaItems(client, repos, agendaLabel)
const agendaItems = []
agendaItems.push(...await agenda.fetchAgendaItems(client, repos, agendaLabel))

if (discussions) {
const agendaDiscussions = await agenda.fetchDiscussionsItems(repos, agendaLabel, token)
agendaItems.push(...agendaDiscussions)
}

console.log(`Found ${agendaItems.length} total items for agenda`)

const opts = {
...repo,
Expand All @@ -106,7 +116,7 @@ const pkg = require('./package.json')
createWithin,
agendaLabel,
meetingLink,
agendaIssues,
agendaIssues: agendaItems,
issueTitle: titleTemplate
}

Expand Down