Skip to content

Commit 56a53b3

Browse files
committed
feat(pipeline): Add list_pipeline_trigger_jobs tools
1 parent ee16a17 commit 56a53b3

File tree

4 files changed

+744
-323
lines changed

4 files changed

+744
-323
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,20 +232,21 @@ $ sh scripts/image_push.sh docker_user_name
232232
48. `list_pipelines` - List pipelines in a GitLab project with filtering options
233233
49. `get_pipeline` - Get details of a specific pipeline in a GitLab project
234234
50. `list_pipeline_jobs` - List all jobs in a specific pipeline
235-
51. `get_pipeline_job` - Get details of a GitLab pipeline job number
236-
52. `get_pipeline_job_output` - Get the output/trace of a GitLab pipeline job number
237-
53. `create_pipeline` - Create a new pipeline for a branch or tag
238-
54. `retry_pipeline` - Retry a failed or canceled pipeline
239-
55. `cancel_pipeline` - Cancel a running pipeline
240-
56. `list_merge_requests` - List merge requests in a GitLab project with filtering options
241-
57. `list_milestones` - List milestones in a GitLab project with filtering options
242-
58. `get_milestone` - Get details of a specific milestone
243-
59. `create_milestone` - Create a new milestone in a GitLab project
244-
60. `edit_milestone` - Edit an existing milestone in a GitLab project
245-
61. `delete_milestone` - Delete a milestone from a GitLab project
246-
62. `get_milestone_issue` - Get issues associated with a specific milestone
247-
63. `get_milestone_merge_requests` - Get merge requests associated with a specific milestone
248-
64. `promote_milestone` - Promote a milestone to the next stage
249-
65. `get_milestone_burndown_events` - Get burndown events for a specific milestone
250-
66. `get_users` - Get GitLab user details by usernames
235+
51. `list_pipeline_trigger_jobs` - List all trigger jobs (bridges) in a specific pipeline that trigger downstream pipelines
236+
52. `get_pipeline_job` - Get details of a GitLab pipeline job number
237+
53. `get_pipeline_job_output` - Get the output/trace of a GitLab pipeline job number
238+
54. `create_pipeline` - Create a new pipeline for a branch or tag
239+
55. `retry_pipeline` - Retry a failed or canceled pipeline
240+
56. `cancel_pipeline` - Cancel a running pipeline
241+
57. `list_merge_requests` - List merge requests in a GitLab project with filtering options
242+
58. `list_milestones` - List milestones in a GitLab project with filtering options
243+
59. `get_milestone` - Get details of a specific milestone
244+
60. `create_milestone` - Create a new milestone in a GitLab project
245+
61. `edit_milestone` - Edit an existing milestone in a GitLab project
246+
62. `delete_milestone` - Delete a milestone from a GitLab project
247+
63. `get_milestone_issue` - Get issues associated with a specific milestone
248+
64. `get_milestone_merge_requests` - Get merge requests associated with a specific milestone
249+
65. `promote_milestone` - Promote a milestone to the next stage
250+
66. `get_milestone_burndown_events` - Get burndown events for a specific milestone
251+
67. `get_users` - Get GitLab user details by usernames
251252
<!-- TOOLS-END -->

index.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,14 @@ import {
9393
GetPipelineSchema,
9494
ListPipelinesSchema,
9595
ListPipelineJobsSchema,
96+
ListPipelineTriggerJobsSchema,
9697
CreatePipelineSchema,
9798
RetryPipelineSchema,
9899
CancelPipelineSchema,
99100
// pipeline job schemas
100101
GetPipelineJobOutputSchema,
101102
GitLabPipelineJobSchema,
103+
GitLabPipelineTriggerJobSchema,
102104
// Discussion Schemas
103105
GitLabDiscussionNoteSchema, // Added
104106
GitLabDiscussionSchema,
@@ -130,10 +132,12 @@ import {
130132
type ListPipelinesOptions,
131133
type GetPipelineOptions,
132134
type ListPipelineJobsOptions,
135+
type ListPipelineTriggerJobsOptions,
133136
type CreatePipelineOptions,
134137
type RetryPipelineOptions,
135138
type CancelPipelineOptions,
136139
type GitLabPipelineJob,
140+
type GitLabPipelineTriggerJob,
137141
type GitLabMilestones,
138142
type ListProjectMilestonesOptions,
139143
type GetProjectMilestoneOptions,
@@ -643,6 +647,11 @@ const allTools = [
643647
description: "List all jobs in a specific pipeline",
644648
inputSchema: zodToJsonSchema(ListPipelineJobsSchema),
645649
},
650+
{
651+
name: "list_pipeline_trigger_jobs",
652+
description: "List all trigger jobs (bridges) in a specific pipeline that trigger downstream pipelines",
653+
inputSchema: zodToJsonSchema(ListPipelineTriggerJobsSchema),
654+
},
646655
{
647656
name: "get_pipeline_job",
648657
description: "Get details of a GitLab pipeline job number",
@@ -766,6 +775,7 @@ const readOnlyTools = [
766775
"get_pipeline",
767776
"list_pipelines",
768777
"list_pipeline_jobs",
778+
"list_pipeline_trigger_jobs",
769779
"get_pipeline_job",
770780
"get_pipeline_job_output",
771781
"list_projects",
@@ -816,6 +826,7 @@ const pipelineToolNames = [
816826
"list_pipelines",
817827
"get_pipeline",
818828
"list_pipeline_jobs",
829+
"list_pipeline_trigger_jobs",
819830
"get_pipeline_job",
820831
"get_pipeline_job_output",
821832
"create_pipeline",
@@ -2816,6 +2827,49 @@ async function listPipelineJobs(
28162827
const data = await response.json();
28172828
return z.array(GitLabPipelineJobSchema).parse(data);
28182829
}
2830+
2831+
/**
2832+
* List all trigger jobs (bridges) in a specific pipeline
2833+
*
2834+
* @param {string} projectId - The ID or URL-encoded path of the project
2835+
* @param {number} pipelineId - The ID of the pipeline
2836+
* @param {Object} options - Options for filtering trigger jobs
2837+
* @returns {Promise<GitLabPipelineTriggerJob[]>} List of pipeline trigger jobs
2838+
*/
2839+
async function listPipelineTriggerJobs(
2840+
projectId: string,
2841+
pipelineId: number | string,
2842+
options: Omit<ListPipelineTriggerJobsOptions, "project_id" | "pipeline_id"> = {}
2843+
): Promise<GitLabPipelineTriggerJob[]> {
2844+
projectId = decodeURIComponent(projectId); // Decode project ID
2845+
const url = new URL(
2846+
`${GITLAB_API_URL}/projects/${encodeURIComponent(getEffectiveProjectId(projectId))}/pipelines/${pipelineId}/bridges`
2847+
);
2848+
2849+
// Add all query parameters
2850+
Object.entries(options).forEach(([key, value]) => {
2851+
if (value !== undefined) {
2852+
if (typeof value === "boolean") {
2853+
url.searchParams.append(key, value ? "true" : "false");
2854+
} else {
2855+
url.searchParams.append(key, value.toString());
2856+
}
2857+
}
2858+
});
2859+
2860+
const response = await fetch(url.toString(), {
2861+
...DEFAULT_FETCH_CONFIG,
2862+
});
2863+
2864+
if (response.status === 404) {
2865+
throw new Error(`Pipeline not found`);
2866+
}
2867+
2868+
await handleGitLabError(response);
2869+
const data = await response.json();
2870+
return z.array(GitLabPipelineTriggerJobSchema).parse(data);
2871+
}
2872+
28192873
async function getPipelineJob(projectId: string, jobId: number | string): Promise<GitLabPipelineJob> {
28202874
projectId = decodeURIComponent(projectId); // Decode project ID
28212875
const url = new URL(`${GITLAB_API_URL}/projects/${encodeURIComponent(getEffectiveProjectId(projectId))}/jobs/${jobId}`);
@@ -4131,6 +4185,21 @@ server.setRequestHandler(CallToolRequestSchema, async request => {
41314185
};
41324186
}
41334187

4188+
case "list_pipeline_trigger_jobs": {
4189+
const { project_id, pipeline_id, ...options } = ListPipelineTriggerJobsSchema.parse(
4190+
request.params.arguments
4191+
);
4192+
const triggerJobs = await listPipelineTriggerJobs(project_id, pipeline_id, options);
4193+
return {
4194+
content: [
4195+
{
4196+
type: "text",
4197+
text: JSON.stringify(triggerJobs, null, 2),
4198+
},
4199+
],
4200+
};
4201+
}
4202+
41344203
case "get_pipeline_job": {
41354204
const { project_id, job_id } = GetPipelineJobOutputSchema.parse(request.params.arguments);
41364205
const jobDetails = await getPipelineJob(project_id, job_id);

0 commit comments

Comments
 (0)