0

Update a schedule

by
Published Dec 20, 2024

Not yet available to projects that use GitLab or GitHub App. Updates a schedule and returns the updated schedule.

Script circleci Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Circleci = {
3
	token: string
4
}
5
/**
6
 * Update a schedule
7
 * Not yet available to projects that use GitLab or GitHub App. Updates a schedule and returns the updated schedule.
8
 */
9
export async function main(
10
	auth: Circleci,
11
	schedule_id: string,
12
	body: {
13
		description?: string
14
		name?: string
15
		timetable?: {
16
			'per-hour'?: number
17
			'hours-of-day'?: number[]
18
			'days-of-week'?: 'TUE' | 'SAT' | 'SUN' | 'MON' | 'THU' | 'WED' | 'FRI'[]
19
			'days-of-month'?: number[]
20
			months?:
21
				| 'MAR'
22
				| 'NOV'
23
				| 'DEC'
24
				| 'JUN'
25
				| 'MAY'
26
				| 'OCT'
27
				| 'FEB'
28
				| 'APR'
29
				| 'SEP'
30
				| 'AUG'
31
				| 'JAN'
32
				| 'JUL'[]
33
		}
34
		'attribution-actor'?: 'current' | 'system'
35
		parameters?: {}
36
	}
37
) {
38
	const url = new URL(`https://circleci.com/api/v2/schedule/${schedule_id}`)
39

40
	const response = await fetch(url, {
41
		method: 'PATCH',
42
		headers: {
43
			'Content-Type': 'application/json',
44
			'Circle-Token': auth.token
45
		},
46
		body: JSON.stringify(body)
47
	})
48
	if (!response.ok) {
49
		const text = await response.text()
50
		throw new Error(`${response.status} ${text}`)
51
	}
52
	return await response.json()
53
}
54