Skip to content

Add new discussions to project #33

Add new discussions to project

Add new discussions to project #33

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: Debug Info
run: |
echo "Event: ${{ github.event_name }}"
echo "Action: ${{ github.event.action }}"
echo "Discussion ID: ${{ github.event.discussion.node_id }}"
echo "Discussion Number: ${{ github.event.discussion.number }}"
echo "Organization: ${{ github.repository_owner }}"
- name: Add to project
uses: actions/github-script@v6
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 adding to project:', error);
core.setFailed(error.message);
}