Skip to content

Commit e5abb87

Browse files
committed
fix: more flexible user matching
1 parent ae424c1 commit e5abb87

File tree

7 files changed

+303
-97
lines changed

7 files changed

+303
-97
lines changed

dist/index.js

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81717,23 +81717,61 @@ var SlackAppUrl;
8171781717
;// CONCATENATED MODULE: ./src/utils/slack/user-matchers.ts
8171881718

8171981719

81720+
/**
81721+
* Redacts sensitive information for safe logging
81722+
* Replaces characters with * but keeps first and last character
81723+
* For emails, preserves the domain part
81724+
*/
81725+
function redact(text) {
81726+
if (!text) {
81727+
return '';
81728+
}
81729+
// Handle email addresses specially
81730+
if (text.includes('@')) {
81731+
const [localPart, domainPart] = text.split('@');
81732+
if (localPart.length <= 2) {
81733+
return `${localPart}@${domainPart}`;
81734+
}
81735+
return `${localPart[0]}${'*'.repeat(localPart.length - 2)}${localPart[localPart.length - 1]}@${domainPart}`;
81736+
}
81737+
// Handle regular text
81738+
if (text.length <= 2) {
81739+
return text;
81740+
}
81741+
return `${text[0]}${'*'.repeat(text.length - 2)}${text[text.length - 1]}`;
81742+
}
8172081743
function customMappingMatcher(githubUsername, slackUsername) {
8172181744
return {
81722-
check: (user) => user.name?.toLowerCase() === slackUsername.toLowerCase() ||
81723-
user.profile?.display_name?.toLowerCase() === slackUsername.toLowerCase() ||
81724-
user.profile?.real_name?.toLowerCase() === slackUsername.toLowerCase(),
81745+
check: (user) => {
81746+
const name = user.name?.toLowerCase() ?? '';
81747+
const displayName = user.profile?.display_name?.toLowerCase() ?? '';
81748+
const realName = user.profile?.real_name?.toLowerCase() ?? '';
81749+
const slackNameLower = slackUsername.toLowerCase();
81750+
return (name.includes(slackNameLower) ||
81751+
slackNameLower.includes(name) ||
81752+
displayName.includes(slackNameLower) ||
81753+
slackNameLower.includes(displayName) ||
81754+
realName.includes(slackNameLower) ||
81755+
slackNameLower.includes(realName));
81756+
},
8172581757
description: 'custom user mapping',
8172681758
log: (user) => {
8172781759
(0,core.debug)(`Match found by custom mapping: GitHub username [${githubUsername}] to Slack username [${slackUsername}] for user [${user.id}]`);
81760+
(0,core.debug)(`Redacted debug info: GitHub username [${redact(githubUsername)}] to Slack username [${redact(slackUsername)}] matched with user name [${redact(user.name ?? '')}], display_name [${redact(user.profile?.display_name ?? '')}], real_name [${redact(user.profile?.real_name ?? '')}]`);
8172881761
},
8172981762
};
8173081763
}
8173181764
function displayNameMatcher(username) {
8173281765
return {
81733-
check: (user) => user.profile?.display_name?.toLowerCase() === username.toLowerCase(),
81766+
check: (user) => {
81767+
const displayName = user.profile?.display_name?.toLowerCase() ?? '';
81768+
const usernameLower = username.toLowerCase();
81769+
return displayName.includes(usernameLower) || usernameLower.includes(displayName);
81770+
},
8173481771
description: 'user.profile.display_name fields',
8173581772
log: (user) => {
8173681773
(0,core.debug)(`Match found by username [${username}] matching Slack displayName [${user.profile?.display_name}]`);
81774+
(0,core.debug)(`Redacted debug info: username [${redact(username)}] matched with display_name [${redact(user.profile?.display_name ?? '')}]`);
8173781775
},
8173881776
};
8173981777
}
@@ -81745,6 +81783,7 @@ function emailContainsMatcher(username) {
8174581783
description: 'user.profile.email contains check',
8174681784
log: (user) => {
8174781785
(0,core.debug)(`Match found by username [${username}] contained in Slack email [${user.profile?.email}]`);
81786+
(0,core.debug)(`Redacted debug info: username [${redact(username)}] matched with email [${redact(user.profile?.email ?? '')}]`);
8174881787
},
8174981788
};
8175081789
}
@@ -81754,15 +81793,21 @@ function emailMatcher(email) {
8175481793
description: 'user.profile.email fields',
8175581794
log: (user) => {
8175681795
(0,core.debug)(`Match found by email [${email}] with Slack email [${user.profile?.email}]`);
81796+
(0,core.debug)(`Redacted debug info: email [${redact(email)}] matched with Slack email [${redact(user.profile?.email ?? '')}]`);
8175781797
},
8175881798
};
8175981799
}
8176081800
function realNameMatcher(username) {
8176181801
return {
81762-
check: (user) => user.profile?.real_name?.toLowerCase() === username.toLowerCase(),
81802+
check: (user) => {
81803+
const realName = user.profile?.real_name?.toLowerCase() ?? '';
81804+
const usernameLower = username.toLowerCase();
81805+
return realName.includes(usernameLower) || usernameLower.includes(realName);
81806+
},
8176381807
description: 'user.profile.real_name fields',
8176481808
log: (user) => {
8176581809
(0,core.debug)(`Match found by username [${username}] matching Slack realName [${user.profile?.real_name}]`);
81810+
(0,core.debug)(`Redacted debug info: username [${redact(username)}] matched with real_name [${redact(user.profile?.real_name ?? '')}]`);
8176681811
},
8176781812
};
8176881813
}
@@ -81772,6 +81817,7 @@ function userIdMatcher(userId) {
8177281817
description: 'user.id fields',
8177381818
log: (user) => {
8177481819
(0,core.debug)(`Match found by userId [${userId}] with Slack userId [${user.id}]`);
81820+
(0,core.debug)(`Redacted debug info: userId matched with Slack userId [${redact(user.id ?? '')}]`);
8177581821
},
8177681822
};
8177781823
}
@@ -81782,6 +81828,7 @@ const createUserMatchers = ({ email, userId, userMappings = [], username }) => {
8178281828
const matchingMappings = userMappings.filter((mapping) => mapping.githubUsername === username);
8178381829
if (matchingMappings.length > 0) {
8178481830
(0,core.debug)(`Found [${matchingMappings.length}] custom mappings for GitHub username [${username}]`);
81831+
(0,core.debug)(`Redacted debug info: Found [${matchingMappings.length}] custom mappings for GitHub username [${redact(username)}]`);
8178581832
// Add a matcher for each mapping
8178681833
matchingMappings.forEach((mapping) => {
8178781834
matchers.push(customMappingMatcher(username, mapping.slackUsername));
@@ -81804,25 +81851,35 @@ const createUserMatchers = ({ email, userId, userMappings = [], username }) => {
8180481851
};
8180581852
const logFailedMatches = ({ email, userId, userMappings = [], username }, usersCount) => {
8180681853
console.log(`No user match found for [${username}] after checking against [${usersCount}] Slack ${(0,src.plural)('user', usersCount)}`);
81854+
// Redacted version
81855+
console.log(`Redacted debug info: No user match found for [${redact(username ?? '')}] after checking against [${usersCount}] Slack ${(0,src.plural)('user', usersCount)}`);
8180781856
// Log mapping failures
8180881857
if (username && userMappings.length > 0) {
8180981858
const matchingMappings = userMappings.filter((mapping) => mapping.githubUsername === username);
8181081859
if (matchingMappings.length > 0) {
8181181860
(0,core.debug)(`WARNING: Custom mappings for GitHub username [${username}] were defined but no matching Slack users were found:`);
81861+
(0,core.debug)(`Redacted debug info: WARNING: Custom mappings for GitHub username [${redact(username)}] were defined but no matching Slack users were found:`);
8181281862
// Show each mapping that failed
8181381863
matchingMappings.forEach((mapping) => {
8181481864
(0,core.debug)(` - Mapped to Slack username [${mapping.slackUsername}] but no Slack user with this name/display_name/real_name was found`);
81865+
(0,core.debug)(` - Redacted debug info: Mapped to Slack username [${redact(mapping.slackUsername)}] but no Slack user with this name/display_name/real_name was found`);
8181581866
});
8181681867
(0,core.debug)(`Attempted to fall back to standard matching methods`);
8181781868
}
8181881869
}
8181981870
// Log standard matchers that were tried
81820-
if (userId)
81871+
if (userId) {
8182181872
(0,core.debug)(`Tried to match userId [${userId}] against Slack user.id fields`);
81822-
if (email)
81873+
(0,core.debug)(`Redacted debug info: Tried to match userId [${redact(userId)}] against Slack user.id fields`);
81874+
}
81875+
if (email) {
8182381876
(0,core.debug)(`Tried to match email [${email}] against Slack user.profile.email fields`);
81824-
if (username)
81877+
(0,core.debug)(`Redacted debug info: Tried to match email [${redact(email)}] against Slack user.profile.email fields`);
81878+
}
81879+
if (username) {
8182581880
(0,core.debug)(`Tried to match username [${username}] against Slack user.profile.email (contains), display_name and real_name fields`);
81881+
(0,core.debug)(`Redacted debug info: Tried to match username [${redact(username)}] against Slack user.profile.email (contains), display_name and real_name fields`);
81882+
}
8182681883
(0,core.debug)(`Since no Slack user match found, unable to @mention user or use their profile image`);
8182781884
};
8182881885

@@ -90631,7 +90688,7 @@ module.exports = {"version":"3.17.0"};
9063190688
/***/ 8330:
9063290689
/***/ ((module) => {
9063390690

90634-
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.3.2","TB":"https://buymeacoffee.com/coltenkrauter"}');
90691+
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.3.3","TB":"https://buymeacoffee.com/coltenkrauter"}');
9063590692

9063690693
/***/ })
9063790694

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@krauters/github-notifier",
33
"description": "GitHub Notifier by Krauters – Post Open Pull Requests to Slack",
4-
"version": "1.3.2",
4+
"version": "1.3.3",
55
"author": "Colten Krauter <coltenkrauter>",
66
"type": "module",
77
"homepage": "https://buymeacoffee.com/coltenkrauter",

src/utils/slack/user-matchers.ts

Lines changed: 108 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,84 @@ export interface UserMatcher {
1717
log: (user: Member) => void
1818
}
1919

20+
/**
21+
* Redacts sensitive information for safe logging
22+
* Replaces characters with * but keeps first and last character
23+
* For emails, obfuscates both username and domain parts
24+
*/
25+
export function redact(text: string): string {
26+
if (!text) {
27+
return ''
28+
}
29+
30+
// Handle email addresses specially
31+
if (text.includes('@')) {
32+
const [localPart, domainPart] = text.split('@')
33+
const redactedLocal = redact(localPart)
34+
35+
// Obfuscate domain part too
36+
const domainParts = domainPart.split('.')
37+
const redactedDomain = domainParts.map(part => {
38+
if (part.length <= 2) {
39+
return part
40+
}
41+
return `${part[0]}${'*'.repeat(part.length - 2)}${part[part.length - 1]}`
42+
}).join('.')
43+
44+
return `${redactedLocal}@${redactedDomain}`
45+
}
46+
47+
// Handle regular text
48+
if (text.length <= 2) {
49+
return text
50+
}
51+
52+
return `${text[0]}${'*'.repeat(text.length - 2)}${text[text.length - 1]}`
53+
}
54+
2055
function customMappingMatcher(githubUsername: string, slackUsername: string): UserMatcher {
2156
return {
22-
check: (user: Member) =>
23-
user.name?.toLowerCase() === slackUsername.toLowerCase() ||
24-
user.profile?.display_name?.toLowerCase() === slackUsername.toLowerCase() ||
25-
user.profile?.real_name?.toLowerCase() === slackUsername.toLowerCase(),
57+
check: (user: Member) => {
58+
const name = user.name?.toLowerCase() ?? ''
59+
const displayName = user.profile?.display_name?.toLowerCase() ?? ''
60+
const realName = user.profile?.real_name?.toLowerCase() ?? ''
61+
const slackNameLower = slackUsername.toLowerCase()
62+
63+
return (
64+
name.includes(slackNameLower) ||
65+
slackNameLower.includes(name) ||
66+
displayName.includes(slackNameLower) ||
67+
slackNameLower.includes(displayName) ||
68+
realName.includes(slackNameLower) ||
69+
slackNameLower.includes(realName)
70+
)
71+
},
2672
description: 'custom user mapping',
2773
log: (user: Member) => {
2874
debug(
2975
`Match found by custom mapping: GitHub username [${githubUsername}] to Slack username [${slackUsername}] for user [${user.id}]`,
3076
)
77+
debug(
78+
`Redacted debug info: GitHub username [${redact(githubUsername)}] to Slack username [${redact(slackUsername)}] matched with user name [${redact(user.name ?? '')}], display_name [${redact(user.profile?.display_name ?? '')}], real_name [${redact(user.profile?.real_name ?? '')}]`,
79+
)
3180
},
3281
}
3382
}
3483

3584
function displayNameMatcher(username: string): UserMatcher {
3685
return {
37-
check: (user: Member) => user.profile?.display_name?.toLowerCase() === username.toLowerCase(),
86+
check: (user: Member) => {
87+
const displayName = user.profile?.display_name?.toLowerCase() ?? ''
88+
const usernameLower = username.toLowerCase()
89+
90+
return displayName.includes(usernameLower) || usernameLower.includes(displayName)
91+
},
3892
description: 'user.profile.display_name fields',
3993
log: (user: Member) => {
4094
debug(`Match found by username [${username}] matching Slack displayName [${user.profile?.display_name}]`)
95+
debug(
96+
`Redacted debug info: username [${redact(username)}] matched with display_name [${redact(user.profile?.display_name ?? '')}]`,
97+
)
4198
},
4299
}
43100
}
@@ -51,6 +108,9 @@ function emailContainsMatcher(username: string): UserMatcher {
51108
description: 'user.profile.email contains check',
52109
log: (user: Member) => {
53110
debug(`Match found by username [${username}] contained in Slack email [${user.profile?.email}]`)
111+
debug(
112+
`Redacted debug info: username [${redact(username)}] matched with email [${redact(user.profile?.email ?? '')}]`,
113+
)
54114
},
55115
}
56116
}
@@ -61,16 +121,27 @@ function emailMatcher(email: string): UserMatcher {
61121
description: 'user.profile.email fields',
62122
log: (user: Member) => {
63123
debug(`Match found by email [${email}] with Slack email [${user.profile?.email}]`)
124+
debug(
125+
`Redacted debug info: email [${redact(email)}] matched with Slack email [${redact(user.profile?.email ?? '')}]`,
126+
)
64127
},
65128
}
66129
}
67130

68131
function realNameMatcher(username: string): UserMatcher {
69132
return {
70-
check: (user: Member) => user.profile?.real_name?.toLowerCase() === username.toLowerCase(),
133+
check: (user: Member) => {
134+
const realName = user.profile?.real_name?.toLowerCase() ?? ''
135+
const usernameLower = username.toLowerCase()
136+
137+
return realName.includes(usernameLower) || usernameLower.includes(realName)
138+
},
71139
description: 'user.profile.real_name fields',
72140
log: (user: Member) => {
73141
debug(`Match found by username [${username}] matching Slack realName [${user.profile?.real_name}]`)
142+
debug(
143+
`Redacted debug info: username [${redact(username)}] matched with real_name [${redact(user.profile?.real_name ?? '')}]`,
144+
)
74145
},
75146
}
76147
}
@@ -81,6 +152,7 @@ function userIdMatcher(userId: string): UserMatcher {
81152
description: 'user.id fields',
82153
log: (user: Member) => {
83154
debug(`Match found by userId [${userId}] with Slack userId [${user.id}]`)
155+
debug(`Redacted debug info: userId matched with Slack userId [${redact(user.id ?? '')}]`)
84156
},
85157
}
86158
}
@@ -94,6 +166,9 @@ export const createUserMatchers = ({ email, userId, userMappings = [], username
94166

95167
if (matchingMappings.length > 0) {
96168
debug(`Found [${matchingMappings.length}] custom mappings for GitHub username [${username}]`)
169+
debug(
170+
`Redacted debug info: Found [${matchingMappings.length}] custom mappings for GitHub username [${redact(username)}]`,
171+
)
97172

98173
// Add a matcher for each mapping
99174
matchingMappings.forEach((mapping) => {
@@ -128,6 +203,11 @@ export const logFailedMatches = (
128203
`No user match found for [${username}] after checking against [${usersCount}] Slack ${plural('user', usersCount)}`,
129204
)
130205

206+
// Redacted version
207+
console.log(
208+
`Redacted debug info: No user match found for [${redact(username ?? '')}] after checking against [${usersCount}] Slack ${plural('user', usersCount)}`,
209+
)
210+
131211
// Log mapping failures
132212
if (username && userMappings.length > 0) {
133213
const matchingMappings = userMappings.filter((mapping) => mapping.githubUsername === username)
@@ -136,24 +216,43 @@ export const logFailedMatches = (
136216
`WARNING: Custom mappings for GitHub username [${username}] were defined but no matching Slack users were found:`,
137217
)
138218

219+
debug(
220+
`Redacted debug info: WARNING: Custom mappings for GitHub username [${redact(username)}] were defined but no matching Slack users were found:`,
221+
)
222+
139223
// Show each mapping that failed
140224
matchingMappings.forEach((mapping) => {
141225
debug(
142226
` - Mapped to Slack username [${mapping.slackUsername}] but no Slack user with this name/display_name/real_name was found`,
143227
)
228+
debug(
229+
` - Redacted debug info: Mapped to Slack username [${redact(mapping.slackUsername)}] but no Slack user with this name/display_name/real_name was found`,
230+
)
144231
})
145232

146233
debug(`Attempted to fall back to standard matching methods`)
147234
}
148235
}
149236

150237
// Log standard matchers that were tried
151-
if (userId) debug(`Tried to match userId [${userId}] against Slack user.id fields`)
152-
if (email) debug(`Tried to match email [${email}] against Slack user.profile.email fields`)
153-
if (username)
238+
if (userId) {
239+
debug(`Tried to match userId [${userId}] against Slack user.id fields`)
240+
debug(`Redacted debug info: Tried to match userId [${redact(userId)}] against Slack user.id fields`)
241+
}
242+
243+
if (email) {
244+
debug(`Tried to match email [${email}] against Slack user.profile.email fields`)
245+
debug(`Redacted debug info: Tried to match email [${redact(email)}] against Slack user.profile.email fields`)
246+
}
247+
248+
if (username) {
154249
debug(
155250
`Tried to match username [${username}] against Slack user.profile.email (contains), display_name and real_name fields`,
156251
)
252+
debug(
253+
`Redacted debug info: Tried to match username [${redact(username)}] against Slack user.profile.email (contains), display_name and real_name fields`,
254+
)
255+
}
157256

158257
debug(`Since no Slack user match found, unable to @mention user or use their profile image`)
159258
}

0 commit comments

Comments
 (0)