Merge pull request #25132 from benjidotsh/feat/scaffolder-bitbucket-autocomplete
feat(scaffolder): add autocompletion for Bitbucket
This commit is contained in:
@@ -12,11 +12,20 @@ export class BitbucketCloudClient {
|
||||
config: BitbucketCloudIntegrationConfig,
|
||||
): BitbucketCloudClient;
|
||||
// (undocumented)
|
||||
listProjectsByWorkspace(
|
||||
workspace: string,
|
||||
options?: FilterAndSortOptions & PartialResponseOptions,
|
||||
): WithPagination<Models.PaginatedProjects, Models.Project>;
|
||||
// (undocumented)
|
||||
listRepositoriesByWorkspace(
|
||||
workspace: string,
|
||||
options?: FilterAndSortOptions & PartialResponseOptions,
|
||||
): WithPagination<Models.PaginatedRepositories, Models.Repository>;
|
||||
// (undocumented)
|
||||
listWorkspaces(
|
||||
options?: FilterAndSortOptions & PartialResponseOptions,
|
||||
): WithPagination<Models.PaginatedWorkspaces, Models.Workspace>;
|
||||
// (undocumented)
|
||||
searchCode(
|
||||
workspace: string,
|
||||
query: string,
|
||||
@@ -200,9 +209,15 @@ export namespace Models {
|
||||
size?: number;
|
||||
values?: Array<TResultItem> | Set<TResultItem>;
|
||||
}
|
||||
export interface PaginatedProjects extends Paginated<Project> {
|
||||
values?: Set<Project>;
|
||||
}
|
||||
export interface PaginatedRepositories extends Paginated<Repository> {
|
||||
values?: Set<Repository>;
|
||||
}
|
||||
export interface PaginatedWorkspaces extends Paginated<Workspace> {
|
||||
values?: Set<Workspace>;
|
||||
}
|
||||
export interface Participant extends ModelObject {
|
||||
// (undocumented)
|
||||
approved?: boolean;
|
||||
|
||||
@@ -107,4 +107,59 @@ describe('BitbucketCloudClient', () => {
|
||||
expect(results).toHaveLength(1);
|
||||
expect(results[0].slug).toEqual('repo1');
|
||||
});
|
||||
|
||||
it('listProjectsByWorkspace', async () => {
|
||||
server.use(
|
||||
rest.get(
|
||||
'https://api.bitbucket.org/2.0/workspaces/ws/projects',
|
||||
(_, res, ctx) => {
|
||||
const response = {
|
||||
values: [
|
||||
{
|
||||
type: 'project',
|
||||
slug: 'project1',
|
||||
} as Models.Project,
|
||||
],
|
||||
};
|
||||
return res(ctx.json(response));
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
const pagination = client.listProjectsByWorkspace('ws');
|
||||
|
||||
const results = [];
|
||||
for await (const result of pagination.iterateResults()) {
|
||||
results.push(result);
|
||||
}
|
||||
|
||||
expect(results).toHaveLength(1);
|
||||
expect(results[0].slug).toEqual('project1');
|
||||
});
|
||||
|
||||
it('listWorkspaces', async () => {
|
||||
server.use(
|
||||
rest.get('https://api.bitbucket.org/2.0/workspaces', (_, res, ctx) => {
|
||||
const response = {
|
||||
values: [
|
||||
{
|
||||
type: 'workspace',
|
||||
slug: 'workspace1',
|
||||
} as Models.Workspace,
|
||||
],
|
||||
};
|
||||
return res(ctx.json(response));
|
||||
}),
|
||||
);
|
||||
|
||||
const pagination = client.listWorkspaces();
|
||||
|
||||
const results = [];
|
||||
for await (const result of pagination.iterateResults()) {
|
||||
results.push(result);
|
||||
}
|
||||
|
||||
expect(results).toHaveLength(1);
|
||||
expect(results[0].slug).toEqual('workspace1');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -69,6 +69,32 @@ export class BitbucketCloudClient {
|
||||
);
|
||||
}
|
||||
|
||||
listProjectsByWorkspace(
|
||||
workspace: string,
|
||||
options?: FilterAndSortOptions & PartialResponseOptions,
|
||||
): WithPagination<Models.PaginatedProjects, Models.Project> {
|
||||
const workspaceEnc = encodeURIComponent(workspace);
|
||||
|
||||
return new WithPagination(
|
||||
paginationOptions =>
|
||||
this.createUrl(`/workspaces/${workspaceEnc}/projects`, {
|
||||
...paginationOptions,
|
||||
...options,
|
||||
}),
|
||||
url => this.getTypeMapped(url),
|
||||
);
|
||||
}
|
||||
|
||||
listWorkspaces(
|
||||
options?: FilterAndSortOptions & PartialResponseOptions,
|
||||
): WithPagination<Models.PaginatedWorkspaces, Models.Workspace> {
|
||||
return new WithPagination(
|
||||
paginationOptions =>
|
||||
this.createUrl('/workspaces', { ...paginationOptions, ...options }),
|
||||
url => this.getTypeMapped(url),
|
||||
);
|
||||
}
|
||||
|
||||
private createUrl(endpoint: string, options?: RequestOptions): URL {
|
||||
const request = new URL(this.config.apiBaseUrl + endpoint);
|
||||
for (const key in options) {
|
||||
@@ -113,6 +139,8 @@ export class BitbucketCloudClient {
|
||||
'utf8',
|
||||
);
|
||||
headers.Authorization = `Basic ${buffer.toString('base64')}`;
|
||||
} else if (this.config.token) {
|
||||
headers.Authorization = `Bearer ${this.config.token}`;
|
||||
}
|
||||
|
||||
return headers;
|
||||
|
||||
@@ -253,6 +253,28 @@ export namespace Models {
|
||||
values?: Set<Repository>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A paginated list of projects.
|
||||
* @public
|
||||
*/
|
||||
export interface PaginatedProjects extends Paginated<Project> {
|
||||
/**
|
||||
* The values of the current page.
|
||||
*/
|
||||
values?: Set<Project>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A paginated list of workspaces.
|
||||
* @public
|
||||
*/
|
||||
export interface PaginatedWorkspaces extends Paginated<Workspace> {
|
||||
/**
|
||||
* The values of the current page.
|
||||
*/
|
||||
values?: Set<Workspace>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object describing a user's role on resources like commits or pull requests.
|
||||
* @public
|
||||
|
||||
Reference in New Issue
Block a user