77 types : [opened, closed, ready_for_review, converted_to_draft]
88
99env :
10- PROJECT_ID : PVT_kwHOAGEyUM4A_SBA # GitHub Project V2 ID
10+ PROJECT_ID : PVT_kwHOAGEyUM4A_SBA # Your project ID
1111
1212jobs :
1313 update-project :
@@ -22,12 +22,13 @@ jobs:
2222
2323 // Helper function to get project info
2424 async function getProjectInfo() {
25- // Try organization project first
26- let query = `
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,56 +51,30 @@ jobs:
5051 `;
5152
5253 try {
53- // If PROJECT_ID is a number, use it as project number
54- if (/^\d+$/.test(PROJECT_ID)) {
55- const result = await github.graphql(query, {
56- org: context.repo.owner,
57- projectNumber: parseInt(PROJECT_ID)
58- });
59- return result.organization.projectV2;
60- }
61-
62- // Otherwise try as global ID
63- query = `
64- query($projectId: ID!) {
65- node(id: $projectId) {
66- ... on ProjectV2 {
67- id
68- fields(first: 20) {
69- nodes {
70- ... on ProjectV2Field {
71- id
72- name
73- }
74- ... on ProjectV2SingleSelectField {
75- id
76- name
77- options {
78- id
79- name
80- }
81- }
82- }
83- }
84- }
85- }
86- }
87- `;
88-
89- const result = await github.graphql(query, {
54+ console.log(`Looking up project by ID: ${PROJECT_ID}`);
55+ const result = await github.graphql(directQuery, {
9056 projectId: PROJECT_ID
9157 });
92- return result.node;
93- } catch (error) {
94- console.log('Error fetching project info:', error);
9558
96- // Try repository-level project as fallback
97- try {
98- query = `
99- query($owner: String!, $repo: String!, $projectNumber: Int!) {
100- repository(owner: $owner, name: $repo) {
101- projectV2(number: $projectNumber) {
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 {
10276 id
77+ title
10378 fields(first: 20) {
10479 nodes {
10580 ... on ProjectV2Field {
@@ -119,21 +94,25 @@ jobs:
11994 }
12095 }
12196 }
122- `;
97+ }
98+ `;
99+
100+ try {
101+ const viewerResult = await github.graphql(viewerQuery);
102+ const project = viewerResult.viewer.projectsV2.nodes.find(p => p.id === PROJECT_ID);
123103
124- if (/^\d+$/.test(PROJECT_ID) ) {
125- const result = await github.graphql(query, {
126- owner: context.repo.owner,
127- repo: context.repo.repo,
128- projectNumber: parseInt(PROJECT_ID)
129- } );
130- return result.repository.projectV2 ;
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 ;
131111 }
132- } catch (fallbackError) {
133- console.log('Repository project fallback failed:', fallbackError);
112+ } catch (viewerError) {
113+ console.log('❌ Viewer query failed:', viewerError.message);
114+ return null;
134115 }
135-
136- return null;
137116 }
138117 }
139118
0 commit comments