Skip to content

Add new discussions to project #9

Add new discussions to project

Add new discussions to project #9

name: Add new organization discussions to project
on:
discussion:
types: [created, reopened]
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: Add discussion to project
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate_token.outputs.token }}
script: |
const fs = require('fs');
const eventPayload = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8'));
console.log('Event payload:', JSON.stringify(eventPayload, null, 2));
const orgLogin = eventPayload.organization.login;
const discussion = eventPayload.discussion;
console.log(`Organization: ${orgLogin}, Discussion Number: ${discussion.number}`);
const query = `
mutation($projectId:ID!, $contentId:ID!) {
addProjectV2ItemById(input: {projectId: $projectId, contentId: $contentId}) {
item {
id
}
}
}
`;
try {
const result = await github.graphql(query, {
projectId: "3",
contentId: discussion.node_id
});
console.log('Added to project:', JSON.stringify(result, null, 2));
return result.addProjectV2ItemById.item.id;
} catch (error) {
console.error('Error:', error);
throw error;
}