Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(slack): Do not override existing picture #55

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading