diff --git a/plugins/catalog-backend-module-github/src/lib/annotation.ts b/plugins/catalog-backend-module-github/src/lib/annotation.ts new file mode 100644 index 0000000000..b80e10c8b5 --- /dev/null +++ b/plugins/catalog-backend-module-github/src/lib/annotation.ts @@ -0,0 +1,23 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * The value of this annotation is the so-called login that identifies a user on +[GitHub](https://github.com) + * + * @public + */ +export const ANNOTATION_GITHUB_USER_LOGIN = 'github.com/user-login'; diff --git a/plugins/catalog-backend-module-github/src/lib/defaultTransformers.ts b/plugins/catalog-backend-module-github/src/lib/defaultTransformers.ts index efd3eedd5d..cf6edde1dc 100644 --- a/plugins/catalog-backend-module-github/src/lib/defaultTransformers.ts +++ b/plugins/catalog-backend-module-github/src/lib/defaultTransformers.ts @@ -16,6 +16,7 @@ import { GroupEntity, UserEntity } from '@backstage/catalog-model'; import { graphql } from '@octokit/graphql'; +import { ANNOTATION_GITHUB_USER_LOGIN } from './annotation'; import { GithubTeam, GithubUser } from './github'; /** @@ -63,7 +64,7 @@ export const defaultUserTransformer: UserTransformer = async ( metadata: { name: item.login, annotations: { - 'github.com/user-login': item.login, + [ANNOTATION_GITHUB_USER_LOGIN]: item.login, }, }, spec: { diff --git a/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts index 3093c2a897..95e3780f76 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts @@ -65,6 +65,7 @@ import { getOrganizationTeam, getOrganizationTeamsFromUsers, } from '../lib/github'; +import { ANNOTATION_GITHUB_USER_LOGIN } from '../lib/annotation'; /** * Options for {@link GithubOrgEntityProvider}. @@ -602,10 +603,13 @@ export function withLocations( org: string, entity: Entity, ): Entity { + const login = + entity.metadata.annotations[ANNOTATION_GITHUB_USER_LOGIN] || + entity.metadata.name; const location = entity.kind === 'Group' - ? `url:${baseUrl}/orgs/${org}/teams/${entity.metadata.name}` - : `url:${baseUrl}/${entity.metadata.name}`; + ? `url:${baseUrl}/orgs/${org}/teams/${login}` + : `url:${baseUrl}/${login}`; return merge( { metadata: {