Fetch Project & Column IDs #1
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: # ✅ Manual trigger only | |
jobs: | |
fetch-ids: | |
runs-on: ubuntu-latest | |
steps: | |
# ✅ Step 1: Fetch Project IDs for both projects | |
- 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 }); | |
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}"`); | |
}); | |
# ✅ Step 2: Fetch Column IDs for each project | |
- name: Get Column IDs | |
id: get_columns | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const projectIds = JSON.parse('${{ steps.get_project_ids.outputs.result }}'); | |
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 }); | |
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}"`); | |
}); | |
}); |