Add new discussions to project #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Add new organization discussions to project | |
on: | |
discussion: | |
types: [created] | |
jobs: | |
add-to-project: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Generate token | |
id: generate_token | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{ secrets.APP_ID }} | |
private_key: ${{ secrets.APP_PRIVATE_KEY }} | |
- name: Get discussion details | |
id: get_discussion | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ steps.generate_token.outputs.token }} | |
script: | | |
console.log('Event payload:', JSON.stringify(github.context.payload)); | |
const query = `query($org: String!) { | |
organization(login: $org) { | |
discussionCategories(first: 10) { | |
nodes { | |
discussions(first: 1, orderBy: {field: CREATED_AT, direction: DESC}) { | |
nodes { | |
id | |
} | |
} | |
} | |
} | |
} | |
}`; | |
const variables = { | |
org: context.payload.organization.login | |
}; | |
console.log('GraphQL variables:', JSON.stringify(variables)); | |
try { | |
const result = await github.graphql(query, variables); | |
console.log('GraphQL result:', JSON.stringify(result)); | |
// Find the most recently created discussion | |
const discussions = result.organization.discussionCategories.nodes.flatMap(category => category.discussions.nodes); | |
const mostRecentDiscussion = discussions.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))[0]; | |
if (mostRecentDiscussion) { | |
return mostRecentDiscussion.id; | |
} else { | |
throw new Error('No discussions found'); | |
} | |
} catch (error) { | |
console.error('GraphQL Error:', error); | |
throw error; | |
} | |
- name: Add to Project | |
uses: actions/[email protected] | |
with: | |
project-url: https://github.com/orgs/stampchain-io/projects/3 | |
github-token: ${{ steps.generate_token.outputs.token }} | |
content-id: ${{ steps.get_discussion.outputs.result }} |