Fetch Cluster API Issues and PRs & Add to Project #24
This file contains 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 Cluster API Issues and PRs & Add to Project | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs daily at midnight UTC | |
workflow_dispatch: # Allows manual execution | |
jobs: | |
fetch-and-add-to-project: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Fetch Cluster API Issues and PRs and Add to Project | |
id: fetch-cluster-api-items | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GH_PAT }} | |
script: | | |
const projectId = "PVT_kwHOCAOYJ84AxkbT"; // Project Board ID | |
const repo = "kubernetes-sigs/cluster-api"; | |
async function fetchItems(github, query) { | |
const items = []; | |
let page = 1; | |
let hasMore = true; | |
while (hasMore) { | |
const results = await github.rest.search.issuesAndPullRequests({ | |
q: query, | |
per_page: 100, | |
page, | |
}); | |
items.push(...results.data.items); | |
hasMore = results.data.items.length === 100; | |
page += 1; | |
} | |
return items; | |
} | |
async function addToProject(github, contentId) { | |
try { | |
await github.graphql(` | |
mutation($projectId: ID!, $contentId: ID!) { | |
addProjectV2ItemById(input: {projectId: $projectId, contentId: $contentId}) { | |
item { | |
id | |
} | |
} | |
} | |
`, { | |
projectId: projectId, | |
contentId: contentId | |
}); | |
console.log(`Successfully added item ${contentId} to project.`); | |
} catch (error) { | |
console.error(`Failed to add item ${contentId} to project: ${error.message}`); | |
} | |
} | |
console.log("Fetching all Cluster API-related issues and PRs..."); | |
const milestoneQuery = `repo:${repo} milestone:v1.10`; | |
const milestoneItems = await fetchItems(github, milestoneQuery); | |
if (milestoneItems.length === 0) { | |
console.log("No issues or PRs found for milestone v1.10."); | |
return; | |
} | |
console.log(`Found ${milestoneItems.length} relevant items. Adding to project...`); | |
for (const item of milestoneItems) { | |
await addToProject(github, item.node_id); | |
} |