Edits history of script submission #20146 for ' Bulk remove an organizations issues (sentry)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Bulk remove an organizations issues
     * Permanently remove the given issues. If IDs are provided, queries and filtering will be ignored. If any IDs are out of scope, the data won't be mutated but the endpoint will still produce a successful response. For example, if no issues were found matching the criteria, a HTTP 204 is returned.
     */
    export async function main(
    	auth: RT.Sentry,
    	environment?: string | undefined,
    	project?: string | undefined,
    	id?: string | undefined,
    	query?: string | undefined,
    	viewId?: string | undefined,
    	sort?: 'date' | 'freq' | 'inbox' | 'new' | 'trends' | 'user' | undefined,
    	limit?: string | undefined
    ) {
    	const url = new URL(
    		`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/issues/`
    	)
    	for (const [k, v] of [
    		['environment', environment],
    		['project', project],
    		['id', id],
    		['query', query],
    		['viewId', viewId],
    		['sort', sort],
    		['limit', limit]
    	]) {
    		if (v !== undefined && v !== '') {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'DELETE',
    		headers: {
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.text()
    }
    

    Submitted by hugo697 235 days ago