Edits history of script submission #20289 for ' Retrieve paginated list of test results for repository owner and organization (sentry)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Retrieve paginated list of test results for repository owner and organization
     * Retrieves the list of test results for a given repository and owner. Also accepts a number of query parameters to filter the results.
     */
    export async function main(
    	auth: RT.Sentry,
    	owner: string,
    	repository: string,
    	sortBy?: string | undefined,
    	filterBy?: string | undefined,
    	interval?: string | undefined,
    	branch?: string | undefined,
    	limit?: string | undefined,
    	navigation?: string | undefined,
    	cursor?: string | undefined,
    	term?: string | undefined
    ) {
    	const url = new URL(
    		`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/prevent/owner/${owner}/repository/${repository}/test-results/`
    	)
    	for (const [k, v] of [
    		['sortBy', sortBy],
    		['filterBy', filterBy],
    		['interval', interval],
    		['branch', branch],
    		['limit', limit],
    		['navigation', navigation],
    		['cursor', cursor],
    		['term', term]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 235 days ago