Export the Status of Batch Change PRs Using GraphQL API

Note: As of 5.3, batch change data can be exported through the UI.
https://github.com/sourcegraph/sourcegraph/pull/56721

This guide explains how to check the status of batch change pull requests (PRs) using the GraphQL API. Follow these steps:

Step 1: Get Your Namespace ID

Run this GraphQL query to fetch your Namespace ID.

# query

query User($username: String!) {
user(username: $username) {
id
}
}
# variables
{
"username": "<USERNAME>"
}

Step 2: Get the Batch Change ID

Use the Namespace ID obtained above to fetch your Batch Change ID.

# query

query BatchChangeByNamespace($namespaceID: ID!, $batchChange: String!) {
batchChange(namespace: $namespaceID, name: $batchChange) {
id
}
}
# variables
{
"namespaceID": "<NAMESPACE ID FROM ABOVE>",
"batchChange": "<BATCH CHANGE NAME>"
}

3. Get the batch change changesets
Retrieve details of the changesets in your batch change using this query.

#query

query BatchChangeChangesets($batchChange: ID!, $state: ChangesetState) {
node(id: $batchChange) {
__typename
... on BatchChange {
changesets(
state: $state
) {
__typename
totalCount
pageInfo {
endCursor
hasNextPage
__typename
}
nodes {
__typename
... on HiddenExternalChangeset {
...HiddenExternalChangesetFields
__typename
}
... on ExternalChangeset {
...ExternalChangesetFields
__typename
}
}
}
__typename
}
}
}

fragment HiddenExternalChangesetFields on HiddenExternalChangeset {
__typename
id
createdAt
updatedAt
nextSyncAt
state
}

fragment ExternalChangesetFields on ExternalChangeset {
__typename
id
title
body
state
reviewState
checkState
error
syncerError
labels {
...ChangesetLabelFields
__typename
}
repository {
id
name
url
__typename
}
externalURL {
url
__typename
}
forkNamespace
externalID
diffStat {
...DiffStatFields
__typename
}
createdAt
updatedAt
nextSyncAt
commitVerification {
... on GitHubCommitVerification {
verified
__typename
}
__typename
}
currentSpec {
id
type
description {
__typename
... on GitBranchChangesetDescription {
baseRef
headRef
__typename
}
}
forkTarget {
pushUser
namespace
__typename
}
__typename
}
}

fragment DiffStatFields on DiffStat {
__typename
added
deleted
}

fragment ChangesetLabelFields on ChangesetLabel {
__typename
color
description
text
}
#variables
{
"batchChange": "<BATCH CHANGE ID FROM STEP 2>",
"state": "OPEN"
}

Notes:

Replace placeholders (e.g., ) with your actual data.
Adjust the state variable in step 3 to filter the changesets by their state (e.g., "OPEN", "CLOSED").
For more information, refer to the GraphQL API docs.

Was this article helpful?
0 out of 0 found this helpful

Articles in this section