Changes based on latest round of feedback
Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
'@backstage/plugin-azure-devops': minor
|
||||
---
|
||||
|
||||
Updated to support cases where only Azure Pipelines are being used by adding an annotation that get builds by definition name
|
||||
Updated to support cases where only Azure Pipelines to see Builds. You can use this new feature by adding the `dev.azure.com/project` and `dev.azure.com/build-definition` annotations to your `catalog-info.yaml` files. The Azure DevOps plugin [README has more detailed instructions](https://github.com/backstage/backstage/tree/master/plugins/azure-devops#setup).
|
||||
|
||||
@@ -51,13 +51,14 @@ spec:
|
||||
|
||||
#### Azure Pipelines Only
|
||||
|
||||
If you are only using Azure Pipelines along with a different SCM tool then you can use the following annotation to see Builds:
|
||||
If you are only using Azure Pipelines along with a different SCM tool then you can use the following two annotations to see Builds:
|
||||
|
||||
```yaml
|
||||
dev.azure.com/project-definition: <project-name>/<definition-name>
|
||||
dev.azure.com/project: <project-name>
|
||||
dev.azure.com/build-definition: <build-definition-name>
|
||||
```
|
||||
|
||||
In this case `<project-name>` will be the name of your Team Project and `<definition-name>` will be the name of the Build Definition you would like to see Builds for. If the Build Definition name has spaces in it make sure to put quotes around it
|
||||
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. If the Build Definition name has spaces in it make sure to put quotes around it
|
||||
|
||||
### Azure Pipelines Component
|
||||
|
||||
@@ -93,7 +94,7 @@ To get the Azure Pipelines component working you'll need to do the following two
|
||||
</EntitySwitch>
|
||||
```
|
||||
|
||||
2. If you are using the `dev.azure.com/project-definition` annotation then you'll want to do this:
|
||||
2. If you are using the ``dev.azure.com/project` and `dev.azure.com/build-definition` annotations then you'll want to do this:
|
||||
|
||||
```tsx
|
||||
// In packages/app/src/components/catalog/EntityPage.tsx
|
||||
|
||||
@@ -51,7 +51,7 @@ export interface AzureDevOpsApi {
|
||||
getAllTeams(): Promise<Team[]>;
|
||||
|
||||
getUserTeamIds(userId: string): Promise<string[]>;
|
||||
|
||||
|
||||
getBuildRuns(
|
||||
projectName: string,
|
||||
repoName?: string,
|
||||
|
||||
@@ -93,7 +93,7 @@ export class AzureDevOpsClient implements AzureDevOpsApi {
|
||||
public getUserTeamIds(userId: string): Promise<string[]> {
|
||||
return this.get<string[]>(`users/${userId}/team-ids`);
|
||||
}
|
||||
|
||||
|
||||
public async getBuildRuns(
|
||||
projectName: string,
|
||||
repoName?: string,
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export const AZURE_DEVOPS_BUILD_DEFINITION_ANNOTATION =
|
||||
'dev.azure.com/build-definition';
|
||||
export const AZURE_DEVOPS_PROJECT_ANNOTATION = 'dev.azure.com/project';
|
||||
export const AZURE_DEVOPS_REPO_ANNOTATION = 'dev.azure.com/project-repo';
|
||||
export const AZURE_DEVOPS_DEFINITION_ANNOTATION =
|
||||
'dev.azure.com/project-definition';
|
||||
export const AZURE_DEVOPS_DEFAULT_TOP: number = 10;
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
AZURE_DEVOPS_DEFINITION_ANNOTATION,
|
||||
AZURE_DEVOPS_BUILD_DEFINITION_ANNOTATION,
|
||||
AZURE_DEVOPS_PROJECT_ANNOTATION,
|
||||
AZURE_DEVOPS_REPO_ANNOTATION,
|
||||
} from './constants';
|
||||
import {
|
||||
@@ -40,7 +41,10 @@ export const isAzureDevOpsAvailable = (entity: Entity) =>
|
||||
|
||||
export const isAzurePipelinesAvailable = (entity: Entity) =>
|
||||
Boolean(entity.metadata.annotations?.[AZURE_DEVOPS_REPO_ANNOTATION]) ||
|
||||
Boolean(entity.metadata.annotations?.[AZURE_DEVOPS_DEFINITION_ANNOTATION]);
|
||||
(Boolean(entity.metadata.annotations?.[AZURE_DEVOPS_PROJECT_ANNOTATION]) &&
|
||||
Boolean(
|
||||
entity.metadata.annotations?.[AZURE_DEVOPS_BUILD_DEFINITION_ANNOTATION],
|
||||
));
|
||||
|
||||
export const azureDevOpsPlugin = createPlugin({
|
||||
id: 'azureDevOps',
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
AZURE_DEVOPS_DEFINITION_ANNOTATION,
|
||||
AZURE_DEVOPS_BUILD_DEFINITION_ANNOTATION,
|
||||
AZURE_DEVOPS_PROJECT_ANNOTATION,
|
||||
AZURE_DEVOPS_REPO_ANNOTATION,
|
||||
} from '../constants';
|
||||
|
||||
@@ -26,37 +27,30 @@ export function getAnnotationFromEntity(entity: Entity): {
|
||||
repo?: string;
|
||||
definition?: string;
|
||||
} {
|
||||
let annotation =
|
||||
entity.metadata.annotations?.[AZURE_DEVOPS_DEFINITION_ANNOTATION];
|
||||
if (annotation) {
|
||||
const { project, definition } = getProjectDefinition(annotation);
|
||||
const repo = undefined;
|
||||
return { project, repo, definition };
|
||||
}
|
||||
|
||||
annotation = entity.metadata.annotations?.[AZURE_DEVOPS_REPO_ANNOTATION];
|
||||
const annotation =
|
||||
entity.metadata.annotations?.[AZURE_DEVOPS_REPO_ANNOTATION];
|
||||
if (annotation) {
|
||||
const { project, repo } = getProjectRepo(annotation);
|
||||
const definition = undefined;
|
||||
return { project, repo, definition };
|
||||
}
|
||||
|
||||
throw new Error('No supported Azure DevOps annotation was found');
|
||||
}
|
||||
const project =
|
||||
entity.metadata.annotations?.[AZURE_DEVOPS_PROJECT_ANNOTATION];
|
||||
if (!project) {
|
||||
throw new Error('Value for annotation dev.azure.com/project was not found');
|
||||
}
|
||||
|
||||
function getProjectDefinition(annotation: string): {
|
||||
project: string;
|
||||
definition: string;
|
||||
} {
|
||||
const [project, definition] = annotation.split('/');
|
||||
|
||||
if (!project && !definition) {
|
||||
const definition =
|
||||
entity.metadata.annotations?.[AZURE_DEVOPS_BUILD_DEFINITION_ANNOTATION];
|
||||
if (!definition) {
|
||||
throw new Error(
|
||||
'Value for annotation dev.azure.com/project-definition was not in the correct format: <project-name>/<definition-name>',
|
||||
'Value for annotation dev.azure.com/build-definition was not found',
|
||||
);
|
||||
}
|
||||
|
||||
return { project, definition };
|
||||
const repo = undefined;
|
||||
return { project, repo, definition };
|
||||
}
|
||||
|
||||
function getProjectRepo(annotation: string): {
|
||||
|
||||
Reference in New Issue
Block a user