Skip to content

Commit

Permalink
fix(slack): Do not override existing picture (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaik authored Apr 10, 2024
1 parent 35a7625 commit 66f86b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions plugins/slack-catalog-backend/src/SlackUserProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,21 @@ describe('SlackUserProcessor', () => {
jest.clearAllMocks();
});

test('should add slack info', async () => {
test.each([
{ beforePicture: '', expectedPicture: 'rufus-192.png' },
{
beforePicture: 'https://example.com/me.jpg',
expectedPicture: 'https://example.com/me.jpg',
},
])('should add slack info', async ({ beforePicture, expectedPicture }) => {
const before: UserEntity = {
apiVersion: 'backstage.io/v1alpha1',
kind: 'User',
metadata: {
name: 'rufus',
},
spec: {
profile: {
email: '[email protected]',
},
profile: { email: '[email protected]', picture: beforePicture },
},
};
const result = await processor.postProcessEntity(
Expand All @@ -89,7 +93,7 @@ describe('SlackUserProcessor', () => {
},
spec: {
profile: {
picture: 'rufus-192.png',
picture: expectedPicture,
email: '[email protected]',
},
},
Expand Down
3 changes: 2 additions & 1 deletion plugins/slack-catalog-backend/src/SlackUserProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ export class SlackUserProcessor implements CatalogProcessor {
if (slackUser.id) {
entity.metadata.annotations['slack.com/user_id'] = slackUser.id;
}
if (slackUser.profile?.image_192) {
// if the user entity doesn't already have a profile picture set, *and* there's a slack avatar for the user, add that.
if (!entity.spec.profile.picture && slackUser.profile?.image_192) {
entity.spec.profile.picture = slackUser.profile.image_192;
}

Expand Down

0 comments on commit 66f86b1

Please sign in to comment.