type Bitbucket = {
username: string;
password: string;
};
/**
* List commits that modified a file
* Returns a paginated list of commits that modified the specified file.
*/
export async function main(
auth: Bitbucket,
commit: string,
path: string,
repo_slug: string,
workspace: string,
renames: string | undefined,
q: string | undefined,
sort: string | undefined
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/filehistory/${commit}/${path}`
);
for (const [k, v] of [
["renames", renames],
["q", q],
["sort", sort],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 375 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* List commits that modified a file
* Returns a paginated list of commits that modified the specified file.
*/
export async function main(
auth: Bitbucket,
commit: string,
path: string,
repo_slug: string,
workspace: string,
renames: string | undefined,
q: string | undefined,
sort: string | undefined
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/filehistory/${commit}/${path}`
);
for (const [k, v] of [
["renames", renames],
["q", q],
["sort", sort],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 935 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* List commits that modified a file
* Returns a paginated list of commits that modified the specified file.
Commits are returned in reverse chronological order. This is roughly
equivalent to the following commands:
$ git log --follow --date-order <sha> <path>
By default, Bitbucket will follow renames and the path name in the
returned entries reflects that. This can be turned off using the
`?renames=false` query parameter.
Results are returned in descending chronological order by default, and
like most endpoints you can
[filter and sort](/cloud/bitbucket/rest/intro/#filtering) the response to
only provide exactly the data you want.
For example, if you wanted to find commits made before 2011-05-18
against a file named `README.rst`, but you only wanted the path and
date, your query would look like this:
```
$ curl 'https://api.bitbucket.org/2.0/repositories/evzijst/dogslow/filehistory/master/README.rst'\
'?fields=values.next,values.path,values.commit.date&q=commit.date<=2011-05-18'
{
"values": [
{
"commit": {
"date": "2011-05-17T07:32:09+00:00"
},
"path": "README.rst"
},
{
"commit": {
"date": "2011-05-16T06:33:28+00:00"
},
"path": "README.txt"
},
{
"commit": {
"date": "2011-05-16T06:15:39+00:00"
},
"path": "README.txt"
}
]
}
```
In the response you can see that the file was renamed to `README.rst`
by the commit made on 2011-05-16, and was previously named `README.txt`.
*/
export async function main(
auth: Bitbucket,
commit: string,
path: string,
repo_slug: string,
workspace: string,
renames: string | undefined,
q: string | undefined,
sort: string | undefined
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/filehistory/${commit}/${path}`
);
for (const [k, v] of [
["renames", renames],
["q", q],
["sort", sort],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 935 days ago