Skip to content

Commit c9d6d35

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

File tree

7 files changed

+421
-97
lines changed

7 files changed

+421
-97
lines changed

dist/index.js

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81717,23 +81717,69 @@ 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, obfuscates both username and domain parts
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+
const redactedLocal = redact(localPart);
81733+
// Obfuscate domain part too
81734+
const domainParts = domainPart.split('.');
81735+
const redactedDomain = domainParts
81736+
.map((part) => {
81737+
if (part.length <= 2) {
81738+
return part;
81739+
}
81740+
return `${part[0]}${'*'.repeat(part.length - 2)}${part[part.length - 1]}`;
81741+
})
81742+
.join('.');
81743+
return `${redactedLocal}@${redactedDomain}`;
81744+
}
81745+
// Handle regular text
81746+
if (text.length <= 2) {
81747+
return text;
81748+
}
81749+
return `${text[0]}${'*'.repeat(text.length - 2)}${text[text.length - 1]}`;
81750+
}
8172081751
function customMappingMatcher(githubUsername, slackUsername) {
8172181752
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(),
81753+
check: (user) => {
81754+
const name = user.name?.toLowerCase() ?? '';
81755+
const displayName = user.profile?.display_name?.toLowerCase() ?? '';
81756+
const realName = user.profile?.real_name?.toLowerCase() ?? '';
81757+
const slackNameLower = slackUsername.toLowerCase();
81758+
return (name.includes(slackNameLower) ||
81759+
slackNameLower.includes(name) ||
81760+
displayName.includes(slackNameLower) ||
81761+
slackNameLower.includes(displayName) ||
81762+
realName.includes(slackNameLower) ||
81763+
slackNameLower.includes(realName));
81764+
},
8172581765
description: 'custom user mapping',
8172681766
log: (user) => {
8172781767
(0,core.debug)(`Match found by custom mapping: GitHub username [${githubUsername}] to Slack username [${slackUsername}] for user [${user.id}]`);
81768+
(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 ?? '')}]`);
8172881769
},
8172981770
};
8173081771
}
8173181772
function displayNameMatcher(username) {
8173281773
return {
81733-
check: (user) => user.profile?.display_name?.toLowerCase() === username.toLowerCase(),
81774+
check: (user) => {
81775+
const displayName = user.profile?.display_name?.toLowerCase() ?? '';
81776+
const usernameLower = username.toLowerCase();
81777+
return displayName.includes(usernameLower) || usernameLower.includes(displayName);
81778+
},
8173481779
description: 'user.profile.display_name fields',
8173581780
log: (user) => {
8173681781
(0,core.debug)(`Match found by username [${username}] matching Slack displayName [${user.profile?.display_name}]`);
81782+
(0,core.debug)(`Redacted debug info: username [${redact(username)}] matched with display_name [${redact(user.profile?.display_name ?? '')}]`);
8173781783
},
8173881784
};
8173981785
}
@@ -81745,6 +81791,7 @@ function emailContainsMatcher(username) {
8174581791
description: 'user.profile.email contains check',
8174681792
log: (user) => {
8174781793
(0,core.debug)(`Match found by username [${username}] contained in Slack email [${user.profile?.email}]`);
81794+
(0,core.debug)(`Redacted debug info: username [${redact(username)}] matched with email [${redact(user.profile?.email ?? '')}]`);
8174881795
},
8174981796
};
8175081797
}
@@ -81754,15 +81801,21 @@ function emailMatcher(email) {
8175481801
description: 'user.profile.email fields',
8175581802
log: (user) => {
8175681803
(0,core.debug)(`Match found by email [${email}] with Slack email [${user.profile?.email}]`);
81804+
(0,core.debug)(`Redacted debug info: email [${redact(email)}] matched with Slack email [${redact(user.profile?.email ?? '')}]`);
8175781805
},
8175881806
};
8175981807
}
8176081808
function realNameMatcher(username) {
8176181809
return {
81762-
check: (user) => user.profile?.real_name?.toLowerCase() === username.toLowerCase(),
81810+
check: (user) => {
81811+
const realName = user.profile?.real_name?.toLowerCase() ?? '';
81812+
const usernameLower = username.toLowerCase();
81813+
return realName.includes(usernameLower) || usernameLower.includes(realName);
81814+
},
8176381815
description: 'user.profile.real_name fields',
8176481816
log: (user) => {
8176581817
(0,core.debug)(`Match found by username [${username}] matching Slack realName [${user.profile?.real_name}]`);
81818+
(0,core.debug)(`Redacted debug info: username [${redact(username)}] matched with real_name [${redact(user.profile?.real_name ?? '')}]`);
8176681819
},
8176781820
};
8176881821
}
@@ -81772,6 +81825,7 @@ function userIdMatcher(userId) {
8177281825
description: 'user.id fields',
8177381826
log: (user) => {
8177481827
(0,core.debug)(`Match found by userId [${userId}] with Slack userId [${user.id}]`);
81828+
(0,core.debug)(`Redacted debug info: userId matched with Slack userId [${redact(user.id ?? '')}]`);
8177581829
},
8177681830
};
8177781831
}
@@ -81782,6 +81836,7 @@ const createUserMatchers = ({ email, userId, userMappings = [], username }) => {
8178281836
const matchingMappings = userMappings.filter((mapping) => mapping.githubUsername === username);
8178381837
if (matchingMappings.length > 0) {
8178481838
(0,core.debug)(`Found [${matchingMappings.length}] custom mappings for GitHub username [${username}]`);
81839+
(0,core.debug)(`Redacted debug info: Found [${matchingMappings.length}] custom mappings for GitHub username [${redact(username)}]`);
8178581840
// Add a matcher for each mapping
8178681841
matchingMappings.forEach((mapping) => {
8178781842
matchers.push(customMappingMatcher(username, mapping.slackUsername));
@@ -81804,25 +81859,35 @@ const createUserMatchers = ({ email, userId, userMappings = [], username }) => {
8180481859
};
8180581860
const logFailedMatches = ({ email, userId, userMappings = [], username }, usersCount) => {
8180681861
console.log(`No user match found for [${username}] after checking against [${usersCount}] Slack ${(0,src.plural)('user', usersCount)}`);
81862+
// Redacted version
81863+
console.log(`Redacted debug info: No user match found for [${redact(username ?? '')}] after checking against [${usersCount}] Slack ${(0,src.plural)('user', usersCount)}`);
8180781864
// Log mapping failures
8180881865
if (username && userMappings.length > 0) {
8180981866
const matchingMappings = userMappings.filter((mapping) => mapping.githubUsername === username);
8181081867
if (matchingMappings.length > 0) {
8181181868
(0,core.debug)(`WARNING: Custom mappings for GitHub username [${username}] were defined but no matching Slack users were found:`);
81869+
(0,core.debug)(`Redacted debug info: WARNING: Custom mappings for GitHub username [${redact(username)}] were defined but no matching Slack users were found:`);
8181281870
// Show each mapping that failed
8181381871
matchingMappings.forEach((mapping) => {
8181481872
(0,core.debug)(` - Mapped to Slack username [${mapping.slackUsername}] but no Slack user with this name/display_name/real_name was found`);
81873+
(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`);
8181581874
});
8181681875
(0,core.debug)(`Attempted to fall back to standard matching methods`);
8181781876
}
8181881877
}
8181981878
// Log standard matchers that were tried
81820-
if (userId)
81879+
if (userId) {
8182181880
(0,core.debug)(`Tried to match userId [${userId}] against Slack user.id fields`);
81822-
if (email)
81881+
(0,core.debug)(`Redacted debug info: Tried to match userId [${redact(userId)}] against Slack user.id fields`);
81882+
}
81883+
if (email) {
8182381884
(0,core.debug)(`Tried to match email [${email}] against Slack user.profile.email fields`);
81824-
if (username)
81885+
(0,core.debug)(`Redacted debug info: Tried to match email [${redact(email)}] against Slack user.profile.email fields`);
81886+
}
81887+
if (username) {
8182581888
(0,core.debug)(`Tried to match username [${username}] against Slack user.profile.email (contains), display_name and real_name fields`);
81889+
(0,core.debug)(`Redacted debug info: Tried to match username [${redact(username)}] against Slack user.profile.email (contains), display_name and real_name fields`);
81890+
}
8182681891
(0,core.debug)(`Since no Slack user match found, unable to @mention user or use their profile image`);
8182781892
};
8182881893

@@ -90631,7 +90696,7 @@ module.exports = {"version":"3.17.0"};
9063190696
/***/ 8330:
9063290697
/***/ ((module) => {
9063390698

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

9063690701
/***/ })
9063790702

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",

0 commit comments

Comments
 (0)