Skip to content

Commit 790e358

Browse files
committed
refactor: cleanup add @krauter packages
1 parent 7eb9417 commit 790e358

File tree

13 files changed

+80658
-27444
lines changed

13 files changed

+80658
-27444
lines changed

.husky/pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
npm run bundle
44

5+
MAIN_DIR=./node_modules/@krauters/utils/scripts/pre-commit
6+
. $MAIN_DIR/index.sh
7+
58
if [ $? -ne 0 ]; then
69
echo "Command 'npm run bundle' failed"
710
exit 1

dist/index.js

Lines changed: 77056 additions & 25805 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: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@krauters/github-notifier",
33
"description": "GitHub Notifier by Krauters – Post Open Pull Requests to Slack",
4-
"version": "0.13.1",
4+
"version": "0.14.0",
55
"author": "Colten Krauter <coltenkrauter>",
66
"type": "module",
7-
"homepage": "https://github.com/krauters/github-notifier",
7+
"homepage": "https://buymeacoffee.com/coltenkrauter",
88
"repository": {
99
"type": "git",
1010
"url": "git+https://github.com/krauters/github-notifier.git"
@@ -34,24 +34,31 @@
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"
56-
}
58+
"typescript": "^5.6.3",
59+
"typescript-eslint": "^8.13.0"
60+
},
61+
"bugs": {
62+
"url": "https://github.com/krauters/github-notifier/issues/new?title=%5BBUG%5D+Brief+Description&template=bug_report.md"
63+
}
5764
}

src/app.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
import type { KnownBlock } from '@slack/web-api'
44

55
import { context } from '@actions/github'
6+
import { formatStringList, plural, snapDate, SnapType } from '@krauters/utils'
67

78
import type { RunProps } from './structures.js'
89

910
import { homepage, name, version } from '../package.json'
1011
import { workflowLogsUrl, workflowUrl } from './defaults.js'
1112
import { GitHubClient } from './utils/github/github-client.js'
1213
import { PullState, RepositoryType } from './utils/github/structures.js'
13-
import { adjustDate, formatStringList, plural } from './utils/misc.js'
1414
import { getFirstBlocks, getLastBlocks, getPullBlocks } from './utils/slack/blocks.js'
1515
import { SlackClient } from './utils/slack/slack-client.js'
16-
import { SnapType } from './utils/structures.js'
1716
import { getApprovedPullRequest } from './utils/test-data.js'
1817

1918
/**
2019
* Runs the GitHub Notifier to query GitHub for open pull requests and then post messages to Slack channels.
21-
* @param {RunProps} props - Configurable properties of the GitHub Notifier.
22-
* @returns {Promise<void>}
20+
*
21+
* @param props Configurable properties of the GitHub Notifier.
2322
*/
2423
export async function run({
2524
githubProps,
@@ -89,7 +88,7 @@ export async function run({
8988

9089
if (withPullReport) {
9190
const pulls = await gh.getPulls({
92-
oldest: adjustDate({ months: -12, snap: SnapType.Month }),
91+
oldest: snapDate(new Date(), { months: -12, snap: SnapType.Month }),
9392
onlyGhReviews: true,
9493
repositories,
9594
state: PullState.All,

src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { debug, getBooleanInput, getInput } from '@actions/core'
2+
import { stringToArray } from '@krauters/utils'
23

34
import { run } from './app.js'
4-
import { stringToArray } from './utils/misc.js'
55

66
/**
77
* The main function that gets executed when the action is run.
8-
* @returns {undefined}
98
*/
109
export async function main(): Promise<void> {
1110
debug('Starting main...')

src/utils/github/github-client.ts

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
22
import { getOctokit } from '@actions/github'
3+
import { average, getHoursAgo, minutesBetweenDates, snapDate, SnapType } from '@krauters/utils'
34

45
import { ignoreFilenamesForChanges } from '../../defaults.js'
5-
import { adjustDate, average, getHoursAgo, getRelativeHumanReadableAge, minutesBetweenDates } from '../misc.js'
6-
import { SnapType } from '../structures.js'
6+
import { getRelativeHumanReadableAge } from '../misc.js'
77
import {
88
type FilesAndChanges,
99
type GetCommitsProps,
@@ -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,11 +182,11 @@ 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({
190-
oldest = adjustDate({ months: -6, snap: SnapType.Month }),
189+
oldest = snapDate(new Date(), { months: -6, snap: SnapType.Month }),
191190
onlyGhReviews = false,
192191
repositories,
193192
state = PullState.All,
@@ -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}]...`)

0 commit comments

Comments
 (0)