@@ -80746,10 +80746,10 @@ __nccwpck_require__.a(module, async (__webpack_handle_async_dependencies__, __we
8074680746/* harmony import */ var _krauters_utils__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__nccwpck_require__.n(_krauters_utils__WEBPACK_IMPORTED_MODULE_2__);
8074780747/* harmony import */ var _package_json__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(8330);
8074880748/* harmony import */ var _constants_js__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(27242);
80749- /* harmony import */ var _utils_github_github_client_js__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(32031 );
80749+ /* harmony import */ var _utils_github_client_js__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(10598 );
8075080750/* harmony import */ var _utils_github_structures_js__WEBPACK_IMPORTED_MODULE_6__ = __nccwpck_require__(28315);
8075180751/* harmony import */ var _utils_slack_blocks_js__WEBPACK_IMPORTED_MODULE_7__ = __nccwpck_require__(96114);
80752- /* harmony import */ var _utils_slack_slack_client_js__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(70741 );
80752+ /* harmony import */ var _utils_slack_client_js__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(90294 );
8075380753/* harmony import */ var _utils_test_data_js__WEBPACK_IMPORTED_MODULE_9__ = __nccwpck_require__(23930);
8075480754/* harmony import */ var _input_parser_js__WEBPACK_IMPORTED_MODULE_10__ = __nccwpck_require__(40935);
8075580755// https://github.com/actions/github-script
@@ -80772,12 +80772,12 @@ async function main() {
8077280772 try {
8077380773 (0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.debug)('Starting main...');
8077480774 const { githubConfig, repositoryFilter, slackConfig, withArchived, withDrafts, withPublic, withTestData, withUserMentions, } = (0,_input_parser_js__WEBPACK_IMPORTED_MODULE_10__/* .parseInputs */ .T)();
80775- const slack = new _utils_slack_slack_client_js__WEBPACK_IMPORTED_MODULE_8__ /* .SlackClient */ .Q(slackConfig);
80775+ const slack = new _utils_slack_client_js__WEBPACK_IMPORTED_MODULE_8__ /* .SlackClient */ .Q(slackConfig);
8077680776 const results = await githubConfig.tokens.reduce(async (accPromise, token) => {
8077780777 const acc = await accPromise;
8077880778 try {
8077980779 // TODO - Consider making this thread safe so requests can be made in parallel
80780- const client = new _utils_github_github_client_js__WEBPACK_IMPORTED_MODULE_5__ /* .GitHubClient */ .j({
80780+ const client = new _utils_github_client_js__WEBPACK_IMPORTED_MODULE_5__ /* .GitHubClient */ .j({
8078180781 options: githubConfig.options,
8078280782 token,
8078380783 });
@@ -80933,7 +80933,7 @@ function parseInputs() {
8093380933
8093480934/***/ }),
8093580935
80936- /***/ 32031 :
80936+ /***/ 10598 :
8093780937/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {
8093880938
8093980939/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
@@ -81376,7 +81376,7 @@ var PullState;
8137681376/**
8137781377 * Get an emoji based on the age of something.
8137881378 *
81379- * @param {number} hoursAgo - The number of hours ago since something happened.
81379+ * @param {number} hoursAgo The number of hours ago since something happened.
8138081380 * @returns {string}
8138181381 */
8138281382function getAgeBasedEmoji(hoursAgo) {
@@ -81391,8 +81391,8 @@ function getAgeBasedEmoji(hoursAgo) {
8139181391/**
8139281392 * Get the relative human readable age of something.
8139381393 *
81394- * @param {number} hoursAgo - The number of hours ago since something happened.
81395- * @param {boolean} [withAgo=true] - Whether to include the ' ago' suffix when appropriate.
81394+ * @param {number} hoursAgo The number of hours ago since something happened.
81395+ * @param {boolean} [withAgo=true] Whether to include the ' ago' suffix when appropriate.
8139681396 * @returns {string}
8139781397 */
8139881398function getRelativeHumanReadableAge(hoursAgo, withAgo = true) {
@@ -81409,7 +81409,7 @@ function getRelativeHumanReadableAge(hoursAgo, withAgo = true) {
8140981409}
8141081410/**
8141181411 * Get have or has depending on quantity context.
81412- * @param {number} number - The number of entities in question.
81412+ * @param {number} number The number of entities in question.
8141381413 * @returns {string}
8141481414 */
8141581415function haveOrHas(number) {
@@ -81584,13 +81584,17 @@ async function getPullBlocks(pull, slack, withUserMentions) {
8158481584 const activityBlocks = [];
8158581585 for (const review of Object.values(reviews ?? [])) {
8158681586 const { context, email, login: username, relativeHumanReadableAge } = review;
81587- const slackUser = await slack.getSlackUser ({
81587+ const slackUser = await slack.getUser ({
8158881588 email,
8158981589 username,
8159081590 });
81591- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
8159281591 const displayName = slackUser?.profile?.display_name || slackUser?.profile?.real_name_normalized || username;
81593- const imageUrl = slackUser?.profile?.image_72;
81592+ const imageUrl = slackUser?.profile?.image_512 ||
81593+ slackUser?.profile?.image_192 ||
81594+ slackUser?.profile?.image_72 ||
81595+ slackUser?.profile?.image_48 ||
81596+ slackUser?.profile?.image_32 ||
81597+ slackUser?.profile?.image_24;
8159481598 activityBlocks.push({
8159581599 elements: [
8159681600 {
@@ -81613,8 +81617,7 @@ async function getPullBlocks(pull, slack, withUserMentions) {
8161381617 if (requestedReviewers.length) {
8161481618 const slackUserIdsOrLogins = [];
8161581619 for (const username of requestedReviewers) {
81616- const slackUser = await slack.getSlackUser({ username });
81617- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
81620+ const slackUser = await slack.getUser({ username });
8161881621 slackUserIdsOrLogins.push((withUserMentions && slackUser?.id && `<@${slackUser.id}>`) || username);
8161981622 }
8162081623 activityBlocks.unshift(...getContextMarkdownBlock((0,_krauters_utils__WEBPACK_IMPORTED_MODULE_0__.formatStringList)(slackUserIdsOrLogins) +
@@ -81660,7 +81663,7 @@ async function getPullBlocks(pull, slack, withUserMentions) {
8166081663
8166181664/***/ }),
8166281665
81663- /***/ 70741 :
81666+ /***/ 90294 :
8166481667/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {
8166581668
8166681669
@@ -81680,7 +81683,7 @@ var SlackAppUrl;
8168081683 SlackAppUrl["SuffixDisplayInfo"] = "general#display_info_form";
8168181684})(SlackAppUrl || (SlackAppUrl = {}));
8168281685
81683- ;// CONCATENATED MODULE: ./src/utils/slack/slack- client.ts
81686+ ;// CONCATENATED MODULE: ./src/utils/slack/client.ts
8168481687
8168581688
8168681689
@@ -81759,27 +81762,47 @@ class SlackClient {
8175981762 * @param username An email address that hopefully as matched to a Slack user account.
8176081763 * @param [botId] The botId for the bot to find.
8176181764 */
81762- async getSlackUser ({ email, userId, username }) {
81765+ async getUser ({ email, userId, username }) {
8176381766 console.log(`Getting Slack UserId for email [${email}], username [${username}], and userId [${userId}]...`);
8176481767 const users = this.users ?? (await this.getAllusers());
81768+ // Define matching functions for better readability and extensibility
81769+ const matchById = (user) => userId && user.id === userId;
81770+ const matchByEmail = (user) => email && user.profile?.email === email;
81771+ const matchByEmailContainsUsername = (user) => username && String(user.profile?.email ?? '').includes(username);
81772+ const matchByDisplayName = (user) => username && user.profile?.display_name === username;
81773+ const matchByRealName = (user) => username && user.profile?.real_name === username;
8176581774 const user = users.find((user) => {
81766- if (userId) {
81767- return user?.id === userId;
81768- }
81769- const profile = user.profile;
81770- return (
81775+ const idMatch = matchById(user);
81776+ const emailMatch = matchByEmail(user);
81777+ const emailContainsUsernameMatch = matchByEmailContainsUsername(user);
81778+ const displayNameMatch = matchByDisplayName(user);
81779+ const realNameMatch = matchByRealName(user);
81780+ // Log the first match attempt that succeeds for debugging
81781+ if (idMatch && userId)
81782+ console.log(`Match found by userId [${userId}] with Slack userId [${user.id}]`);
81783+ else if (emailMatch && email)
81784+ console.log(`Match found by email [${email}] with Slack email [${user.profile?.email}]`);
81785+ else if (emailContainsUsernameMatch && username)
81786+ console.log(`Match found by username [${username}] contained in Slack email [${user.profile?.email}]`);
81787+ else if (displayNameMatch && username)
81788+ console.log(`Match found by username [${username}] matching Slack display_name [${user.profile?.display_name}]`);
81789+ else if (realNameMatch && username)
81790+ console.log(`Match found by username [${username}] matching Slack real_name [${user.profile?.real_name}]`);
8177181791 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
81772- (email && profile?.email === email) ||
81773- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
81774- String(profile?.email).includes(username) ||
81775- profile?.display_name === username ||
81776- profile?.real_name === username);
81792+ return idMatch || emailMatch || emailContainsUsernameMatch || displayNameMatch || realNameMatch;
8177781793 });
8177881794 if (user) {
8177981795 console.log(`User found with userId [${user.id}]`);
8178081796 return user;
8178181797 }
81782- console.log('User not found, returning undefined');
81798+ console.log(`No user match found after checking against [${users.length}] users`);
81799+ if (userId)
81800+ console.log(`Tried to match userId [${userId}] against Slack user.id fields`);
81801+ if (email)
81802+ console.log(`Tried to match email [${email}] against Slack user.profile.email fields`);
81803+ if (username)
81804+ console.log(`Tried to match username [${username}] against Slack user.profile.email (contains), display_name and real_name fields`);
81805+ console.log(`Since no Slack user match found, unable to @mention user or use their profile image`);
8178381806 }
8178481807 /**
8178581808 * Post a message with blocks to Slack channels.
@@ -90365,7 +90388,7 @@ module.exports = {"version":"3.17.0"};
9036590388/***/ 8330:
9036690389/***/ ((module) => {
9036790390
90368- module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.1 .0","TB":"https://buymeacoffee.com/coltenkrauter"}');
90391+ module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.2 .0","TB":"https://buymeacoffee.com/coltenkrauter"}');
9036990392
9037090393/***/ })
9037190394
0 commit comments