Skip to content

Commit

Permalink
actions: notify teams upon new discussion in category
Browse files Browse the repository at this point in the history
  • Loading branch information
walesch-yan authored and marcus-oscarsson committed Sep 18, 2024
1 parent efa4d9c commit 39a5bed
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/discussions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
# This workflow notifies working groups about new discussions in their corresponding
# categories, by mentioning the Team in a first comment.
# It is necessary since GitHub doesn't support subsriptions to discussion categories
# see related feature request: https://github.com/orgs/community/discussions/3951
# If GitHub implements this feature, this workflow becomes obsolete.

name: Notify Team on New Discussion
"on":
discussion:
types: [created]

jobs:
notify_team:
runs-on: ubuntu-latest
steps:
- name: Notify Team
uses: actions/github-script@v7
with:
github-token: ${{ secrets.DISCUSSIONS_NOTIFICATIONS }}
script: |
const discussion = context.payload.discussion;
const category = discussion.category.name;
const query = `
query($discussionNumber: Int!) {
repository(
owner: "${context.repo.owner}",
name: "${context.repo.repo}"
) {
discussion(number: $discussionNumber) {
id
}
}
}
`;
const mutation = `
mutation($discussionId: ID!, $body: String!) {
addDiscussionComment(
input: {discussionId: $discussionId, body: $body}
) {
comment {
id
body
}
}
}
`;
const response = await github.graphql(query, {
discussionNumber: discussion.number
});
const discussionId = response.repository.discussion.id;
const teams = await github.rest.teams.list({
org: context.repo.owner,
});
const team = teams.data.find(t => t.name === category);
if (team) {
const teamMention = `${context.repo.owner}/${team.slug}`;
const commentBody = `@${teamMention} A new discussion was created in the`
+ ` "${category}" category: ${discussion.html_url}`;
await github.graphql(mutation, {
discussionId: discussionId,
body: commentBody
});
} else {
console.log(`No team found for category: ${category}`);
}

0 comments on commit 39a5bed

Please sign in to comment.