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

Identical to GET /repositories/{workspace}/{repo_slug}/commits, 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 645 days ago Viewed 22514 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 645 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * List commits with include/exclude
7
 * Identical to `GET /repositories/{workspace}/{repo_slug}/commits`,
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
  workspace: string
17
) {
18
  const url = new URL(
19
    `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commits`
20
  );
21

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