()
| 27 | }; |
| 28 | |
| 29 | async function getEnvs() { |
| 30 | const { |
| 31 | BITBUCKET_REPO_OWNER: owner, |
| 32 | BITBUCKET_REPO_NAME: repo, |
| 33 | BITBUCKET_OUATH_CONSUMER_KEY: consumerKey, |
| 34 | BITBUCKET_OUATH_CONSUMER_SECRET: consumerSecret, |
| 35 | } = process.env; |
| 36 | if (!owner || !repo || !consumerKey || !consumerSecret) { |
| 37 | throw new Error( |
| 38 | 'Please set BITBUCKET_REPO_OWNER, BITBUCKET_REPO_NAME, BITBUCKET_OUATH_CONSUMER_KEY, BITBUCKET_OUATH_CONSUMER_SECRET environment variables', |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | const params = new URLSearchParams(); |
| 43 | params.append('grant_type', 'client_credentials'); |
| 44 | |
| 45 | const { |
| 46 | access_token: token, |
| 47 | } = await fetch( |
| 48 | `https://${consumerKey}:${consumerSecret}@bitbucket.org/site/oauth2/access_token`, |
| 49 | { method: 'POST', body: params }, |
| 50 | ).then(r => r.json()); |
| 51 | |
| 52 | return { owner, repo, token }; |
| 53 | } |
| 54 | |
| 55 | const API_URL = 'https://api.bitbucket.org/2.0/'; |
| 56 |
no outgoing calls
no test coverage detected