Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 4x 4x 17x 3x 17x 17x 3x 4x 44x 22x 22x 22x 22x 22x 22x 22x | import { gql } from 'graphql-tag';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
/**
* GraphQL documents for CI Runners.
*
* Verified against a live GitLab 19.x instance via schema introspection:
* - Queries: `runners` (admin, instance-wide), `currentUser.runners`,
* `group/project(fullPath).runners`, `runner(id)` with a `jobs(statuses)` connection.
* - Mutations: `runnerCreate` (returns ephemeralAuthenticationToken), `runnerUpdate`
* (description/tagList/paused/... — also powers pause/resume), `runnerDelete`.
*
* GitLab has no per-runner authentication-token reset mutation in GraphQL
* (only the legacy group/project registration-token reset), so that one action
* uses the REST endpoint in the handler.
*/
const RUNNER_FIELDS = `
id
description
runnerType
status
paused
locked
runUntagged
tagList
accessLevel
maximumTimeout
jobExecutionStatus
jobCount
contactedAt
createdAt
`;
/**
* Projects a runner is associated with, read only to check a project allowlist. All fields
* exist in GitLab 16.0:
* https://github.com/gitlabhq/gitlabhq/blob/v16.0.0/app/graphql/types/ci/runner_type.rb
* projectCount includes invisible associations; projects alone cannot prove confinement.
*/
const RUNNER_PROVENANCE_FIELDS = `
runnerType
projectCount
projects(first: 100) { nodes { id fullPath } pageInfo { hasNextPage } }
`;
/**
* A listed runner, with its projects only when the listing checks an allowlist: nested in a
* listing of 100 runners they add 26 to its query complexity (limit 250; measured on GitLab
* 19.0), instead of one query per runner.
*/
const LISTED_RUNNER_FIELDS = `
${RUNNER_FIELDS}
projectCount @include(if: $restricted)
projects(first: 100) @include(if: $restricted) { nodes { id fullPath } pageInfo { hasNextPage } }
`;
export interface RunnerProject {
id: string;
fullPath: string;
}
export interface RunnerProvenance {
runnerType: string;
projectCount?: number | null;
projects?: { nodes: RunnerProject[]; pageInfo: { hasNextPage: boolean } } | null;
}
export interface RunnerNode extends RunnerProvenance {
id: string;
description: string | null;
runnerType: string;
status: string | null;
paused: boolean;
locked: boolean;
runUntagged: boolean;
tagList: string[] | null;
accessLevel: string | null;
maximumTimeout: number | null;
jobExecutionStatus: string | null;
jobCount: number | null;
contactedAt: string | null;
createdAt: string | null;
}
interface PageInfo {
hasNextPage: boolean;
endCursor: string | null;
}
interface RunnerConnection {
nodes: RunnerNode[];
pageInfo: PageInfo;
}
// Shared list filters (subset of the runners connection args we expose).
export interface RunnerListVars {
type?: string | null;
status?: string | null;
paused?: boolean | null;
tagList?: string[] | null;
search?: string | null;
first?: number | null;
after?: string | null;
/** Whether each runner's projects are read, to check a project allowlist. */
restricted: boolean;
}
const LIST_ARG_DECLS = `
$restricted: Boolean!
$type: CiRunnerType
$status: CiRunnerStatus
$paused: Boolean
$tagList: [String!]
$search: String
$first: Int
$after: String
`;
const LIST_ARG_USE = `
type: $type
status: $status
paused: $paused
tagList: $tagList
search: $search
first: $first
after: $after
`;
// --- Query: instance-wide runners (admin) ---
export interface ListRunnersResult {
runners: RunnerConnection | null;
}
export const LIST_RUNNERS: TypedDocumentNode<ListRunnersResult, RunnerListVars> = gql`
query ListRunners(${LIST_ARG_DECLS}) {
runners(${LIST_ARG_USE}) {
nodes { ${LISTED_RUNNER_FIELDS} }
pageInfo { hasNextPage endCursor }
}
}
`;
// --- Query: current user's runners ---
export interface ListOwnedRunnersResult {
currentUser: { runners: RunnerConnection | null } | null;
}
export const LIST_OWNED_RUNNERS: TypedDocumentNode<ListOwnedRunnersResult, RunnerListVars> = gql`
query ListOwnedRunners(${LIST_ARG_DECLS}) {
currentUser {
runners(${LIST_ARG_USE}) {
nodes { ${LISTED_RUNNER_FIELDS} }
pageInfo { hasNextPage endCursor }
}
}
}
`;
// --- Query: group runners ---
export interface ListGroupRunnersResult {
group: { runners: RunnerConnection | null } | null;
}
export interface ListNamespaceRunnersVars extends RunnerListVars {
fullPath: string;
}
export const LIST_GROUP_RUNNERS: TypedDocumentNode<
ListGroupRunnersResult,
ListNamespaceRunnersVars
> = gql`
query ListGroupRunners($fullPath: ID!, ${LIST_ARG_DECLS}) {
group(fullPath: $fullPath) {
runners(${LIST_ARG_USE}) {
nodes { ${LISTED_RUNNER_FIELDS} }
pageInfo { hasNextPage endCursor }
}
}
}
`;
// --- Query: project runners ---
export interface ListProjectRunnersResult {
project: { runners: RunnerConnection | null } | null;
}
export const LIST_PROJECT_RUNNERS: TypedDocumentNode<
ListProjectRunnersResult,
ListNamespaceRunnersVars
> = gql`
query ListProjectRunners($fullPath: ID!, ${LIST_ARG_DECLS}) {
project(fullPath: $fullPath) {
runners(${LIST_ARG_USE}) {
nodes { ${LISTED_RUNNER_FIELDS} }
pageInfo { hasNextPage endCursor }
}
}
}
`;
// --- Query: a single runner ---
export interface GetRunnerResult {
runner: RunnerNode | null;
}
export interface GetRunnerVars {
id: string;
}
export const GET_RUNNER: TypedDocumentNode<GetRunnerResult, GetRunnerVars> = gql`
query GetRunner($id: CiRunnerID!) {
runner(id: $id) { ${RUNNER_FIELDS} }
}
`;
export interface RunnerProjectAccessResult {
runner: RunnerProvenance | null;
}
export const RUNNER_PROJECT_ACCESS: TypedDocumentNode<RunnerProjectAccessResult, GetRunnerVars> =
gql`
query RunnerProjectAccess($id: CiRunnerID!) {
runner(id: $id) { ${RUNNER_PROVENANCE_FIELDS} }
}
`;
/** Runners per ownership batch: ten cost 153 of GitLab's 250 query complexity (19.0). */
export const RUNNERS_PER_ACCESS_QUERY = 10;
const accessBatches = new Map<number, TypedDocumentNode<RunnerAccessBatchResult, RunnerIdVars>>();
/** Ownership of each runner of a batch, answered as `r<index>`. */
export type RunnerAccessBatchResult = Record<string, RunnerProvenance | null>;
/** The runners of a batch as `id<index>` global IDs. */
export type RunnerIdVars = Record<string, string>;
/** The ownership query for a batch of `size` runners, `id0`... answered as `r0`... */
export function runnerAccessBatch(
size: number,
): TypedDocumentNode<RunnerAccessBatchResult, RunnerIdVars> {
let document = accessBatches.get(size);
if (!document) {
const indexes = Array.from({ length: size }, (_, index) => index);
document = gql`
query RunnerProjectAccessBatch(${indexes.map((i) => `$id${i}: CiRunnerID!`).join(' ')}) {
${indexes.map((i) => `r${i}: runner(id: $id${i}) { ${RUNNER_PROVENANCE_FIELDS} }`).join('\n')}
}
`;
accessBatches.set(size, document);
}
return document;
}
// --- Query: jobs run by a runner ---
export interface RunnerJobNode {
id: string;
name: string | null;
status: string | null;
createdAt: string | null;
finishedAt: string | null;
duration: number | null;
webPath: string | null;
project?: RunnerProject | null;
}
export interface ListRunnerJobsResult {
runner: {
id: string;
jobs: { nodes: RunnerJobNode[]; pageInfo: PageInfo } | null;
} | null;
}
export interface ListRunnerJobsVars {
id: string;
statuses?: string[] | null;
first?: number | null;
after?: string | null;
}
function runnerJobsQuery(
projectFields: string,
): TypedDocumentNode<ListRunnerJobsResult, ListRunnerJobsVars> {
return gql`
query ListRunnerJobs($id: CiRunnerID!, $statuses: [CiJobStatus!], $first: Int, $after: String) {
runner(id: $id) {
id
jobs(statuses: $statuses, first: $first, after: $after) {
nodes {
id
name
status
createdAt
finishedAt
duration
webPath
${projectFields}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
`;
}
export const LIST_RUNNER_JOBS = runnerJobsQuery('');
// CiJob.project exists in GitLab 16.0 (app/graphql/types/ci/job_type.rb).
export const LIST_SCOPED_RUNNER_JOBS = runnerJobsQuery('project { id fullPath }');
// --- Lookups: resolve a group/project full path to its global ID ---
// runnerCreate needs the namespace global ID, but callers pass the human path.
export interface ResolveGroupResult {
group: { id: string } | null;
}
export interface ResolveProjectResult {
project: { id: string } | null;
}
export interface ResolvePathVars {
fullPath: string;
}
export const RESOLVE_GROUP_ID: TypedDocumentNode<ResolveGroupResult, ResolvePathVars> = gql`
query ResolveGroupId($fullPath: ID!) {
group(fullPath: $fullPath) {
id
}
}
`;
export const RESOLVE_PROJECT_ID: TypedDocumentNode<ResolveProjectResult, ResolvePathVars> = gql`
query ResolveProjectId($fullPath: ID!) {
project(fullPath: $fullPath) {
id
}
}
`;
// --- Mutation: create a runner (returns ephemeral auth token) ---
export interface RunnerCreateResult {
runnerCreate: {
runner: (RunnerNode & { ephemeralAuthenticationToken: string | null }) | null;
errors: string[];
} | null;
}
export interface RunnerCreateVars {
input: {
runnerType: string;
groupId?: string | null;
projectId?: string | null;
description?: string | null;
paused?: boolean | null;
locked?: boolean | null;
runUntagged?: boolean | null;
tagList?: string[] | null;
accessLevel?: string | null;
maximumTimeout?: number | null;
maintenanceNote?: string | null;
};
}
export const RUNNER_CREATE: TypedDocumentNode<RunnerCreateResult, RunnerCreateVars> = gql`
mutation RunnerCreate($input: RunnerCreateInput!) {
runnerCreate(input: $input) {
runner {
${RUNNER_FIELDS}
ephemeralAuthenticationToken
}
errors
}
}
`;
// --- Mutation: update a runner (also powers pause/resume via `paused`) ---
export interface RunnerUpdateResult {
runnerUpdate: { runner: RunnerNode | null; errors: string[] } | null;
}
export interface RunnerUpdateVars {
input: {
id: string;
description?: string | null;
paused?: boolean | null;
locked?: boolean | null;
runUntagged?: boolean | null;
tagList?: string[] | null;
accessLevel?: string | null;
maximumTimeout?: number | null;
maintenanceNote?: string | null;
};
}
export const RUNNER_UPDATE: TypedDocumentNode<RunnerUpdateResult, RunnerUpdateVars> = gql`
mutation RunnerUpdate($input: RunnerUpdateInput!) {
runnerUpdate(input: $input) {
runner { ${RUNNER_FIELDS} }
errors
}
}
`;
// --- Mutation: delete a runner ---
export interface RunnerDeleteResult {
runnerDelete: { errors: string[] } | null;
}
export interface RunnerDeleteVars {
input: { id: string };
}
export const RUNNER_DELETE: TypedDocumentNode<RunnerDeleteResult, RunnerDeleteVars> = gql`
mutation RunnerDelete($input: RunnerDeleteInput!) {
runnerDelete(input: $input) {
errors
}
}
`;
|