Skip to content

Commit 6bf6ced

Browse files
tloubrieu-jplclaude
andcommitted
Deploy workflow: org-add-to-project.yml
This workflow is being deployed across the organization. Co-Authored-By: Claude (claude-sonnet-4.5) <noreply@anthropic.com>
1 parent da781fe commit 6bf6ced

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# used to triage new issues and PRs on project board, so not to miss external feedback or contributions of users.
2+
name: Add to PODAAC Project
3+
4+
5+
on:
6+
issues:
7+
types: [opened]
8+
pull_request:
9+
types: [opened]
10+
11+
jobs:
12+
add-to-project:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Add to project
16+
uses: actions/add-to-project@v0.5.0
17+
with:
18+
project-url: https://github.com/orgs/podaac/projects/75
19+
github-token: ${{ secrets.PROJECTS_PAT }}
20+
21+
- name: Set status to needs:triage
22+
uses: actions/github-script@v7
23+
with:
24+
github-token: ${{ secrets.PROJECTS_PAT }}
25+
script: |
26+
const projectNumber = 75; // Update this with your actual project number
27+
const org = 'podaac';
28+
29+
// Get the project ID
30+
const projectQuery = `
31+
query($org: String!, $number: Int!) {
32+
organization(login: $org) {
33+
projectV2(number: $number) {
34+
id
35+
fields(first: 20) {
36+
nodes {
37+
... on ProjectV2SingleSelectField {
38+
id
39+
name
40+
options {
41+
id
42+
name
43+
}
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
`;
51+
52+
const projectData = await github.graphql(projectQuery, {
53+
org: org,
54+
number: projectNumber
55+
});
56+
57+
const project = projectData.organization.projectV2;
58+
const statusField = project.fields.nodes.find(field => field.name === 'Status');
59+
const triageOption = statusField?.options.find(option => option.name === 'needs:triage');
60+
61+
if (!triageOption) {
62+
core.warning('Could not find "needs:triage" status option');
63+
return;
64+
}
65+
66+
// Get the item ID that was just added
67+
const itemType = context.eventName === 'issues' ? 'Issue' : 'PullRequest';
68+
const itemNumber = context.payload.issue?.number || context.payload.pull_request?.number;
69+
70+
const itemQuery = `
71+
query($org: String!, $repo: String!, $number: Int!) {
72+
repository(owner: $org, name: $repo) {
73+
${itemType === 'Issue' ? 'issue' : 'pullRequest'}(number: $number) {
74+
projectItems(first: 10) {
75+
nodes {
76+
id
77+
project {
78+
id
79+
}
80+
}
81+
}
82+
}
83+
}
84+
}
85+
`;
86+
87+
const itemData = await github.graphql(itemQuery, {
88+
org: org,
89+
repo: context.repo.repo,
90+
number: itemNumber
91+
});
92+
93+
const items = itemType === 'Issue'
94+
? itemData.repository.issue.projectItems.nodes
95+
: itemData.repository.pullRequest.projectItems.nodes;
96+
97+
const projectItem = items.find(item => item.project.id === project.id);
98+
99+
if (!projectItem) {
100+
core.warning('Could not find project item');
101+
return;
102+
}
103+
104+
// Update the status field
105+
const updateMutation = `
106+
mutation($projectId: ID!, $itemId: ID!, $fieldId: ID!, $value: String!) {
107+
updateProjectV2ItemFieldValue(
108+
input: {
109+
projectId: $projectId
110+
itemId: $itemId
111+
fieldId: $fieldId
112+
value: { singleSelectOptionId: $value }
113+
}
114+
) {
115+
projectV2Item {
116+
id
117+
}
118+
}
119+
}
120+
`;
121+
122+
await github.graphql(updateMutation, {
123+
projectId: project.id,
124+
itemId: projectItem.id,
125+
fieldId: statusField.id,
126+
value: triageOption.id
127+
});
128+
129+
core.info('Successfully set status to needs:triage');

0 commit comments

Comments
 (0)