-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (44 loc) · 1.59 KB
/
new_discussion_to_project.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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);
}