Skip to content

Add new discussions to project #38

Add new discussions to project

Add new discussions to project #38

name: Add new discussions to project
on:
discussion:
types: [created, reopened]
jobs:
add-to-project:
name: Add discussion 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 to project
uses: actions/github-script@v7
with:
github-token: ${{ steps.generate_token.outputs.token }}
script: |
const projectId = 'PVT_kwDOCAGLAM4Anzfw';
const discussionId = context.payload.discussion.node_id;
console.log(`Adding discussion ${discussionId} to project ${projectId}`);
try {
const response = await github.graphql(`
mutation($projectId: ID!, $contentId: ID!) {
addProjectV2ItemById(input: {projectId: $projectId, contentId: $contentId}) {
item {
id
}
}
}
`, {
projectId: projectId,
contentId: discussionId
});
console.log('Added to project:', JSON.stringify(response, null, 2));
} catch (error) {
console.error('Error:', error.message);
if (error.errors) {
error.errors.forEach((e, i) => console.error(`Error ${i + 1}:`, e));
}
core.setFailed(error.message);
}