Merge pull request #25460 from benjidotsh/feat/scaffolder-bitbucket-autocomplete-branch

feat(scaffolder): add RepoBranchPicker field extension
This commit is contained in:
Ben Lambert
2024-08-06 12:55:40 +02:00
committed by GitHub
25 changed files with 1147 additions and 12 deletions
@@ -12,6 +12,12 @@ export class BitbucketCloudClient {
config: BitbucketCloudIntegrationConfig,
): BitbucketCloudClient;
// (undocumented)
listBranchesByRepository(
repository: string,
workspace: string,
options?: FilterAndSortOptions & PartialResponseOptions,
): WithPagination<Models.PaginatedBranches, Models.Branch>;
// (undocumented)
listProjectsByWorkspace(
workspace: string,
options?: FilterAndSortOptions & PartialResponseOptions,
@@ -209,6 +215,9 @@ export namespace Models {
size?: number;
values?: Array<TResultItem> | Set<TResultItem>;
}
export interface PaginatedBranches extends Paginated<Branch> {
values?: Set<Branch>;
}
export interface PaginatedProjects extends Paginated<Project> {
values?: Set<Project>;
}
@@ -162,4 +162,33 @@ describe('BitbucketCloudClient', () => {
expect(results).toHaveLength(1);
expect(results[0].slug).toEqual('workspace1');
});
it('listBranchesByRepository', async () => {
server.use(
rest.get(
'https://api.bitbucket.org/2.0/repositories/workspace1/repo1/refs/branches',
(_, res, ctx) => {
const response = {
values: [
{
type: 'branch',
name: 'branch1',
} as Models.Branch,
],
};
return res(ctx.json(response));
},
),
);
const pagination = client.listBranchesByRepository('repo1', 'workspace1');
const results = [];
for await (const result of pagination.iterateResults()) {
results.push(result);
}
expect(results).toHaveLength(1);
expect(results[0].name).toEqual('branch1');
});
});
@@ -95,6 +95,26 @@ export class BitbucketCloudClient {
);
}
listBranchesByRepository(
repository: string,
workspace: string,
options?: FilterAndSortOptions & PartialResponseOptions,
): WithPagination<Models.PaginatedBranches, Models.Branch> {
const workspaceEnc = encodeURIComponent(workspace);
return new WithPagination(
paginationOptions =>
this.createUrl(
`/repositories/${workspaceEnc}/${repository}/refs/branches`,
{
...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) {
@@ -275,6 +275,17 @@ export namespace Models {
values?: Set<Workspace>;
}
/**
* A paginated list of branches.
* @public
*/
export interface PaginatedBranches extends Paginated<Branch> {
/**
* The values of the current page.
*/
values?: Set<Branch>;
}
/**
* Object describing a user's role on resources like commits or pull requests.
* @public