Skip to content

Commit

Permalink
refactor: cleanup add @krauter packages
Browse files Browse the repository at this point in the history
  • Loading branch information
coltenkrauter committed Nov 8, 2024
1 parent 7eb9417 commit 9cd388e
Show file tree
Hide file tree
Showing 8 changed files with 6,030 additions and 3,109 deletions.
4,142 changes: 2,453 additions & 1,689 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sourcemap-register.cjs

Large diffs are not rendered by default.

4,848 changes: 3,502 additions & 1,346 deletions package-lock.json

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,28 @@
},
"license": "ISC",
"dependencies": {
"@actions/core": "1.10.1",
"@actions/core": "1.11.1",
"@actions/github": "6.0.0",
"@krauters/environment": "^0.2.1",
"@krauters/logger": "^0.3.2",
"@krauters/structures": "^1.0.2",
"@krauters/utils": "^1.0.0",
"@octokit/rest": "21.0.2",
"@octokit/types": "13.5.0",
"@slack/web-api": "7.4.0",
"simple-git": "^3.26.0"
"@octokit/types": "13.6.1",
"@slack/web-api": "7.7.0",
"simple-git": "^3.27.0"
},
"devDependencies": {
"@krauters/eslint-config": "^0.1.0",
"@types/jest": "^29.5.12",
"@types/node": "^22.5.4",
"@vercel/ncc": "^0.38.1",
"husky": "9.1.5",
"@krauters/eslint-config": "^1.4.0",
"@types/jest": "^29.5.14",
"@types/node": "^22.9.0",
"@vercel/ncc": "^0.38.2",
"husky": "9.1.6",
"jest": "^29.7.0",
"make-coverage-badge": "^1.2.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"typescript-eslint": "^8.5.0"
"typescript": "^5.6.3",
"typescript-eslint": "^8.13.0"
}
}
58 changes: 28 additions & 30 deletions src/utils/github/github-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ export class GitHubClient {

/**
* A GitHub client for interacting with a GitHub API.
* @param {GitHubClientProps} props - Properties toi configure GitHub client.
*
* @param props Properties toi configure GitHub client.
*/
constructor({ options = {}, token }: GitHubClientProps) {
this.client = getOctokit(token, options)
}

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

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

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

/**
* Get organization associated with current token.
* @returns {Promise<Organization>}
*/
async getOrg(): Promise<Organization> {
if (!this.cacheOrganization) {
Expand Down Expand Up @@ -126,16 +126,15 @@ export class GitHubClient {

/**
* Get organization name associated with current token.
* @returns {Promise<string>}
*/
async getOrgName(): Promise<string> {
return (await this.getOrg()).name
}

/**
* Get a pull report.
* @param {Pull[]} pulls - Pulls against which a report will be generated.
* @returns {unknown}
*
* @param pulls Pulls against which a report will be generated.
*/
getPullReport(pulls: Pull[]) {
const report: Record<string, ReportItem> = {}
Expand Down Expand Up @@ -183,8 +182,8 @@ export class GitHubClient {

/**
* Get all pulls in the GitHub org.
* @param {GetPullsProps} props - Properties for which pulls to get.
* @returns {Promise<Pull[]>}
*
* @param props Properties for which pulls to get.
*/
async getPulls({
oldest = adjustDate({ months: -6, snap: SnapType.Month }),
Expand Down Expand Up @@ -283,10 +282,9 @@ export class GitHubClient {
}

/**
*
* Get repositories in the GitHub org that the token has access to.
* @param {GetRepositoriesProps} props - Properties for which repositories to get.
* @returns {Promise<GitHubRepositories>}
*
* @param props Properties for which repositories to get.
*/
async getRepositories({
repositoryFilter = [],
Expand Down Expand Up @@ -322,9 +320,9 @@ export class GitHubClient {

/**
* Get requested reviewers in a pull.
* @param {string} repo - The repository associated with the pull.
* @param {number} number - The pull number.
* @returns {Promise<GitHubPullRequestedReviewers>}
*
* @param repo The repository associated with the pull.
* @param number The pull number.
*/
async getRequestedReviewers(repo: string, number: number): Promise<GitHubPullRequestedReviewers> {
const response = await this.client.rest.pulls.listRequestedReviewers({
Expand All @@ -338,9 +336,9 @@ export class GitHubClient {

/**
* Get the required number of reviewers for a branch based on branch rules.
* @param {string} repo - The repository to get branch rules for.
* @param {string} branchName - The branch to get branch rules for.
* @returns {Promise<number>}
*
* @param repo The repository to get branch rules for.
* @param branchName The branch to get branch rules for.
*/
async getRequiredReviewers(repo: string, branchName: string): Promise<number> {
const org = await this.getOrgName()
Expand Down Expand Up @@ -392,12 +390,12 @@ export class GitHubClient {

/**
* Get a report of the pull reviews.
* @param {string} repo - The repository associated with the pull.
* @param {number} number - The pull number.
* @param {string} baseRef - The base ref of the pull.
* @param {stringp[]} requestedReviewers - A list of requested reviewer logins.
* @param {boolean} [onlyGhReviews] - Only return Github review data in the report.
* @returns {Promise<ReviewReport>}
*
* @param repo The repository associated with the pull.
* @param number The pull number.
* @param baseRef The base ref of the pull.
* @param requestedReviewers A list of requested reviewer logins.
* @param [onlyGhReviews] Only return Github review data in the report.
*/
async getReviewReport(
repo: string,
Expand Down Expand Up @@ -481,8 +479,8 @@ export class GitHubClient {

/**
* Get a GitHub user object from a username.
* @param {string} username - A GitHub username.
* @returns {Promise<GitHubUser>}
*
* @param username A GitHub username.
*/
async getUser(username: string): Promise<GitHubUser> {
console.log(`Getting user from GitHub for username [${username}]...`)
Expand Down
34 changes: 17 additions & 17 deletions src/utils/slack/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { formatStringList, getAgeBasedEmoji, haveOrHas, plural } from '../misc.j

/**
* Get the first Slack block which includes a header and buttons.
* @param {string} org - The GitHub org.
* @param {string} header - The header text.
* @param {string} [text] - The sub-header text.
* @returns {KnownBlock[]}
*
* @param org The GitHub org.
* @param header The header text.
* @param [text] The sub-header text.
*/
export function getFirstBlocks(org: string, header: string, text?: string): KnownBlock[] {
return [
Expand Down Expand Up @@ -53,18 +53,18 @@ export function getFirstBlocks(org: string, header: string, text?: string): Know

/**
* Get the last Slack block which includes footer markdown.
* @param {string} text - The footer text/markdown.
* @returns {KnownBlock[]}
*
* @param text The footer text/markdown.
*/
export function getLastBlocks(text: string): KnownBlock[] {
return getContextMarkdownBlock(text)
}

/**
* Get a context block with markdown text.
* @param {string} text - The footer text/markdown.
* @param {boolean} [withIndentation=false] - Include leading white space.
* @returns {KnownBlock[]}
*
* @param text The footer text/markdown.
* @param [withIndentation=false] Include leading white space.
*/
export function getContextMarkdownBlock(text: string, withIndentation = false): KnownBlock[] {
const elements: PlainTextElement[] = []
Expand All @@ -91,10 +91,10 @@ export function getContextMarkdownBlock(text: string, withIndentation = false):

/**
* Get a pull block.
* @param {Pull} pull - Pull data.
* @param {SlackClient} slack - Slack client.
* @param {boolean} withUserMentions - Whether or not to mention Slack users.
* @returns {Promise<KnownBlock[]>}
*
* @param pull Pull data.
* @param slack Slack client.
* @param withUserMentions Whether or not to mention Slack users.
*/
// eslint-disable-next-line max-lines-per-function
export async function getPullBlocks(pull: Pull, slack: SlackClient, withUserMentions: boolean): Promise<KnownBlock[]> {
Expand Down Expand Up @@ -223,10 +223,10 @@ export async function getPullBlocks(pull: Pull, slack: SlackClient, withUserMent
}

/**
* Get emoji blocks,.
* @param {string} name - The name of the emoji.
* @param {string} type - The type of section.
* @returns {(PlainTextElement | RichTextElement)[]}
* Get emoji blocks.
*
* @param name The name of the emoji.
* @param type The type of section.
*/
export function getEmojiBlocks(name?: string, type = 'rich_text_section'): (PlainTextElement | RichTextElement)[] {
if (!name) {
Expand Down
27 changes: 13 additions & 14 deletions src/utils/slack/slack-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export class SlackClient {

/**
* Slack client for interacting with the Slack API.
* @param {string} token - Slack token.
* @param {string[]} channels - Slack channel IDs for posting messages in.
*
* @param token Slack token.
* @param channels Slack channel IDs for posting messages in.
*/
constructor({ channels, token }: SlackClientProps) {
this.client = new WebClient(token)
Expand All @@ -27,8 +28,8 @@ export class SlackClient {

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

/**
* Get all Slack users.
* @returns {Promise<Member[]>}
*/
async getAllusers(): Promise<Member[]> {
this.users = []
Expand Down Expand Up @@ -77,7 +77,6 @@ export class SlackClient {

/**
* Get Slack app information for current app.
* @returns {void}
*/
async getBotInfo(): Promise<BotsInfoResponse> {
try {
Expand All @@ -96,10 +95,10 @@ export class SlackClient {

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

/**
* Post a message with blocks to Slack channels.
* @param {string} text - The message to post.
* @param {KnownBlocks[]} blocks - Slack blocks to post.
* @param {string[]} [channels=this.channels] - Channels to post to.
* @returns {Promise<void>}
*
* @param text The message to post.
* @param blocks Slack blocks to post.
* @param [channels=this.channels] Channels to post to.
*/
async postMessage(text: string, blocks: Block[], channels = this.channels): Promise<void> {
for (const channel of channels) {
Expand Down

0 comments on commit 9cd388e

Please sign in to comment.