Skip to content

Commit 618a7b6

Browse files
committed
feat(sc-30416): add support for user mapping file to resolve Slack user by GitHub login
- Introduce `user_mapping_filepath` input in `action.yml` to optionally provide a mapping file for Slack user details by GitHub login. - Update `getMessageAuthorFactory` and related logic to use the mapping file if provided, avoiding Slack and GitHub API calls when possible. - Add fallback and error handling for mapping file usage. - Refactor main entry to pass `user_mapping_filepath` to author resolution. Signed-off-by: Jake Schurch <[email protected]>
1 parent ebd4585 commit 618a7b6

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/getMessageAuthorFactory.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@ export type GetMessageAuthor = (
1313
options?: GetMessageAuthorOptions
1414
) => Promise<MessageAuthor | null>
1515

16-
interface GetMessageAuthorOptions {
16+
interface GetMessageAuthorOptions extends GetMessageAuthorFactoryOptions {
1717
/** `false` falls back to GitHub username, skipping a conservatively rate-limited Slack API call */
18-
withSlackUserId: boolean
19-
userMappingFilepath: string
18+
withSlackUserId?: boolean
19+
}
20+
21+
interface GetMessageAuthorFactoryOptions {
22+
userMappingFilepath?: string
2023
}
2124

2225
export function getMessageAuthorFactory(
2326
octokit: OctokitClient,
2427
slack: SlackClient,
25-
options: GetMessageAuthorOptions = {
26-
withSlackUserId: false,
27-
userMappingFilepath: ''
28+
options: GetMessageAuthorFactoryOptions = {
29+
userMappingFilepath: undefined
2830
}
2931
): GetMessageAuthor {
3032
return async (
31-
messageAuthorOptions: GetMessageAuthorOptions = options
33+
{withSlackUserId}: GetMessageAuthorOptions = {withSlackUserId: false}
3234
): Promise<MessageAuthor | null> => {
33-
return getMessageAuthor(octokit, slack, messageAuthorOptions)
35+
return getMessageAuthor(octokit, slack, {withSlackUserId, ...options})
3436
}
3537
}
3638

src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ async function notifySlack(
5858
octokit: OctokitClient,
5959
slack: SlackClient
6060
): Promise<void> {
61-
const getMessageAuthor = getMessageAuthorFactory(octokit, slack, {userMappingFilepath: getInput(user_mapping_filepath)})
61+
const getMessageAuthor = getMessageAuthorFactory(octokit, slack, {
62+
userMappingFilepath: getInput('user_mapping_filepath')
63+
})
6264
const ts = await postMessage({octokit, slack, getMessageAuthor})
6365

6466
if (ts) {

0 commit comments

Comments
 (0)