Skip to content

Commit fdb43a8

Browse files
committed
feat: image_72 fallbacks
1 parent f674407 commit fdb43a8

File tree

14 files changed

+172
-57
lines changed

14 files changed

+172
-57
lines changed

dist/index.js

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
8138281382
function 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
*/
8139881398
function 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
*/
8141581415
function haveOrHas(number) {
@@ -81588,9 +81588,13 @@ async function getPullBlocks(pull, slack, withUserMentions) {
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
{
@@ -81614,7 +81618,6 @@ async function getPullBlocks(pull, slack, withUserMentions) {
8161481618
const slackUserIdsOrLogins = [];
8161581619
for (const username of requestedReviewers) {
8161681620
const slackUser = await slack.getSlackUser({ username });
81617-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
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

@@ -81762,24 +81765,36 @@ class SlackClient {
8176281765
async getSlackUser({ 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;
8177081775
return (
8177181776
// 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);
81777+
matchById(user) ||
81778+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
81779+
matchByEmail(user) ||
81780+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
81781+
matchByEmailContainsUsername(user) ||
81782+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
81783+
matchByDisplayName(user) ||
81784+
matchByRealName(user));
8177781785
});
8177881786
if (user) {
8177981787
console.log(`User found with userId [${user.id}]`);
8178081788
return user;
8178181789
}
81782-
console.log('User not found, returning undefined');
81790+
console.log(`No user match found after checking [${users.length}] users with criteria:`);
81791+
if (userId)
81792+
console.log(`- user id [${userId}]`);
81793+
if (email)
81794+
console.log(`- email [${email}]`);
81795+
if (username)
81796+
console.log(`- username [${username}] (checking display name, real name, and email)`);
81797+
return undefined;
8178381798
}
8178481799
/**
8178581800
* Post a message with blocks to Slack channels.
@@ -90365,7 +90380,7 @@ module.exports = {"version":"3.17.0"};
9036590380
/***/ 8330:
9036690381
/***/ ((module) => {
9036790382

90368-
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.1.0","TB":"https://buymeacoffee.com/coltenkrauter"}');
90383+
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.2.0","TB":"https://buymeacoffee.com/coltenkrauter"}');
9036990384

9037090385
/***/ })
9037190386

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.1.0",
4+
"version": "1.2.0",
55
"author": "Colten Krauter <coltenkrauter>",
66
"type": "module",
77
"homepage": "https://buymeacoffee.com/coltenkrauter",

src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import { formatStringList, plural } from '@krauters/utils'
88

99
import pkg from '../package.json' with { type: 'json' }
1010
import { workflowLogsUrl, workflowUrl } from './constants.js'
11-
import { GitHubClient } from './utils/github/github-client.js'
11+
import { GitHubClient } from './utils/github/client.js'
1212
import type { Pull } from './utils/github/structures.js'
1313
import { PullState, RepositoryType } from './utils/github/structures.js'
1414
import { getFirstBlocks, getLastBlocks, getPullBlocks } from './utils/slack/blocks.js'
15-
import { SlackClient } from './utils/slack/slack-client.js'
15+
import { SlackClient } from './utils/slack/client.js'
1616
import { getApprovedPullRequest } from './utils/test-data.js'
1717
import { parseInputs as getInputs } from './input-parser.js'
1818

src/utils/misc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { plural } from '@krauters/utils'
33
/**
44
* Get an emoji based on the age of something.
55
*
6-
* @param {number} hoursAgo - The number of hours ago since something happened.
6+
* @param {number} hoursAgo The number of hours ago since something happened.
77
* @returns {string}
88
*/
99
export function getAgeBasedEmoji(hoursAgo: number): string {
@@ -22,8 +22,8 @@ export function getAgeBasedEmoji(hoursAgo: number): string {
2222
/**
2323
* Get the relative human readable age of something.
2424
*
25-
* @param {number} hoursAgo - The number of hours ago since something happened.
26-
* @param {boolean} [withAgo=true] - Whether to include the ' ago' suffix when appropriate.
25+
* @param {number} hoursAgo The number of hours ago since something happened.
26+
* @param {boolean} [withAgo=true] Whether to include the ' ago' suffix when appropriate.
2727
* @returns {string}
2828
*/
2929
export function getRelativeHumanReadableAge(hoursAgo: number, withAgo = true): string {
@@ -41,7 +41,7 @@ export function getRelativeHumanReadableAge(hoursAgo: number, withAgo = true): s
4141

4242
/**
4343
* Get have or has depending on quantity context.
44-
* @param {number} number - The number of entities in question.
44+
* @param {number} number The number of entities in question.
4545
* @returns {string}
4646
*/
4747
export function haveOrHas(number: number): string {

src/utils/slack/blocks.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
2+
/* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
23
import type { KnownBlock, PlainTextElement, RichTextElement } from '@slack/web-api'
34
import type { Button } from '@slack/types'
45

56
import { capitalize, formatStringList, plural } from '@krauters/utils'
67

78
import type { Pull } from '../github/structures.js'
8-
import type { SlackClient } from './slack-client.js'
9+
import type { SlackClient } from './client.js'
910

1011
import { prBaseUrl, scmUrl } from '../../constants.js'
1112
import { getAgeBasedEmoji, haveOrHas } from '../misc.js'
@@ -195,9 +196,14 @@ export async function getPullBlocks(pull: Pull, slack: SlackClient, withUserMent
195196
username,
196197
})
197198

198-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
199199
const displayName = slackUser?.profile?.display_name || slackUser?.profile?.real_name_normalized || username
200-
const imageUrl = slackUser?.profile?.image_72
200+
const imageUrl =
201+
slackUser?.profile?.image_512 ||
202+
slackUser?.profile?.image_192 ||
203+
slackUser?.profile?.image_72 ||
204+
slackUser?.profile?.image_48 ||
205+
slackUser?.profile?.image_32 ||
206+
slackUser?.profile?.image_24
201207

202208
activityBlocks.push({
203209
elements: [
@@ -223,7 +229,6 @@ export async function getPullBlocks(pull: Pull, slack: SlackClient, withUserMent
223229
const slackUserIdsOrLogins: string[] = []
224230
for (const username of requestedReviewers) {
225231
const slackUser = await slack.getSlackUser({ username })
226-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
227232
slackUserIdsOrLogins.push((withUserMentions && slackUser?.id && `<@${slackUser.id}>`) || username)
228233
}
229234
activityBlocks.unshift(
Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
22
import type { Block, BotsInfoResponse } from '@slack/web-api'
33
import type { Bot } from '@slack/web-api/dist/types/response/BotsInfoResponse.js'
4-
import type { Member, Profile } from '@slack/web-api/dist/types/response/UsersListResponse.js'
4+
import type { Member } from '@slack/web-api/dist/types/response/UsersListResponse.js'
55
import type { User } from '@slack/web-api/dist/types/response/UsersLookupByEmailResponse.js'
66

77
import { getBatches } from '@krauters/utils'
@@ -104,20 +104,26 @@ export class SlackClient {
104104
console.log(`Getting Slack UserId for email [${email}], username [${username}], and userId [${userId}]...`)
105105

106106
const users = this.users ?? (await this.getAllusers())
107-
const user = users.find((user: Member) => {
108-
if (userId) {
109-
return user?.id === userId
110-
}
111107

112-
const profile: Profile | undefined = user.profile
108+
// Define matching functions for better readability and extensibility
109+
const matchById = (user: Member) => userId && user.id === userId
110+
const matchByEmail = (user: Member) => email && user.profile?.email === email
111+
const matchByEmailContainsUsername = (user: Member) =>
112+
username && String(user.profile?.email ?? '').includes(username)
113+
const matchByDisplayName = (user: Member) => username && user.profile?.display_name === username
114+
const matchByRealName = (user: Member) => username && user.profile?.real_name === username
113115

116+
const user = users.find((user: Member) => {
114117
return (
115118
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
116-
(email && profile?.email === email) ||
117-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118-
String(profile?.email).includes(username!) ||
119-
profile?.display_name === username ||
120-
profile?.real_name === username
119+
matchById(user) ||
120+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
121+
matchByEmail(user) ||
122+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
123+
matchByEmailContainsUsername(user) ||
124+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
125+
matchByDisplayName(user) ||
126+
matchByRealName(user)
121127
)
122128
})
123129

@@ -127,7 +133,12 @@ export class SlackClient {
127133
return user
128134
}
129135

130-
console.log('User not found, returning undefined')
136+
console.log(`No user match found after checking [${users.length}] users with criteria:`)
137+
if (userId) console.log(`- user id [${userId}]`)
138+
if (email) console.log(`- email [${email}]`)
139+
if (username) console.log(`- username [${username}] (checking display name, real name, and email)`)
140+
141+
return undefined
131142
}
132143

133144
/**

src/utils/slack/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export * from './blocks.js'
2-
export * from './slack-client.js'
2+
export * from './client.js'

0 commit comments

Comments
 (0)