//native
type Circleci = {
token: string
}
/**
* Trigger a new pipeline
* Not available to projects that use GitLab or GitHub App. Triggers a new pipeline on the project. **GitHub App users should use the [new Trigger Pipeline API](#tag/Pipeline/operation/triggerPipelineRun)**.
*/
export async function main(
auth: Circleci,
project_slug: string,
body: { branch?: string; tag?: string; parameters?: {} }
) {
const url = new URL(`https://circleci.com/api/v2/project/${project_slug}/pipeline`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Circle-Token': auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 536 days ago