refct(events,catalog/github): use team-id instead node-id

Signed-off-by: Rogerio Angeliski <angeliski@hotmail.com>
This commit is contained in:
Rogerio Angeliski
2022-12-01 19:49:53 +00:00
parent 1f18561c9b
commit cf716d4a25
7 changed files with 28 additions and 18 deletions
+1 -1
View File
@@ -167,7 +167,7 @@ transformation if you only need to change a few properties.
**Attention:**
When you use the Events Support with a `TeamTransformer`, you need to ensure your entity will have the
annotation `github.com/node-id` with the value from `team.id`. Without this, the `team.edit` event could fail to update
annotation `github.com/team-id` with the value from `team.databaseId`. Without this, the `team.edit` event could fail to update
### Resolving GitHub users via organization email
@@ -253,7 +253,7 @@ export class GithubOrgReaderProcessor implements CatalogProcessor {
// @public
export type GithubTeam = {
id: string;
databaseId: number;
slug: string;
combinedSlug: string;
name?: string;
@@ -88,9 +88,12 @@ export const defaultOrganizationTeamTransformer: TeamTransformer =
async team => {
const annotations: { [annotationName: string]: string } = {
'github.com/team-slug': team.combinedSlug,
'github.com/node-id': team.id,
};
if (team.databaseId) {
annotations['github.com/team-id'] = `${team.databaseId}`;
}
if (team.editTeamUrl) {
annotations['backstage.io/edit-url'] = team.editTeamUrl;
}
@@ -209,7 +209,7 @@ describe('github', () => {
pageInfo: { hasNextPage: false },
nodes: [
{
id: 'node-id-1',
databaseId: 1,
slug: 'team',
combinedSlug: 'blah/team',
name: 'Team',
@@ -217,7 +217,7 @@ describe('github', () => {
avatarUrl: 'http://example.com/team.jpeg',
editTeamUrl: 'http://example.com/orgs/blah/teams/team/edit',
parentTeam: {
id: 'node-id-parent',
databaseId: 2,
slug: 'parent',
combinedSlug: '',
members: [],
@@ -242,7 +242,7 @@ describe('github', () => {
description: 'The one and only team',
annotations: {
'github.com/team-slug': 'blah/team',
'github.com/node-id': 'node-id-1',
'github.com/team-id': '1',
'backstage.io/edit-url':
'http://example.com/orgs/blah/teams/team/edit',
},
@@ -312,7 +312,7 @@ describe('github', () => {
pageInfo: { hasNextPage: false },
nodes: [
{
id: 'node-id-1',
databaseId: 1,
slug: 'team',
combinedSlug: 'blah/team',
name: 'Team',
@@ -320,7 +320,7 @@ describe('github', () => {
avatarUrl: 'http://example.com/team.jpeg',
editTeamUrl: 'http://example.com/orgs/blah/teams/team/edit',
parentTeam: {
id: 'node-id-parent',
databaseId: 3,
slug: 'parent',
combinedSlug: '',
members: [],
@@ -379,7 +379,7 @@ describe('github', () => {
pageInfo: { hasNextPage: false },
nodes: [
{
id: 'node-id-1',
databaseId: 1,
slug: 'team',
combinedSlug: 'blah/team',
name: 'Team',
@@ -387,7 +387,7 @@ describe('github', () => {
avatarUrl: 'http://example.com/team.jpeg',
editTeamUrl: 'http://example.com/orgs/blah/teams/team/edit',
parentTeam: {
id: 'node-id-parent',
databaseId: 3,
slug: 'parent',
combinedSlug: '',
members: [],
@@ -398,7 +398,7 @@ describe('github', () => {
},
},
{
id: 'node-id-2',
databaseId: 2,
slug: 'team',
combinedSlug: 'blah/team',
name: 'aa',
@@ -406,7 +406,7 @@ describe('github', () => {
avatarUrl: 'http://example.com/team.jpeg',
editTeamUrl: 'http://example.com/orgs/blah/teams/team/edit',
parentTeam: {
id: 'node-id-parent',
databaseId: 3,
slug: 'parent',
combinedSlug: '',
members: [],
@@ -467,7 +467,7 @@ describe('github', () => {
const input: QueryResponse = {
organization: {
team: {
id: 'node-id-1',
databaseId: 1,
slug: '',
combinedSlug: '',
members: {
@@ -72,7 +72,7 @@ export type GithubUser = {
* @public
*/
export type GithubTeam = {
id: string;
databaseId: number;
slug: string;
combinedSlug: string;
name?: string;
@@ -187,7 +187,7 @@ export async function getOrganizationTeams(
teams(first: 100, after: $cursor) {
pageInfo { hasNextPage, endCursor }
nodes {
id
databaseId
slug
combinedSlug
name
@@ -592,6 +592,7 @@ describe('GithubOrgEntityProvider', () => {
eventPayload: {
action: 'deleted',
team: {
databaseId: 1,
name: 'New Team',
slug: 'new-team',
description: 'description from the new team',
@@ -368,7 +368,13 @@ export class GithubOrgEntityProvider
const organizationTeamTransformer =
this.options.teamTransformer || defaultOrganizationTeamTransformer;
const { node_id: id, name, html_url: url, description, slug } = event.team;
const {
id: databaseId,
name,
html_url: url,
description,
slug,
} = event.team;
const org = event.organization.login;
const { headers } = await this.credentialsProvider.getCredentials({
url: this.options.orgUrl,
@@ -380,7 +386,7 @@ export class GithubOrgEntityProvider
const group = (await organizationTeamTransformer(
{
id,
databaseId,
name,
slug,
editTeamUrl: `${url}/edit`,
@@ -423,7 +429,7 @@ export class GithubOrgEntityProvider
filter: [
{
kind: 'Group',
[`metadata.annotations.github.com/node-id`]: event.team.node_id,
[`metadata.annotations.github.com/team-id`]: `${event.team.id}`,
},
],
fields: ['apiVersion', 'kind', 'metadata', 'spec'],