0
List commits for revision using include/exclude
One script reply has been approved by the moderators Verified

Identical to GET /repositories/{workspace}/{repo_slug}/commits/{revision}, except that POST allows clients to place the include and exclude parameters in the request body to avoid URL length issues.

Note that this resource does NOT support new commit creation.

Created by hugo697 360 days ago Viewed 8993 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 360 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * List commits for revision using include/exclude
7
 * Identical to `GET /repositories/{workspace}/{repo_slug}/commits/{revision}`,
8
except that POST allows clients to place the include and exclude
9
parameters in the request body to avoid URL length issues.
10

11
**Note that this resource does NOT support new commit creation.**
12
 */
13
export async function main(
14
  auth: Bitbucket,
15
  repo_slug: string,
16
  revision: string,
17
  workspace: string
18
) {
19
  const url = new URL(
20
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commits/${revision}`
21
  );
22

23
  const response = await fetch(url, {
24
    method: "POST",
25
    headers: {
26
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
27
    },
28
    body: undefined,
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36