Skip to content

Instantly share code, notes, and snippets.

@matthewmayer
Created November 2, 2021 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmayer/a3b46bfe49ef410dff2997e81b0a6214 to your computer and use it in GitHub Desktop.
Save matthewmayer/a3b46bfe49ef410dff2997e81b0a6214 to your computer and use it in GitHub Desktop.
Bulk import issues into Github Projects beta
const project="PN_***********"
const org="********"
const repo="**********"
const token="gho_*******************************"
const fetch = require("node-fetch")
const parse = require("parse-link-header")
const getAllIssuesPaginated = async () => {
let issues = []
let url = "https://api.github.com/repos/"+org+"/"+repo+"/issues?per_page=100&pulls=false"
do {
const res = await fetch(url,{
method:"GET",
headers: {
Authorization:"token "+token,
Accept:"application/vnd.github.v3+json"
}
})
const parsed = parse(res.headers.get("link"));
const page = await res.json()
issues = issues.concat(page)
url = parsed?.next?.url
console.log("Fetching "+page.length+" issues")
} while (url)
return issues
}
const main = async () => {
console.log("Checking for open issues in "+repo)
const issues = await getAllIssuesPaginated()
console.log("There are "+issues.length+" issues")
for (let i of issues) {
console.log(i.number, i.title, i.node_id)
const res2 = await fetch("https://api.github.com/graphql",{
method:"POST",
headers: {
Authorization:"token "+token
},
body: JSON.stringify({
query: `mutation {addProjectNextItem(input: {projectId: "${project}" contentId: "${i.node_id}"}) {projectNextItem {id}}}`
})
})
const json = await res2.json()
console.dir(JSON.stringify(json))
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment