-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommits.ts
More file actions
324 lines (289 loc) · 8.33 KB
/
commits.ts
File metadata and controls
324 lines (289 loc) · 8.33 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
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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../core/resource';
import { APIPromise } from '../core/api-promise';
import { EntriesCursor, type EntriesCursorParams, PagePromise } from '../core/pagination';
import { RequestOptions } from '../internal/request-options';
import { path } from '../internal/utils/path';
/**
* Commits are versioned changes to resources.
*/
export class Commits extends APIResource {
/**
* Retrieve a single commit by its ID.
*
* @example
* ```ts
* const commit = await client.commits.retrieve(
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
* );
* ```
*/
retrieve(id: string, options?: RequestOptions): APIPromise<Commit> {
return this._client.get(path`/v1/commits/${id}`, options);
}
/**
* Returns a paginated list of commits in a given environment. The commits are
* ordered from most recent first.
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const commit of client.commits.list({
* environment: 'development',
* })) {
* // ...
* }
* ```
*/
list(query: CommitListParams, options?: RequestOptions): PagePromise<CommitsEntriesCursor, Commit> {
return this._client.getAPIList('/v1/commits', EntriesCursor<Commit>, { query, ...options });
}
/**
* Commit all changes across all resources in the development environment.
*
* @example
* ```ts
* const response = await client.commits.commitAll({
* environment: 'development',
* });
* ```
*/
commitAll(params: CommitCommitAllParams, options?: RequestOptions): APIPromise<CommitCommitAllResponse> {
const { environment, branch, commit_message, resource_id, resource_type } = params;
return this._client.put('/v1/commits', {
query: { environment, branch, commit_message, resource_id, resource_type },
...options,
});
}
/**
* Promote all changes across all resources to the target environment from its
* preceding environment.
*
* @example
* ```ts
* const response = await client.commits.promoteAll({
* to_environment: 'to_environment',
* });
* ```
*/
promoteAll(params: CommitPromoteAllParams, options?: RequestOptions): APIPromise<CommitPromoteAllResponse> {
const { to_environment, branch, resource_id, resource_type } = params;
return this._client.put('/v1/commits/promote', {
query: { to_environment, branch, resource_id, resource_type },
...options,
});
}
/**
* Promotes one change to the subsequent environment.
*
* @example
* ```ts
* const response = await client.commits.promoteOne('id');
* ```
*/
promoteOne(id: string, options?: RequestOptions): APIPromise<CommitPromoteOneResponse> {
return this._client.put(path`/v1/commits/${id}/promote`, options);
}
}
export type CommitsEntriesCursor = EntriesCursor<Commit>;
/**
* A commit is a change to a resource within an environment, made by an author.
*/
export interface Commit {
/**
* The unique identifier for the commit.
*/
id: string;
/**
* The author of the commit.
*/
author: Commit.Author;
/**
* The timestamp of when the commit was created.
*/
created_at: string;
/**
* The environment of the commit.
*/
environment: string;
/**
* The resource object associated with the commit.
*/
resource: Commit.Resource;
/**
* The optional message about the commit.
*/
commit_message?: string;
}
export namespace Commit {
/**
* The author of the commit.
*/
export interface Author {
/**
* The email address of the commit author.
*/
email: string;
/**
* The name of the commit author.
*/
name?: string | null;
}
/**
* The resource object associated with the commit.
*/
export interface Resource {
/**
* The unique identifier for the resource.
*/
identifier: string;
/**
* The type of the resource object.
*/
type: 'audience' | 'email_layout' | 'guide' | 'message_type' | 'partial' | 'translation' | 'workflow';
}
}
/**
* The response from committing all changes.
*/
export interface CommitCommitAllResponse {
/**
* The result of the commit operation.
*/
result: string;
}
/**
* The response from promoting all changes.
*/
export interface CommitPromoteAllResponse {
/**
* The result of the promote operation.
*/
result: string;
}
/**
* Wraps the Commit response under the `commit` key.
*/
export interface CommitPromoteOneResponse {
/**
* A commit is a change to a resource within an environment, made by an author.
*/
commit: Commit;
}
export interface CommitListParams extends EntriesCursorParams {
/**
* The environment slug.
*/
environment: string;
/**
* The slug of a branch to use. This option can only be used when `environment` is
* `"development"`.
*/
branch?: string;
/**
* Whether to show commits in the given environment that have not been promoted to
* the subsequent environment (false) or commits which have been promoted (true).
*/
promoted?: boolean;
/**
* Filter commits by resource identifier. Must be used together with resource_type.
* For most resources, this will be the resource key. In the case of translations,
* this will be the locale code and namespace, separated by a `/`. For example,
* `en/courses` or `en`.
*/
resource_id?: string;
/**
* Filter commits by resource type(s). Accepts a single type or array of types. Can
* be combined with resource_id to filter for specific resources.
*/
resource_type?:
| 'audience'
| 'email_layout'
| 'guide'
| 'message_type'
| 'partial'
| 'translation'
| 'workflow'
| Array<'audience' | 'email_layout' | 'guide' | 'message_type' | 'partial' | 'translation' | 'workflow'>;
}
export interface CommitCommitAllParams {
/**
* The environment slug.
*/
environment: string;
/**
* The slug of a branch to use. This option can only be used when `environment` is
* `"development"`.
*/
branch?: string;
/**
* An optional message to include in a commit.
*/
commit_message?: string;
/**
* Filter changes to commit by resource identifier. Must be used together with
* resource_type.
*/
resource_id?: string;
/**
* Filter changes to commit by resource type(s). Accepts a single type or array of
* types. Can be combined with resource_id to filter for specific resources.
*/
resource_type?:
| 'audience'
| 'email_layout'
| 'guide'
| 'message_type'
| 'partial'
| 'translation'
| 'workflow'
| Array<'audience' | 'email_layout' | 'guide' | 'message_type' | 'partial' | 'translation' | 'workflow'>;
}
export interface CommitPromoteAllParams {
/**
* A slug of the target environment to which you want to promote all changes from
* its directly preceding environment.
*
* For example, if you have three environments “development”, “staging”, and
* “production” (in that order), setting this param to “production” will promote
* all commits not currently in production from staging.
*
* When this param is set to `"development"`, the `"branch"` param must be
* provided.
*/
to_environment: string;
/**
* The slug of the branch to promote all changes from.
*/
branch?: string;
/**
* Filter commits to promote by resource identifier. Must be used together with
* resource_type.
*/
resource_id?: string;
/**
* Filter commits to promote by resource type(s). Accepts a single type or array of
* types. Can be combined with resource_id to filter for specific resources.
*/
resource_type?:
| 'audience'
| 'email_layout'
| 'guide'
| 'message_type'
| 'partial'
| 'translation'
| 'workflow'
| Array<'audience' | 'email_layout' | 'guide' | 'message_type' | 'partial' | 'translation' | 'workflow'>;
}
export declare namespace Commits {
export {
type Commit as Commit,
type CommitCommitAllResponse as CommitCommitAllResponse,
type CommitPromoteAllResponse as CommitPromoteAllResponse,
type CommitPromoteOneResponse as CommitPromoteOneResponse,
type CommitsEntriesCursor as CommitsEntriesCursor,
type CommitListParams as CommitListParams,
type CommitCommitAllParams as CommitCommitAllParams,
type CommitPromoteAllParams as CommitPromoteAllParams,
};
}