Skip to content

Commit b93f0c2

Browse files
committed
fix: logging
1 parent 8e4fba1 commit b93f0c2

File tree

7 files changed

+91
-32
lines changed

7 files changed

+91
-32
lines changed

dist/index.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80770,7 +80770,7 @@ const { /* homepage */ "TB": homepage, /* name */ "UU": name, /* version */ "rE"
8077080770
*/
8077180771
async function main() {
8077280772
try {
80773-
(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.debug)('Starting main...');
80773+
console.log(`Starting GitHub Notifier version [${version}]...`);
8077480774
const { githubConfig, repositoryFilter, slackConfig, withArchived, withDrafts, withPublic, withTestData, withUserMentions, } = (0,_input_parser_js__WEBPACK_IMPORTED_MODULE_10__/* .parseInputs */ .T)();
8077580775
const slack = new _utils_slack_client_js__WEBPACK_IMPORTED_MODULE_8__/* .SlackClient */ .Q(slackConfig);
8077680776
const results = await githubConfig.tokens.reduce(async (accPromise, token) => {
@@ -80789,7 +80789,7 @@ async function main() {
8078980789
});
8079080790
const org = await client.getOrg();
8079180791
const pulls = await client.getPulls({ repositories, state: _utils_github_structures_js__WEBPACK_IMPORTED_MODULE_6__/* .PullState */ .lT.Open, withDrafts });
80792-
console.log(`Found [${pulls.length}] pulls for [${org.name}]`);
80792+
console.log(`Found [${pulls.length}] ${(0,_krauters_utils__WEBPACK_IMPORTED_MODULE_2__.plural)('pull', pulls.length)} for [${org.name}]`);
8079380793
return [...acc, { client, org: org.name, pulls }];
8079480794
}
8079580795
catch (error) {
@@ -80808,6 +80808,7 @@ async function main() {
8080880808
const dedupedPulls = [...new Map(pulls.map((pull) => [`${pull.org}/${pull.repo}/${pull.number}`, pull]))].map(
8080980809
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unused-vars
8081080810
([_, pull]) => pull);
80811+
console.log(`After deduplication, there are [${dedupedPulls.length}] unique pull requests`);
8081180812
let blocks = [];
8081280813
for (const pull of dedupedPulls) {
8081380814
(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.debug)(`Building Slack blocks from pull request [${pull.number}]`);
@@ -80842,7 +80843,9 @@ async function main() {
8084280843
`/${_actions_github__WEBPACK_IMPORTED_MODULE_0__.context.payload.repository?.name}> (<${_constants_js__WEBPACK_IMPORTED_MODULE_4__/* .workflowLogsUrl */ .GM}|logs>) using <${homepage}|${name}>@<${homepage}/releases/tag/${version}|${version}>`,
8084380844
].join('')),
8084480845
];
80846+
console.log(`Posting [${blocks.length}] Slack blocks to [${slack.channels.length}] channels`);
8084580847
await slack.postMessage(header, blocks);
80848+
console.log('Successfully posted notification to Slack');
8084680849
}
8084780850
catch (error) {
8084880851
console.error(`Fatal error [${error}]`);
@@ -81092,22 +81095,25 @@ class GitHubClient {
8109281095
* @param props Configuration for retrieving pull requests.
8109381096
*/
8109481097
async getPulls({ oldest = (0,_krauters_utils__WEBPACK_IMPORTED_MODULE_2__.snapDate)(new Date(), { months: -36, snap: _krauters_utils__WEBPACK_IMPORTED_MODULE_2__.SnapType.Month }), onlyGhReviews = false, repositories, state = _structures_js__WEBPACK_IMPORTED_MODULE_0__/* .PullState */ .lT.All, withCommits = true, withDrafts, withFilesAndChanges = true, withUser = true, }) {
81098+
const startTime = Date.now();
8109581099
const org = await this.getOrgName();
81096-
console.log('\n');
8109781100
if (state === _structures_js__WEBPACK_IMPORTED_MODULE_0__/* .PullState */ .lT.Open) {
81098-
console.log(`Getting [${state}] pulls in org [${org}]...`);
81101+
(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.debug)(`Getting [${state}] ${(0,_krauters_utils__WEBPACK_IMPORTED_MODULE_2__.plural)('pull', 2)} in org [${org}]...`);
8109981102
}
8110081103
else {
81101-
console.log(`Getting [${state}] pulls in org [${org}] that are newer than [${oldest}...`);
81104+
(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.debug)(`Getting [${state}] ${(0,_krauters_utils__WEBPACK_IMPORTED_MODULE_2__.plural)('pull', 2)} in org [${org}] that are newer than [${oldest}]...`);
8110281105
}
8110381106
const pullRequests = [];
81107+
let apiRequestCount = 0;
8110481108
for (const repo of repositories) {
8110581109
(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.debug)(`Getting [${state}] pulls in repository [${repo.name}]...`);
81110+
const repoStartTime = Date.now();
8110681111
const pulls = await this.client.paginate(this.client.rest.pulls.list, {
8110781112
owner: org,
8110881113
repo: repo.name,
8110981114
state,
8111081115
}, (response, done) => {
81116+
apiRequestCount++;
8111181117
(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.debug)(`Paginated response for repository [${repo.name}], status [${response.status}], items [${response.data.length}]`);
8111281118
const found = response.data.find((pull) => new Date(pull.created_at) < oldest);
8111381119
if (found && state !== _structures_js__WEBPACK_IMPORTED_MODULE_0__/* .PullState */ .lT.Open) {
@@ -81116,7 +81122,8 @@ class GitHubClient {
8111681122
}
8111781123
return response.data.filter((pull) => new Date(pull.created_at) > oldest);
8111881124
});
81119-
console.log(`Found [${pulls.length}] pull in repository [${repo.name}]`);
81125+
const repoDuration = (Date.now() - repoStartTime) / 1000;
81126+
console.log(`Found [${pulls.length}] pull in repository [${repo.name}] in [${repoDuration.toFixed(2)}] seconds`);
8112081127
for (const pull of pulls) {
8112181128
const { base, closed_at, created_at, draft, html_url, merged_at, number, title, user } = pull;
8112281129
(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.debug)(`Processing pull [${number}]...`);
@@ -81155,6 +81162,8 @@ class GitHubClient {
8115581162
(0,_actions_core__WEBPACK_IMPORTED_MODULE_1__.debug)(`Added pull [${number}] to response`);
8115681163
}
8115781164
}
81165+
const totalDuration = (Date.now() - startTime) / 1000;
81166+
console.log(`Completed processing [${pullRequests.length}] pull requests in [${totalDuration.toFixed(2)}] seconds with [${apiRequestCount}] API calls`);
8115881167
return pullRequests;
8115981168
}
8116081169
/**
@@ -81832,6 +81841,7 @@ class SlackClient {
8183281841
this.client = new dist.WebClient(token);
8183381842
this.channels = channels;
8183481843
this.userMappings = userMappings;
81844+
console.log(`Slack client initialized with [${channels.length}] channels and [${userMappings.length}] user mappings`);
8183581845
}
8183681846
/**
8183781847
* Ensure app name pattern.
@@ -81848,6 +81858,7 @@ class SlackClient {
8184881858
throw new Error(`Current app name [${name}] does not match the desired pattern [${pattern}]. Please update Slack app "Basic Information" > "Display Information" > "App name" to have the suffix "GitHub Notifier". Slack app url [${SlackAppUrl.Prefix}/${info?.bot?.app_id}/${SlackAppUrl.SuffixDisplayInfo}].`);
8184981859
}
8185081860
this.bot = info.bot;
81861+
console.log(`Verified Slack app name: [${name}]`);
8185181862
}
8185281863
/**
8185381864
* Get all Slack users.
@@ -81856,6 +81867,7 @@ class SlackClient {
8185681867
this.users = [];
8185781868
let cursor;
8185881869
console.log('Getting all Slack users...');
81870+
const startTime = Date.now();
8185981871
try {
8186081872
// Keep paginating until no more cursor is returned
8186181873
do {
@@ -81866,7 +81878,8 @@ class SlackClient {
8186681878
cursor = result.response_metadata?.next_cursor;
8186781879
(0,core.debug)(`Got [${result.members?.length}] users from Slack`);
8186881880
} while (cursor);
81869-
console.log(`Got a total of [${this.users.length}] active users from Slack`);
81881+
const duration = (Date.now() - startTime) / 1000;
81882+
console.log(`Got a total of [${this.users.length}] active users from Slack in [${duration.toFixed(2)}] seconds`);
8187081883
return this.users;
8187181884
}
8187281885
catch (error) {
@@ -81879,6 +81892,7 @@ class SlackClient {
8187981892
*/
8188081893
async getBotInfo() {
8188181894
try {
81895+
console.log('Getting Slack bot information...');
8188281896
const authResponse = await this.client.auth.test({});
8188381897
const response = await this.client.bots.info({ bot: authResponse.bot_id });
8188481898
if (!response.ok) {
@@ -81928,10 +81942,16 @@ class SlackClient {
8192881942
* @param [channels=this.channels] Channels to post to.
8192981943
*/
8193081944
async postMessage(text, blocks, channels = this.channels) {
81945+
const startTime = Date.now();
81946+
const totalBlocks = blocks.length;
81947+
const batches = (0,src.getBatches)(blocks);
81948+
(0,core.debug)(`Preparing to post [${totalBlocks}] blocks to [${channels.length}] channels`);
8193181949
for (const channel of channels) {
8193281950
let batchNumber = 0;
81933-
for (const batch of (0,src.getBatches)(blocks)) {
81934-
console.log(`Posting batch [${batchNumber++}] to Slack channel [${channel}]...`);
81951+
for (const batch of batches) {
81952+
batchNumber++;
81953+
const batchStartTime = Date.now();
81954+
(0,core.debug)(`Posting batch [${batchNumber}] to Slack channel [${channel}]...`);
8193581955
const payload = {
8193681956
blocks: batch.items,
8193781957
channel,
@@ -81945,9 +81965,12 @@ class SlackClient {
8194581965
(0,core.debug)(JSON.stringify(payload, null, 2));
8194681966
const response = await this.client.chat.postMessage(payload);
8194781967
(0,core.debug)(JSON.stringify(response, null, 2));
81948-
console.log(`Posted batch [${batchNumber++}] to Slack channel [${channel}] with success [${response.ok}]`);
81968+
const batchDuration = (Date.now() - batchStartTime) / 1000;
81969+
console.log(`Posted batch [${batchNumber}] to Slack channel [${channel}] with success [${response.ok}] in [${batchDuration.toFixed(2)}] seconds`);
8194981970
}
8195081971
}
81972+
const totalDuration = (Date.now() - startTime) / 1000;
81973+
console.log(`Completed posting all messages to Slack in [${totalDuration.toFixed(2)}] seconds`);
8195181974
}
8195281975
}
8195381976

@@ -90605,7 +90628,7 @@ module.exports = {"version":"3.17.0"};
9060590628
/***/ 8330:
9060690629
/***/ ((module) => {
9060790630

90608-
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.3.0","TB":"https://buymeacoffee.com/coltenkrauter"}');
90631+
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.3.1","TB":"https://buymeacoffee.com/coltenkrauter"}');
9060990632

9061090633
/***/ })
9061190634

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.

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@krauters/github-notifier",
33
"description": "GitHub Notifier by Krauters – Post Open Pull Requests to Slack",
4-
"version": "1.3.0",
4+
"version": "1.3.1",
55
"author": "Colten Krauter <coltenkrauter>",
66
"type": "module",
77
"homepage": "https://buymeacoffee.com/coltenkrauter",
@@ -47,7 +47,7 @@
4747
"devDependencies": {
4848
"@krauters/eslint-config": "^1.8.0",
4949
"@types/jest": "^29.5.14",
50-
"@types/node": "^22.14.1",
50+
"@types/node": "^22.15.0",
5151
"@vercel/ncc": "^0.38.3",
5252
"husky": "9.1.7",
5353
"jest": "^29.7.0",

src/app.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const { homepage, name, version } = pkg
2323
*/
2424
async function main(): Promise<void> {
2525
try {
26-
debug('Starting main...')
26+
console.log(`Starting GitHub Notifier version [${version}]...`)
27+
2728
const {
2829
githubConfig,
2930
repositoryFilter,
@@ -55,7 +56,7 @@ async function main(): Promise<void> {
5556

5657
const org = await client.getOrg()
5758
const pulls = await client.getPulls({ repositories, state: PullState.Open, withDrafts })
58-
console.log(`Found [${pulls.length}] pulls for [${org.name}]`)
59+
console.log(`Found [${pulls.length}] ${plural('pull', pulls.length)} for [${org.name}]`)
5960

6061
return [...acc, { client, org: org.name, pulls }]
6162
} catch (error: unknown) {
@@ -85,6 +86,7 @@ async function main(): Promise<void> {
8586
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unused-vars
8687
([_, pull]) => pull,
8788
)
89+
console.log(`After deduplication, there are [${dedupedPulls.length}] unique pull requests`)
8890

8991
let blocks: KnownBlock[] = []
9092
for (const pull of dedupedPulls) {
@@ -130,7 +132,9 @@ async function main(): Promise<void> {
130132
),
131133
]
132134

135+
console.log(`Posting [${blocks.length}] Slack blocks to [${slack.channels.length}] channels`)
133136
await slack.postMessage(header, blocks)
137+
console.log('Successfully posted notification to Slack')
134138
} catch (error) {
135139
console.error(`Fatal error [${error}]`)
136140
process.exit(1)

src/utils/github/client.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
reviewText,
2828
} from './structures.js'
2929
import { debug } from '@actions/core'
30-
import { average, getHoursAgo, minutesBetweenDates, snapDate, SnapType } from '@krauters/utils'
30+
import { average, getHoursAgo, minutesBetweenDates, plural, snapDate, SnapType } from '@krauters/utils'
3131
import { ignoreFilenamesForChanges } from '../../constants.js'
3232
import { getRelativeHumanReadableAge } from '../misc.js'
3333

@@ -205,17 +205,19 @@ export class GitHubClient {
205205
withFilesAndChanges = true,
206206
withUser = true,
207207
}: GetPullsProps): Promise<Pull[]> {
208+
const startTime = Date.now()
208209
const org = await this.getOrgName()
209-
console.log('\n')
210210
if (state === PullState.Open) {
211-
console.log(`Getting [${state}] pulls in org [${org}]...`)
211+
debug(`Getting [${state}] ${plural('pull', 2)} in org [${org}]...`)
212212
} else {
213-
console.log(`Getting [${state}] pulls in org [${org}] that are newer than [${oldest}...`)
213+
debug(`Getting [${state}] ${plural('pull', 2)} in org [${org}] that are newer than [${oldest}]...`)
214214
}
215215

216216
const pullRequests = []
217+
let apiRequestCount = 0
217218
for (const repo of repositories) {
218219
debug(`Getting [${state}] pulls in repository [${repo.name}]...`)
220+
const repoStartTime = Date.now()
219221
const pulls = await this.client.paginate(
220222
this.client.rest.pulls.list,
221223
{
@@ -224,6 +226,7 @@ export class GitHubClient {
224226
state,
225227
},
226228
(response, done) => {
229+
apiRequestCount++
227230
debug(
228231
`Paginated response for repository [${repo.name}], status [${response.status}], items [${response.data.length}]`,
229232
)
@@ -237,7 +240,10 @@ export class GitHubClient {
237240
},
238241
)
239242

240-
console.log(`Found [${pulls.length}] pull in repository [${repo.name}]`)
243+
const repoDuration = (Date.now() - repoStartTime) / 1000
244+
console.log(
245+
`Found [${pulls.length}] pull in repository [${repo.name}] in [${repoDuration.toFixed(2)}] seconds`,
246+
)
241247
for (const pull of pulls) {
242248
const { base, closed_at, created_at, draft, html_url, merged_at, number, title, user } = pull
243249
debug(`Processing pull [${number}]...`)
@@ -286,6 +292,11 @@ export class GitHubClient {
286292
}
287293
}
288294

295+
const totalDuration = (Date.now() - startTime) / 1000
296+
console.log(
297+
`Completed processing [${pullRequests.length}] pull requests in [${totalDuration.toFixed(2)}] seconds with [${apiRequestCount}] API calls`,
298+
)
299+
289300
return pullRequests
290301
}
291302

0 commit comments

Comments
 (0)