-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathcreate_release.ts
More file actions
142 lines (132 loc) · 3.98 KB
/
Copy pathcreate_release.ts
File metadata and controls
142 lines (132 loc) · 3.98 KB
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
import type { GitLabCreateReleaseParams, GitLabCreateReleaseResponse } from '@/tools/gitlab/types'
import { getGitLabApiBase } from '@/tools/gitlab/utils'
import type { ToolConfig } from '@/tools/types'
export const gitlabCreateReleaseTool: ToolConfig<
GitLabCreateReleaseParams,
GitLabCreateReleaseResponse
> = {
id: 'gitlab_create_release',
name: 'GitLab Create Release',
description: 'Create a new release in a GitLab project',
version: '1.0.0',
params: {
accessToken: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitLab Personal Access Token',
},
host: {
type: 'string',
required: false,
visibility: 'user-only',
description: 'Self-managed GitLab host (e.g. gitlab.example.com). Defaults to gitlab.com.',
},
projectId: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Project ID or path (e.g. mygroup/myproject)',
},
tagName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'The Git tag for the release',
},
name: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'The release name',
},
description: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Release description/notes (Markdown supported)',
},
ref: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Commit SHA, branch, or tag to create the tag from if it does not already exist',
},
releasedAt: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'ISO 8601 date for an upcoming or historical release',
},
tagMessage: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Annotation message to use if creating a new annotated tag',
},
assetLinks: {
type: 'array',
required: false,
visibility: 'user-or-llm',
description:
'Release asset links: array of objects with name, url, and optional link_type (other, runbook, image, package)',
},
milestones: {
type: 'array',
required: false,
visibility: 'user-or-llm',
description: 'Array of milestone titles to associate with the release',
},
},
request: {
url: (params) => {
const encodedId = encodeURIComponent(String(params.projectId).trim())
return `${getGitLabApiBase(params.host)}/projects/${encodedId}/releases`
},
method: 'POST',
headers: (params) => ({
'Content-Type': 'application/json',
'PRIVATE-TOKEN': params.accessToken,
}),
body: (params) => {
const body: Record<string, unknown> = {
tag_name: params.tagName,
}
if (params.tagMessage) body.tag_message = params.tagMessage
if (params.assetLinks) {
// Tolerate a single link object by wrapping it into the array GitLab expects.
const links = Array.isArray(params.assetLinks) ? params.assetLinks : [params.assetLinks]
if (links.length > 0) body.assets = { links }
}
if (params.name) body.name = params.name
if (params.description) body.description = params.description
if (params.ref) body.ref = params.ref
if (params.releasedAt) body.released_at = params.releasedAt
if (params.milestones && params.milestones.length > 0) body.milestones = params.milestones
return body
},
},
transformResponse: async (response) => {
if (!response.ok) {
const errorText = await response.text()
return {
success: false,
error: `GitLab API error: ${response.status} ${errorText}`,
output: {},
}
}
const release = await response.json()
return {
success: true,
output: {
release,
},
}
},
outputs: {
release: {
type: 'object',
description: 'The created GitLab release',
},
},
}