Changes based on latest round of feedback
Signed-off-by: Andre Wanlin <awanlin@rapidrtc.com>
This commit is contained in:
@@ -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