type Bitbucket = {
username: string;
password: string;
};
/**
* Search for code in a team's repositories
* Search for code in the repositories of the specified team.
*/
export async function main(
auth: Bitbucket,
username: string,
search_query: string | undefined,
page: string | undefined,
pagelen: string | undefined
) {
const url = new URL(
`https://api.bitbucket.org/2.0/teams/${username}/search/code`
);
for (const [k, v] of [
["search_query", search_query],
["page", page],
["pagelen", pagelen],
]) {
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 545 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Search for code in a team's repositories
* Search for code in the repositories of the specified team.
*/
export async function main(
auth: Bitbucket,
search_query: string | undefined,
page: string | undefined,
pagelen: string | undefined
) {
const url = new URL(
`https://api.bitbucket.org/2.0/teams/${auth.username}/search/code`
);
for (const [k, v] of [
["search_query", search_query],
["page", page],
["pagelen", pagelen],
]) {
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 551 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Search for code in a team's repositories
* Search for code in the repositories of the specified team.
Note that searches can match in the file's text (`content_matches`),
the path (`path_matches`), or both.
You can use the same syntax for the search query as in the UI.
E.g. to search for "foo" only within the repository "demo",
use the query parameter `search_query=foo+repo:demo`.
Similar to other APIs, you can request more fields using a
`fields` query parameter. E.g. to get some more information about
the repository of matched files, use the query parameter
`search_query=foo&fields=%2Bvalues.file.commit.repository`
(the `%2B` is a URL-encoded `+`).
Try `fields=%2Bvalues.*.*.*.*` to get an idea what's possible.
*/
export async function main(
auth: Bitbucket,
search_query: string | undefined,
page: string | undefined,
pagelen: string | undefined
) {
const url = new URL(
`https://api.bitbucket.org/2.0/teams/${auth.username}/search/code`
);
for (const [k, v] of [
["search_query", search_query],
["page", page],
["pagelen", pagelen],
]) {
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 551 days ago