Repository Archiving & Unarchiving with GitHub GRAPHQL API sample code.
query FindRepoID {
repository(owner:"[github user or org]", name:"[repository]"){
id,
isArchived,
}
}
(lotharschulz/FindRepoID.graphql)
mutation ArchiveRepository {
archiveRepository(input:{clientMutationId:"true",repositoryId:"[repositoryID]"}) {
repository {
isArchived,
description,
}
}
}
(lotharschulz/ArchiveRepository.graphql)
mutation UnArchiveRepository {
unarchiveRepository(input:{clientMutationId:"true",repositoryId:"[insert ID]"}) {
repository {
isArchived,
description
}
}
}
(lotharschulz/UnArchiveRepository.graphql)
GraphQL API with curl
{
"query": "query ($org: String!, $repo: String!) {repository(owner: $org, name: $repo) { id isArchived } }",
"variables": {
"org": "[github user or org]",
"repo": "[repository]"
}
}
(lotharschulz/findRepoID.graphql)
call the graphql API with curl
curl -H "Authorization: bearer [github personal access token]" -X POST -H "Content-Type: application/json" -d @findRepoID.graphql https://api.github.com/graphql
graphql API answer:
{"data":{"repository":{"id":"[SampleRepoID]","isArchived":false}}}
{
"query": "mutation ArchiveRepository ($mutationId: String!, $repoID: String!) {archiveRepository(input:{clientMutationId:$mutationId, repositoryId:$repoID}) {repository { isArchived, description } } }",
"variables": {
"mutationId": "true",
"repoID": "[repo id]"
}
}
(lotharschulz/archiveRepository.graphql)
call the graphql API with curl
curl -H "Authorization: bearer [github personal access token]" -X POST -H "Content-Type: application/json" -d @archiveRepository.graphql https://api.github.com/graphql
graphql API answer:
{"data":{"archiveRepository":{"repository":{"isArchived":true,"description":"test repository"}}}}
{
"query": "mutation UnArchiveRepository ($mutationId: String!, $repoID: String!) {unarchiveRepository(input:{clientMutationId:$mutationId, repositoryId:$repoID}) {repository { isArchived, description } } }",
"variables": {
"mutationId": "true",
"repoID": "[repo id]"
}
}
(lotharschulz/unarchiveRepository.graphql)
call the graphql API with curl
curl -H "Authorization: bearer [github personal access token]" -X POST -H "Content-Type: application/json" -d @unarchiveRepository.graphql https://api.github.com/graphql
graphql API answer:
{"data":{"unarchiveRepository":{"repository":{"isArchived":false,"description":"test repository"}}}}
query FindRepoID($name: String!, $owner: String!) {
repository(owner: $owner, name: $name) {
id,
isArchived
}
}
(lotharschulz/findRepoID_gh_cli.graphql)
use this file with the GitHub CLI in your terminal:
gh api graphql -F owner='[github user or organization]' -F name='[repository]' -f query="$(cat ./findRepoID_gh_cli.graphql)" | jq '.data.repository.id'