Skip to content

Commit 9cd388e

Browse files
committed
refactor: cleanup add @krauter packages
1 parent 7eb9417 commit 9cd388e

File tree

8 files changed

+6030
-3109
lines changed

8 files changed

+6030
-3109
lines changed

dist/index.js

Lines changed: 2453 additions & 1689 deletions
Large diffs are not rendered by default.

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.

dist/sourcemap-register.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

package-lock.json

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

package.json

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,28 @@
3434
},
3535
"license": "ISC",
3636
"dependencies": {
37-
"@actions/core": "1.10.1",
37+
"@actions/core": "1.11.1",
3838
"@actions/github": "6.0.0",
39+
"@krauters/environment": "^0.2.1",
40+
"@krauters/logger": "^0.3.2",
41+
"@krauters/structures": "^1.0.2",
42+
"@krauters/utils": "^1.0.0",
3943
"@octokit/rest": "21.0.2",
40-
"@octokit/types": "13.5.0",
41-
"@slack/web-api": "7.4.0",
42-
"simple-git": "^3.26.0"
44+
"@octokit/types": "13.6.1",
45+
"@slack/web-api": "7.7.0",
46+
"simple-git": "^3.27.0"
4347
},
4448
"devDependencies": {
45-
"@krauters/eslint-config": "^0.1.0",
46-
"@types/jest": "^29.5.12",
47-
"@types/node": "^22.5.4",
48-
"@vercel/ncc": "^0.38.1",
49-
"husky": "9.1.5",
49+
"@krauters/eslint-config": "^1.4.0",
50+
"@types/jest": "^29.5.14",
51+
"@types/node": "^22.9.0",
52+
"@vercel/ncc": "^0.38.2",
53+
"husky": "9.1.6",
5054
"jest": "^29.7.0",
5155
"make-coverage-badge": "^1.2.0",
5256
"ts-jest": "^29.2.5",
5357
"ts-node": "^10.9.2",
54-
"typescript": "^5.6.2",
55-
"typescript-eslint": "^8.5.0"
58+
"typescript": "^5.6.3",
59+
"typescript-eslint": "^8.13.0"
5660
}
5761
}

src/utils/github/github-client.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,17 @@ export class GitHubClient {
3737

3838
/**
3939
* A GitHub client for interacting with a GitHub API.
40-
* @param {GitHubClientProps} props - Properties toi configure GitHub client.
40+
*
41+
* @param props Properties toi configure GitHub client.
4142
*/
4243
constructor({ options = {}, token }: GitHubClientProps) {
4344
this.client = getOctokit(token, options)
4445
}
4546

4647
/**
4748
* Get commits in a pull.
48-
* @param {GetCommitsProps} props - Properties for which commit to get.
49-
* @returns {Promise<GitHubPullCommits>}
49+
*
50+
* @param props Properties for which commit to get.
5051
*/
5152
async getCommits({ number, repo }: GetCommitsProps): Promise<GitHubPullCommits> {
5253
return await this.client.paginate(this.client.rest.pulls.listCommits, {
@@ -58,8 +59,8 @@ export class GitHubClient {
5859

5960
/**
6061
* Get a GitHub user's email address from a username.
61-
* @param {string} username - A GitHub username.
62-
* @returns {Promise<string | undefined>}
62+
*
63+
* @param username A GitHub username.
6364
*/
6465
async getEmail(username: string): Promise<string | undefined> {
6566
console.log(`Getting email from GitHub for username [${username}]...`)
@@ -72,8 +73,8 @@ export class GitHubClient {
7273

7374
/**
7475
* Get the number of changes for a given pull.
75-
* @param {GetFilesAndChangesProps} props - Properties for which files and changes to get.
76-
* @returns {Promise<FilesAndChanges>}
76+
*
77+
* @param props Properties for which files and changes to get.
7778
*/
7879
async getFilesAndChanges({ number, repo }: GetFilesAndChangesProps): Promise<FilesAndChanges> {
7980
const { data: fileList } = await this.client.rest.pulls.listFiles({
@@ -97,7 +98,6 @@ export class GitHubClient {
9798

9899
/**
99100
* Get organization associated with current token.
100-
* @returns {Promise<Organization>}
101101
*/
102102
async getOrg(): Promise<Organization> {
103103
if (!this.cacheOrganization) {
@@ -126,16 +126,15 @@ export class GitHubClient {
126126

127127
/**
128128
* Get organization name associated with current token.
129-
* @returns {Promise<string>}
130129
*/
131130
async getOrgName(): Promise<string> {
132131
return (await this.getOrg()).name
133132
}
134133

135134
/**
136135
* Get a pull report.
137-
* @param {Pull[]} pulls - Pulls against which a report will be generated.
138-
* @returns {unknown}
136+
*
137+
* @param pulls Pulls against which a report will be generated.
139138
*/
140139
getPullReport(pulls: Pull[]) {
141140
const report: Record<string, ReportItem> = {}
@@ -183,8 +182,8 @@ export class GitHubClient {
183182

184183
/**
185184
* Get all pulls in the GitHub org.
186-
* @param {GetPullsProps} props - Properties for which pulls to get.
187-
* @returns {Promise<Pull[]>}
185+
*
186+
* @param props Properties for which pulls to get.
188187
*/
189188
async getPulls({
190189
oldest = adjustDate({ months: -6, snap: SnapType.Month }),
@@ -283,10 +282,9 @@ export class GitHubClient {
283282
}
284283

285284
/**
286-
*
287285
* Get repositories in the GitHub org that the token has access to.
288-
* @param {GetRepositoriesProps} props - Properties for which repositories to get.
289-
* @returns {Promise<GitHubRepositories>}
286+
*
287+
* @param props Properties for which repositories to get.
290288
*/
291289
async getRepositories({
292290
repositoryFilter = [],
@@ -322,9 +320,9 @@ export class GitHubClient {
322320

323321
/**
324322
* Get requested reviewers in a pull.
325-
* @param {string} repo - The repository associated with the pull.
326-
* @param {number} number - The pull number.
327-
* @returns {Promise<GitHubPullRequestedReviewers>}
323+
*
324+
* @param repo The repository associated with the pull.
325+
* @param number The pull number.
328326
*/
329327
async getRequestedReviewers(repo: string, number: number): Promise<GitHubPullRequestedReviewers> {
330328
const response = await this.client.rest.pulls.listRequestedReviewers({
@@ -338,9 +336,9 @@ export class GitHubClient {
338336

339337
/**
340338
* Get the required number of reviewers for a branch based on branch rules.
341-
* @param {string} repo - The repository to get branch rules for.
342-
* @param {string} branchName - The branch to get branch rules for.
343-
* @returns {Promise<number>}
339+
*
340+
* @param repo The repository to get branch rules for.
341+
* @param branchName The branch to get branch rules for.
344342
*/
345343
async getRequiredReviewers(repo: string, branchName: string): Promise<number> {
346344
const org = await this.getOrgName()
@@ -392,12 +390,12 @@ export class GitHubClient {
392390

393391
/**
394392
* Get a report of the pull reviews.
395-
* @param {string} repo - The repository associated with the pull.
396-
* @param {number} number - The pull number.
397-
* @param {string} baseRef - The base ref of the pull.
398-
* @param {stringp[]} requestedReviewers - A list of requested reviewer logins.
399-
* @param {boolean} [onlyGhReviews] - Only return Github review data in the report.
400-
* @returns {Promise<ReviewReport>}
393+
*
394+
* @param repo The repository associated with the pull.
395+
* @param number The pull number.
396+
* @param baseRef The base ref of the pull.
397+
* @param requestedReviewers A list of requested reviewer logins.
398+
* @param [onlyGhReviews] Only return Github review data in the report.
401399
*/
402400
async getReviewReport(
403401
repo: string,
@@ -481,8 +479,8 @@ export class GitHubClient {
481479

482480
/**
483481
* Get a GitHub user object from a username.
484-
* @param {string} username - A GitHub username.
485-
* @returns {Promise<GitHubUser>}
482+
*
483+
* @param username A GitHub username.
486484
*/
487485
async getUser(username: string): Promise<GitHubUser> {
488486
console.log(`Getting user from GitHub for username [${username}]...`)

src/utils/slack/blocks.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import { formatStringList, getAgeBasedEmoji, haveOrHas, plural } from '../misc.j
99

1010
/**
1111
* Get the first Slack block which includes a header and buttons.
12-
* @param {string} org - The GitHub org.
13-
* @param {string} header - The header text.
14-
* @param {string} [text] - The sub-header text.
15-
* @returns {KnownBlock[]}
12+
*
13+
* @param org The GitHub org.
14+
* @param header The header text.
15+
* @param [text] The sub-header text.
1616
*/
1717
export function getFirstBlocks(org: string, header: string, text?: string): KnownBlock[] {
1818
return [
@@ -53,18 +53,18 @@ export function getFirstBlocks(org: string, header: string, text?: string): Know
5353

5454
/**
5555
* Get the last Slack block which includes footer markdown.
56-
* @param {string} text - The footer text/markdown.
57-
* @returns {KnownBlock[]}
56+
*
57+
* @param text The footer text/markdown.
5858
*/
5959
export function getLastBlocks(text: string): KnownBlock[] {
6060
return getContextMarkdownBlock(text)
6161
}
6262

6363
/**
6464
* Get a context block with markdown text.
65-
* @param {string} text - The footer text/markdown.
66-
* @param {boolean} [withIndentation=false] - Include leading white space.
67-
* @returns {KnownBlock[]}
65+
*
66+
* @param text The footer text/markdown.
67+
* @param [withIndentation=false] Include leading white space.
6868
*/
6969
export function getContextMarkdownBlock(text: string, withIndentation = false): KnownBlock[] {
7070
const elements: PlainTextElement[] = []
@@ -91,10 +91,10 @@ export function getContextMarkdownBlock(text: string, withIndentation = false):
9191

9292
/**
9393
* Get a pull block.
94-
* @param {Pull} pull - Pull data.
95-
* @param {SlackClient} slack - Slack client.
96-
* @param {boolean} withUserMentions - Whether or not to mention Slack users.
97-
* @returns {Promise<KnownBlock[]>}
94+
*
95+
* @param pull Pull data.
96+
* @param slack Slack client.
97+
* @param withUserMentions Whether or not to mention Slack users.
9898
*/
9999
// eslint-disable-next-line max-lines-per-function
100100
export async function getPullBlocks(pull: Pull, slack: SlackClient, withUserMentions: boolean): Promise<KnownBlock[]> {
@@ -223,10 +223,10 @@ export async function getPullBlocks(pull: Pull, slack: SlackClient, withUserMent
223223
}
224224

225225
/**
226-
* Get emoji blocks,.
227-
* @param {string} name - The name of the emoji.
228-
* @param {string} type - The type of section.
229-
* @returns {(PlainTextElement | RichTextElement)[]}
226+
* Get emoji blocks.
227+
*
228+
* @param name The name of the emoji.
229+
* @param type The type of section.
230230
*/
231231
export function getEmojiBlocks(name?: string, type = 'rich_text_section'): (PlainTextElement | RichTextElement)[] {
232232
if (!name) {

src/utils/slack/slack-client.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export class SlackClient {
1717

1818
/**
1919
* Slack client for interacting with the Slack API.
20-
* @param {string} token - Slack token.
21-
* @param {string[]} channels - Slack channel IDs for posting messages in.
20+
*
21+
* @param token Slack token.
22+
* @param channels Slack channel IDs for posting messages in.
2223
*/
2324
constructor({ channels, token }: SlackClientProps) {
2425
this.client = new WebClient(token)
@@ -27,8 +28,8 @@ export class SlackClient {
2728

2829
/**
2930
* Ensure app name pattern.
30-
* @param {RegExp} pattern - The pattern to require the bot name to adhere to.
31-
* @returns {Promise<void>}
31+
*
32+
* @param pattern The pattern to require the bot name to adhere to.
3233
*/
3334
async enforceAppNamePattern(pattern: RegExp): Promise<void> {
3435
const info = await this.getBotInfo()
@@ -48,7 +49,6 @@ export class SlackClient {
4849

4950
/**
5051
* Get all Slack users.
51-
* @returns {Promise<Member[]>}
5252
*/
5353
async getAllusers(): Promise<Member[]> {
5454
this.users = []
@@ -77,7 +77,6 @@ export class SlackClient {
7777

7878
/**
7979
* Get Slack app information for current app.
80-
* @returns {void}
8180
*/
8281
async getBotInfo(): Promise<BotsInfoResponse> {
8382
try {
@@ -96,10 +95,10 @@ export class SlackClient {
9695

9796
/**
9897
* Get a Slack user object based on matching email or username.
99-
* @param {string | undefined} email - An email address that hopefully as matched to a Slack user account.
100-
* @param {string} username - An email address that hopefully as matched to a Slack user account.
101-
* @param {string} [botId] - The botId for the bot to find.
102-
* @returns {Promise<Member | undefined>}
98+
*
99+
* @param email An email address that hopefully as matched to a Slack user account.
100+
* @param username An email address that hopefully as matched to a Slack user account.
101+
* @param [botId] The botId for the bot to find.
103102
*/
104103
async getSlackUser({ email, userId, username }: GetUser): Promise<Member | undefined> {
105104
console.log(`Getting Slack UserId for email [${email}], username [${username}], and userId [${userId}]...`)
@@ -133,10 +132,10 @@ export class SlackClient {
133132

134133
/**
135134
* Post a message with blocks to Slack channels.
136-
* @param {string} text - The message to post.
137-
* @param {KnownBlocks[]} blocks - Slack blocks to post.
138-
* @param {string[]} [channels=this.channels] - Channels to post to.
139-
* @returns {Promise<void>}
135+
*
136+
* @param text The message to post.
137+
* @param blocks Slack blocks to post.
138+
* @param [channels=this.channels] Channels to post to.
140139
*/
141140
async postMessage(text: string, blocks: Block[], channels = this.channels): Promise<void> {
142141
for (const channel of channels) {

0 commit comments

Comments
 (0)