Skip to content

Commit 856168a

Browse files
committed
feat(logs): better logging for issues where users have reported issues for a pr where as we have more traffic now we need to check which ID belongs to them vs others with same ids for their prs
1 parent 9c0c3a6 commit 856168a

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

index.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
const checkOutstandingTasks = require('./src/check-outstanding-tasks');
22

3-
const ENABLE_ID_LOGS = true; // simple ID only logs, no private repo data logged
3+
const ENABLE_ID_LOGS = true; // Repo name & ID only for logs, no private data logged! (Repo name only needed to help with issue reports & debugging).
44

55
module.exports = (app) => {
66
app.log('Yay! The app was loaded!');
77

8+
// log helper
9+
function log(pr, message) {
10+
if (ENABLE_ID_LOGS) {
11+
app.log(`PR ${pr.head.repo.full_name}#${pr.number}: ${message}`);
12+
}
13+
}
14+
815
// watch for pull requests & their changes
916
app.on([
1017
'pull_request.opened',
@@ -35,9 +42,7 @@ module.exports = (app) => {
3542
return;
3643
}
3744

38-
if (ENABLE_ID_LOGS) {
39-
app.log(`PR #${pr.number}: Request received`);
40-
}
45+
log(pr, 'Request received');
4146

4247
let prBody = pr.body;
4348

@@ -56,9 +61,7 @@ module.exports = (app) => {
5661
issue_number: pr.number
5762
}));
5863

59-
if (ENABLE_ID_LOGS) {
60-
app.log(`PR #${pr.number}: Main comments api lookup complete`);
61-
}
64+
log(pr, 'Main comments api lookup complete');
6265

6366
// as well as review comments
6467
let reviewComments = await context.octokit.pulls.listReviews(context.repo({
@@ -69,9 +72,7 @@ module.exports = (app) => {
6972
comments.data = comments.data.concat(reviewComments.data);
7073
}
7174

72-
if (ENABLE_ID_LOGS) {
73-
app.log(`PR #${pr.number}: Review comments api lookup complete`);
74-
}
75+
log(pr, 'Review comments api lookup complete');
7576

7677
// and diff level comments on reviews
7778
let reviewDiffComments = await context.octokit.pulls.listReviewComments(context.repo({
@@ -82,9 +83,7 @@ module.exports = (app) => {
8283
comments.data = comments.data.concat(reviewDiffComments.data);
8384
}
8485

85-
if (ENABLE_ID_LOGS) {
86-
app.log(`PR #${pr.number}: Diff comments api lookup complete`);
87-
}
86+
log(pr, 'Diff comments api lookup complete');
8887

8988
// & check them for tasks
9089
if (comments.data.length) {
@@ -120,15 +119,11 @@ module.exports = (app) => {
120119
check.output.summary = 'All tasks have been completed';
121120
};
122121

123-
if (ENABLE_ID_LOGS) {
124-
app.log(`PR #${pr.number}: Complete and sending back to GitHub`);
125-
}
122+
log(pr, 'Complete and sending back to GitHub');
126123

127124
// send check back to GitHub
128125
const response = await context.octokit.checks.create(context.repo(check));
129-
if (ENABLE_ID_LOGS) {
130-
app.log(`PR #${pr.number}: Check response status from GitHub ${response.status}`);
131-
}
126+
log(pr, `Check response status from GitHub ${response.status}`);
132127

133128
return;
134129
});

0 commit comments

Comments
 (0)