0

Makes a decision

by
Published Dec 20, 2024

This endpoint will evaluate input data (config+metadata) against owner's stored policies and return a decision.

Script circleci Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Circleci = {
3
	token: string
4
}
5
/**
6
 * Makes a decision
7
 * This endpoint will evaluate input data (config+metadata) against owner's stored policies and return a decision.
8
 */
9
export async function main(
10
	auth: Circleci,
11
	ownerID: string,
12
	context: string,
13
	body: { input: string; metadata?: {} }
14
) {
15
	const url = new URL(`https://circleci.com/api/v2/owner/${ownerID}/context/${context}/decision`)
16

17
	const response = await fetch(url, {
18
		method: 'POST',
19
		headers: {
20
			'Content-Type': 'application/json',
21
			'Circle-Token': auth.token
22
		},
23
		body: JSON.stringify(body)
24
	})
25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29
	return await response.json()
30
}
31