Prefer the github login annotation over the name field when applying location annotations

Signed-off-by: Jack Grigg <jrgrigg@gmail.com>
This commit is contained in:
Jack Grigg
2023-02-02 11:06:06 +11:00
parent f4e4f04152
commit 4a123fe82a
3 changed files with 31 additions and 3 deletions
@@ -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';
@@ -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: {
@@ -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: {