0
Get project analyses
One script reply has been approved by the moderators Verified

List all analyses for a project

Created by hugo697 2 days ago Viewed 0 times
0
Submitted by hugo697 Bun
Verified 2 days ago
1
//native
2
type Botify = {
3
	token: string
4
}
5
/**
6
 * Get project analyses
7
 * List all analyses for a project
8
 */
9
export async function main(
10
	auth: Botify,
11
	username: string,
12
	project_slug: string,
13
	page: string | undefined,
14
	size: string | undefined,
15
	only_success: string | undefined,
16
	fields: string | undefined
17
) {
18
	const url = new URL(`https://api.botify.com/analyses/${username}/${project_slug}`)
19
	for (const [k, v] of [
20
		['page', page],
21
		['size', size],
22
		['only_success', only_success],
23
		['fields', fields]
24
	]) {
25
		if (v !== undefined && v !== '' && k !== undefined) {
26
			url.searchParams.append(k, v)
27
		}
28
	}
29
	const response = await fetch(url, {
30
		method: 'GET',
31
		headers: {
32
			Authorization: 'Token ' + auth.token
33
		},
34
		body: undefined
35
	})
36
	if (!response.ok) {
37
		const text = await response.text()
38
		throw new Error(`${response.status} ${text}`)
39
	}
40
	return await response.text()
41
}
42