Edits history of script submission #20292 for ' Retrieve statuses of release thresholds alpha (sentry)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Retrieve statuses of release thresholds alpha
     * **`[WARNING]`**: This API is an experimental Alpha feature and is subject to change!
    
    List all derived statuses of releases that fall within the provided start/end datetimes.
    
    Constructs a response key'd off \{`release_version`\}-\{`project_slug`\} that lists thresholds with their status for *specified* projects.
    Each returned enriched threshold will contain the full serialized `release_threshold` instance as well as it's derived health statuses.
     */
    export async function main(
    	auth: RT.Sentry,
    	start: string | undefined,
    	end: string | undefined,
    	environment?: string | undefined,
    	projectSlug?: string | undefined,
    	release?: string | undefined
    ) {
    	const url = new URL(
    		`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/release-threshold-statuses/`
    	)
    	for (const [k, v] of [
    		['start', start],
    		['end', end],
    		['environment', environment],
    		['projectSlug', projectSlug],
    		['release', release]
    	]) {
    		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