Fetch Project & Column IDs #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Fetch Project & Column IDs | ||
on: | ||
workflow_dispatch: | ||
jobs: | ||
fetch-ids: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# ✅ Step 1: Fetch Project IDs | ||
- name: Get Project IDs | ||
id: get_project_ids | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const org = context.repo.owner; | ||
const projectNames = ["Refinement Board", "Project Backlog"]; // Must match the project names | ||
const query = `query($org: String!) { | ||
organization(login: $org) { | ||
projectsV2(first: 10) { | ||
nodes { | ||
id | ||
title | ||
} | ||
} | ||
} | ||
}`; | ||
const result = await github.graphql(query, { org }); | ||
if (!result.organization || !result.organization.projectsV2.nodes.length) { | ||
console.log("❌ No projects found."); | ||
return JSON.stringify({}); | ||
} | ||
let projectIds = {}; | ||
result.organization.projectsV2.nodes.forEach(p => { | ||
if (projectNames.includes(p.title)) { | ||
projectIds[p.title] = p.id; | ||
} | ||
}); | ||
console.log("====== PROJECT IDs ======"); | ||
Object.entries(projectIds).forEach(([name, id]) => { | ||
console.log(`Project "${name}" = Project ID: "${id}"`); | ||
}); | ||
return JSON.stringify(projectIds); // ✅ Ensures JSON is valid | ||
# ✅ Step 2: Fetch Column IDs | ||
- name: Get Column IDs | ||
id: get_columns | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
Check failure on line 57 in .github/workflows/get-project-column-ids.yml
|
||
const projectIds = JSON.parse('${{ steps.get_project_ids.outputs.result || "{}" }}'); | ||
if (Object.keys(projectIds).length === 0) { | ||
console.log("❌ No valid project IDs found."); | ||
return JSON.stringify({}); | ||
} | ||
let columnData = {}; | ||
for (const [projectName, projectId] of Object.entries(projectIds)) { | ||
const query = `query($projectId: ID!) { | ||
node(id: $projectId) { | ||
... on ProjectV2 { | ||
fields(first: 10) { | ||
nodes { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
}`; | ||
const result = await github.graphql(query, { projectId }); | ||
if (!result.node || !result.node.fields.nodes.length) { | ||
console.log(`❌ No columns found for Project ${projectName}.`); | ||
continue; | ||
} | ||
columnData[projectName] = {}; | ||
result.node.fields.nodes.forEach(field => { | ||
columnData[projectName][field.name] = field.id; | ||
}); | ||
} | ||
console.log("====== COLUMN IDs ======"); | ||
Object.entries(columnData).forEach(([project, columns]) => { | ||
console.log(`Project "${project}":`); | ||
Object.entries(columns).forEach(([name, id]) => { | ||
console.log(` Column "${name}" = ID: "${id}"`); | ||
}); | ||
}); | ||
return JSON.stringify(columnData); |