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 4f6bafb
Show file tree
Hide file tree
Showing 12 changed files with 80,645 additions and 27,438 deletions.
102,858 changes: 77,054 additions & 25,804 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"
}
}
9 changes: 4 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
import type { KnownBlock } from '@slack/web-api'

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

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

import { homepage, name, version } from '../package.json'
import { workflowLogsUrl, workflowUrl } from './defaults.js'
import { GitHubClient } from './utils/github/github-client.js'
import { PullState, RepositoryType } from './utils/github/structures.js'
import { adjustDate, formatStringList, plural } from './utils/misc.js'
import { getFirstBlocks, getLastBlocks, getPullBlocks } from './utils/slack/blocks.js'
import { SlackClient } from './utils/slack/slack-client.js'
import { SnapType } from './utils/structures.js'
import { getApprovedPullRequest } from './utils/test-data.js'

/**
* Runs the GitHub Notifier to query GitHub for open pull requests and then post messages to Slack channels.
* @param {RunProps} props - Configurable properties of the GitHub Notifier.
* @returns {Promise<void>}
*
* @param props Configurable properties of the GitHub Notifier.
*/
export async function run({
githubProps,
Expand Down Expand Up @@ -89,7 +88,7 @@ export async function run({

if (withPullReport) {
const pulls = await gh.getPulls({
oldest: adjustDate({ months: -12, snap: SnapType.Month }),
oldest: snapDate(new Date(), { months: -12, snap: SnapType.Month }),
onlyGhReviews: true,
repositories,
state: PullState.All,
Expand Down
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { debug, getBooleanInput, getInput } from '@actions/core'
import { stringToArray } from '@krauters/utils'

import { run } from './app.js'
import { stringToArray } from './utils/misc.js'

/**
* The main function that gets executed when the action is run.
* @returns {undefined}
*/
export async function main(): Promise<void> {
debug('Starting main...')
Expand Down
64 changes: 31 additions & 33 deletions src/utils/github/github-client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { getOctokit } from '@actions/github'
import { average, getHoursAgo, minutesBetweenDates, snapDate, SnapType } from '@krauters/utils'

import { ignoreFilenamesForChanges } from '../../defaults.js'
import { adjustDate, average, getHoursAgo, getRelativeHumanReadableAge, minutesBetweenDates } from '../misc.js'
import { SnapType } from '../structures.js'
import { getRelativeHumanReadableAge } from '../misc.js'
import {
type FilesAndChanges,
type GetCommitsProps,
Expand Down 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,11 +182,11 @@ 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 }),
oldest = snapDate(new Date(), { months: -6, snap: SnapType.Month }),
onlyGhReviews = false,
repositories,
state = PullState.All,
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
Loading

0 comments on commit 4f6bafb

Please sign in to comment.