Skip to content

Commit bf1f3ae

Browse files
author
Himanshu Singhal
committed
AIRA-64: Project Automation Action Update
1 parent 674d612 commit bf1f3ae

File tree

1 file changed

+54
-43
lines changed

1 file changed

+54
-43
lines changed

.github/workflows/project-automation.yml

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
types: [opened, closed, ready_for_review, converted_to_draft]
88

99
env:
10-
PROJECT_NUMBER: 1 # Change this to your project number (find in project URL)
10+
PROJECT_ID: PVT_kwHOAGEyUM4A_SBA # Your project ID
1111

1212
jobs:
1313
update-project:
@@ -18,16 +18,17 @@ jobs:
1818
with:
1919
github-token: ${{ secrets.GITHUB_TOKEN }}
2020
script: |
21-
const PROJECT_NUMBER = parseInt(process.env.PROJECT_NUMBER);
21+
const PROJECT_ID = process.env.PROJECT_ID;
2222
2323
// Helper function to get project info
2424
async function getProjectInfo() {
25-
// Try organization project first
26-
const orgQuery = `
27-
query($org: String!, $projectNumber: Int!) {
28-
organization(login: $org) {
29-
projectV2(number: $projectNumber) {
25+
// Direct project lookup by ID (works for user, org, and repo projects)
26+
const directQuery = `
27+
query($projectId: ID!) {
28+
node(id: $projectId) {
29+
... on ProjectV2 {
3030
id
31+
title
3132
fields(first: 20) {
3233
nodes {
3334
... on ProjectV2Field {
@@ -50,35 +51,44 @@ jobs:
5051
`;
5152
5253
try {
53-
console.log(`Looking for organization project ${PROJECT_NUMBER} in ${context.repo.owner}`);
54-
const result = await github.graphql(orgQuery, {
55-
org: context.repo.owner,
56-
projectNumber: PROJECT_NUMBER
54+
console.log(`Looking up project by ID: ${PROJECT_ID}`);
55+
const result = await github.graphql(directQuery, {
56+
projectId: PROJECT_ID
5757
});
58-
console.log(`✅ Found organization project: ${result.organization.projectV2.id}`);
59-
return result.organization.projectV2;
60-
} catch (orgError) {
61-
console.log('Organization project not found, trying repository project...');
6258
63-
// Try repository-level project as fallback
64-
const repoQuery = `
65-
query($owner: String!, $repo: String!, $projectNumber: Int!) {
66-
repository(owner: $owner, name: $repo) {
67-
projectV2(number: $projectNumber) {
68-
id
69-
fields(first: 20) {
70-
nodes {
71-
... on ProjectV2Field {
72-
id
73-
name
74-
}
75-
... on ProjectV2SingleSelectField {
76-
id
77-
name
78-
options {
59+
if (result.node) {
60+
console.log(`✅ Found project: ${result.node.title} (${result.node.id})`);
61+
return result.node;
62+
} else {
63+
console.log('❌ Project ID resolved but returned null');
64+
return null;
65+
}
66+
} catch (directError) {
67+
console.log('❌ Direct project lookup failed:', directError.message);
68+
69+
// Fallback: Try to find project via viewer query
70+
console.log('Trying to find project via viewer query...');
71+
const viewerQuery = `
72+
query {
73+
viewer {
74+
projectsV2(first: 20) {
75+
nodes {
76+
id
77+
title
78+
fields(first: 20) {
79+
nodes {
80+
... on ProjectV2Field {
7981
id
8082
name
8183
}
84+
... on ProjectV2SingleSelectField {
85+
id
86+
name
87+
options {
88+
id
89+
name
90+
}
91+
}
8292
}
8393
}
8494
}
@@ -88,18 +98,19 @@ jobs:
8898
`;
8999
90100
try {
91-
console.log(`Looking for repository project ${PROJECT_NUMBER} in ${context.repo.owner}/${context.repo.repo}`);
92-
const result = await github.graphql(repoQuery, {
93-
owner: context.repo.owner,
94-
repo: context.repo.repo,
95-
projectNumber: PROJECT_NUMBER
96-
});
97-
console.log(`✅ Found repository project: ${result.repository.projectV2.id}`);
98-
return result.repository.projectV2;
99-
} catch (repoError) {
100-
console.log('❌ No project found at organization or repository level');
101-
console.log('Organization error:', orgError.message);
102-
console.log('Repository error:', repoError.message);
101+
const viewerResult = await github.graphql(viewerQuery);
102+
const project = viewerResult.viewer.projectsV2.nodes.find(p => p.id === PROJECT_ID);
103+
104+
if (project) {
105+
console.log(`✅ Found project via viewer: ${project.title} (${project.id})`);
106+
return project;
107+
} else {
108+
console.log('❌ Project not found in viewer projects');
109+
console.log('Available projects:', viewerResult.viewer.projectsV2.nodes.map(p => `${p.title} (${p.id})`));
110+
return null;
111+
}
112+
} catch (viewerError) {
113+
console.log('❌ Viewer query failed:', viewerError.message);
103114
return null;
104115
}
105116
}

0 commit comments

Comments
 (0)