Merge pull request #21595 from awanlin/topic/use-host-org-everywhere
Added multi-org support
This commit is contained in:
@@ -72,6 +72,53 @@ dev.azure.com/build-definition: <build-definition-name>
|
||||
|
||||
In this case `<project-name>` will be the name of your Team Project and `<build-definition-name>` will be the name of the Build Definition you would like to see Builds for, and it's possible to add more Builds separated by a comma. If the Build Definition name has spaces in it make sure to put quotes around it.
|
||||
|
||||
#### Multiple Organizations
|
||||
|
||||
If you have multiple organizations you'll need to also add this annotation:
|
||||
|
||||
```yaml
|
||||
dev.azure.com/host-org: <host>/<organization>
|
||||
```
|
||||
|
||||
For this annotation `<host>` will match the `host` value in the `integrations.azure` section in your `app-config.yaml` and `<organization>` will be the name of the Organization that is part of the `host`. Let's break this down with an example:
|
||||
|
||||
Say we have the following `integrations.azure` section:
|
||||
|
||||
```yaml
|
||||
integrations:
|
||||
azure:
|
||||
- host: dev.azure.com
|
||||
credentials:
|
||||
- organizations:
|
||||
- my-org
|
||||
- my-other-org
|
||||
clientId: ${AZURE_CLIENT_ID}
|
||||
clientSecret: ${AZURE_CLIENT_SECRET}
|
||||
tenantId: ${AZURE_TENANT_ID}
|
||||
- organizations:
|
||||
- another-org
|
||||
clientId: ${AZURE_CLIENT_ID}
|
||||
- host: server.company.com
|
||||
credentials:
|
||||
- organizations:
|
||||
- yet-another-org
|
||||
personalAccessToken: ${PERSONAL_ACCESS_TOKEN}
|
||||
```
|
||||
|
||||
If the entity we are viewing lives in the `my-other-org` organization then the `dev.azure.com/host-org` annotation would look like this:
|
||||
|
||||
```yaml
|
||||
dev.azure.com/host-org: dev.azure.com/my-other-org
|
||||
```
|
||||
|
||||
And if the entity was from `yet-another-org` it would look like this:
|
||||
|
||||
```yaml
|
||||
dev.azure.com/host-org: server.company.com/yet-another-org
|
||||
```
|
||||
|
||||
**Note:** To save you time, effort, and confusion setting up these annotations manually you can use the `AzureDevOpsAnnotatorProcessor` processor which will add the `dev.azure.com/host-org` and `dev.azure.com/project-repo` annotations for you with the correct values. The Azure DevOps backend plugin has details on how to [add this processor](https://github.com/backstage/backstage/tree/master/plugins/azure-devops-backend#processor).
|
||||
|
||||
### Azure Pipelines Component
|
||||
|
||||
To get the Azure Pipelines component working you'll need to do the following two steps:
|
||||
@@ -247,8 +294,3 @@ To get the README component working you'll need to do the following two steps:
|
||||
- You'll need to add the `EntitySwitch.Case` above from step 2 to all the entity sections you want to see Readme in. For example if you wanted to see Readme when looking at Website entities then you would need to add this to the `websiteEntityPage` section.
|
||||
- The `if` prop is optional on the `EntitySwitch.Case`, you can remove it if you always want to see the tab even if the entity being viewed does not have the needed annotation
|
||||
- The `maxHeight` property on the `EntityAzureReadmeCard` will set the maximum screen size you would like to see, if not set it will default to 100%
|
||||
|
||||
## Limitations
|
||||
|
||||
- Currently multiple organizations are not supported
|
||||
- Mixing Azure DevOps Services (cloud) and Azure DevOps Server (on-premise) is not supported
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user