Added multi-org support

Signed-off-by: Andre Wanlin <awanlin@spotify.com>
This commit is contained in:
Andre Wanlin
2023-11-27 18:35:41 -06:00
parent df4a219c52
commit c70e4f52eb
13 changed files with 202 additions and 31 deletions
+16
View File
@@ -71,6 +71,8 @@ export interface AzureDevOpsApi {
projectName: string,
repoName?: string,
definitionName?: string,
host?: string,
org?: string,
options?: BuildRunOptions,
): Promise<{
items: BuildRun[];
@@ -83,6 +85,8 @@ export interface AzureDevOpsApi {
getGitTags(
projectName: string,
repoName: string,
host?: string,
org?: string,
): Promise<{
items: GitTag[];
}>;
@@ -90,6 +94,8 @@ export interface AzureDevOpsApi {
getPullRequests(
projectName: string,
repoName: string,
host?: string,
org?: string,
options?: PullRequestOptions,
): Promise<{
items: PullRequest[];
@@ -100,6 +106,8 @@ export interface AzureDevOpsApi {
getRepoBuilds(
projectName: string,
repoName: string,
host?: string,
org?: string,
options?: RepoBuildOptions,
): Promise<{
items: RepoBuild[];
@@ -124,6 +132,8 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
projectName: string,
repoName?: string,
definitionName?: string,
host?: string,
org?: string,
options?: BuildRunOptions,
): Promise<{
items: BuildRun[];
@@ -136,6 +146,8 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
getGitTags(
projectName: string,
repoName: string,
host?: string,
org?: string,
): Promise<{
items: GitTag[];
}>;
@@ -143,6 +155,8 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
getPullRequests(
projectName: string,
repoName: string,
host?: string,
org?: string,
options?: PullRequestOptions,
): Promise<{
items: PullRequest[];
@@ -153,6 +167,8 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
getRepoBuilds(
projectName: string,
repoName: string,
host?: string,
org?: string,
options?: RepoBuildOptions,
): Promise<{
items: RepoBuild[];
@@ -40,17 +40,23 @@ export interface AzureDevOpsApi {
getRepoBuilds(
projectName: string,
repoName: string,
host?: string,
org?: string,
options?: RepoBuildOptions,
): Promise<{ items: RepoBuild[] }>;
getGitTags(
projectName: string,
repoName: string,
host?: string,
org?: string,
): Promise<{ items: GitTag[] }>;
getPullRequests(
projectName: string,
repoName: string,
host?: string,
org?: string,
options?: PullRequestOptions,
): Promise<{ items: PullRequest[] }>;
@@ -66,6 +72,8 @@ export interface AzureDevOpsApi {
projectName: string,
repoName?: string,
definitionName?: string,
host?: string,
org?: string,
options?: BuildRunOptions,
): Promise<{ items: BuildRun[] }>;
@@ -47,12 +47,20 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
public async getRepoBuilds(
projectName: string,
repoName: string,
host?: string,
org?: string,
options?: RepoBuildOptions,
): Promise<{ items: RepoBuild[] }> {
const queryString = new URLSearchParams();
if (options?.top) {
queryString.append('top', options.top.toString());
}
if (host) {
queryString.append('host', host);
}
if (org) {
queryString.append('org', org);
}
const urlSegment = `repo-builds/${encodeURIComponent(
projectName,
)}/${encodeURIComponent(repoName)}?${queryString}`;
@@ -64,10 +72,19 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
public async getGitTags(
projectName: string,
repoName: string,
host?: string,
org?: string,
): Promise<{ items: GitTag[] }> {
const queryString = new URLSearchParams();
if (host) {
queryString.append('host', host);
}
if (org) {
queryString.append('org', org);
}
const urlSegment = `git-tags/${encodeURIComponent(
projectName,
)}/${encodeURIComponent(repoName)}`;
)}/${encodeURIComponent(repoName)}?${queryString}`;
const items = await this.get<GitTag[]>(urlSegment);
return { items };
@@ -76,6 +93,8 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
public async getPullRequests(
projectName: string,
repoName: string,
host?: string,
org?: string,
options?: PullRequestOptions,
): Promise<{ items: PullRequest[] }> {
const queryString = new URLSearchParams();
@@ -85,6 +104,12 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
if (options?.status) {
queryString.append('status', options.status.toString());
}
if (host) {
queryString.append('host', host);
}
if (org) {
queryString.append('org', org);
}
const urlSegment = `pull-requests/${encodeURIComponent(
projectName,
)}/${encodeURIComponent(repoName)}?${queryString}`;
@@ -113,12 +138,20 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
projectName: string,
repoName?: string,
definitionName?: string,
host?: string,
org?: string,
options?: BuildRunOptions,
): Promise<{ items: BuildRun[] }> {
const queryString = new URLSearchParams();
if (repoName) {
queryString.append('repoName', repoName);
}
if (host) {
queryString.append('host', host);
}
if (org) {
queryString.append('org', org);
}
if (definitionName) {
const definitionNames = definitionName.split(',');
if (definitionNames.length > 1) {
@@ -149,10 +182,17 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
}
public async getReadme(opts: ReadmeConfig): Promise<Readme> {
const queryString = new URLSearchParams();
if (opts.host) {
queryString.append('host', opts.host);
}
if (opts.org) {
queryString.append('org', opts.org);
}
return await this.get(
`readme/${encodeURIComponent(opts.project)}/${encodeURIComponent(
opts.repo,
)}`,
)}?${queryString}`,
);
}
@@ -42,8 +42,9 @@ export function useBuildRuns(
const api = useApi(azureDevOpsApiRef);
const { value, loading, error } = useAsync(() => {
const { project, repo, definition } = getAnnotationValuesFromEntity(entity);
return api.getBuildRuns(project, repo, definition, options);
const { project, repo, definition, host, org } =
getAnnotationValuesFromEntity(entity);
return api.getBuildRuns(project, repo, definition, host, org, options);
}, [api]);
return {
+2 -2
View File
@@ -30,8 +30,8 @@ export function useGitTags(entity: Entity): {
const api = useApi(azureDevOpsApiRef);
const { value, loading, error } = useAsync(() => {
const { project, repo } = getAnnotationValuesFromEntity(entity);
return api.getGitTags(project, repo as string);
const { project, repo, host, org } = getAnnotationValuesFromEntity(entity);
return api.getGitTags(project, repo as string, host, org);
}, [api]);
return {
@@ -46,8 +46,8 @@ export function usePullRequests(
const api = useApi(azureDevOpsApiRef);
const { value, loading, error } = useAsync(() => {
const { project, repo } = getAnnotationValuesFromEntity(entity);
return api.getPullRequests(project, repo as string, options);
const { project, repo, host, org } = getAnnotationValuesFromEntity(entity);
return api.getPullRequests(project, repo as string, host, org, options);
}, [api, top, status]);
return {
+2 -2
View File
@@ -30,8 +30,8 @@ export function useReadme(entity: Entity): {
const api = useApi(azureDevOpsApiRef);
const { value, loading, error } = useAsync(() => {
const { project, repo } = getAnnotationValuesFromEntity(entity);
return api.getReadme({ project, repo: repo as string });
const { project, repo, host, org } = getAnnotationValuesFromEntity(entity);
return api.getReadme({ project, repo: repo as string, host, org });
}, [api]);
return {