Skip to content

Commit

Permalink
fix: improve debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebonsignori committed Aug 1, 2022
1 parent 61b409f commit 27f6b91
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 32 deletions.
22 changes: 17 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@ function run(getCore, getOctokit, getSlack) {
try {
const notificationSubject = yield octokit.request(notification.subject.url);
notification_html_url = (_a = notificationSubject === null || notificationSubject === void 0 ? void 0 : notificationSubject.data) === null || _a === void 0 ? void 0 : _a.html_url;
// If there still isn't an html_url, it lives on another key
if (!notification_html_url) {
core.warning(`Unable to find URL from linked api url for notification\nid :${notification.id}\nsubject:${JSON.stringify(notification.subject, null, 2)}\subject.url request: ${JSON.stringify(notificationSubject.data, null, 2)}`);
}
}
catch (error) {
core.warning(`Unable to fetch URL for notification\nid:${notification.id}\nsubject:${JSON.stringify(notification.subject, null, 2)}`);
core.warning(`Unable to fetch URL for notification\nid :${notification.id}\nsubject:${JSON.stringify(notification.subject, null, 2)}`);
}
return Object.assign(Object.assign({}, notification), { notification_html_url });
})));
Expand Down Expand Up @@ -186,10 +190,18 @@ function displayFilters(inputs) {
return `
<filter-only-unread>: ${inputs.filterOnlyUnread}
<filter-only-participating>: ${inputs.filterOnlyParticipating}
<filter-include-reasons>: ${inputs.filterIncludeReasons.length ? inputs.filterIncludeReasons.join(", ") : "[]"}
<filter-exclude-reasons>: ${inputs.filterExcludeReasons.length ? inputs.filterExcludeReasons.join(", ") : "[]"}
<filter-include-repositories>: ${inputs.filterIncludeRepositories.length ? inputs.filterIncludeRepositories.join(", ") : "[]"}
<filter-exclude-repositories>: ${inputs.filterExcludeRepositories.length ? inputs.filterExcludeRepositories.join(", ") : "[]"}
<filter-include-reasons>: ${inputs.filterIncludeReasons.length
? inputs.filterIncludeReasons.join(", ")
: "[]"}
<filter-exclude-reasons>: ${inputs.filterExcludeReasons.length
? inputs.filterExcludeReasons.join(", ")
: "[]"}
<filter-include-repositories>: ${inputs.filterIncludeRepositories.length
? inputs.filterIncludeRepositories.join(", ")
: "[]"}
<filter-exclude-repositories>: ${inputs.filterExcludeRepositories.length
? inputs.filterExcludeRepositories.join(", ")
: "[]"}
`;
}
// export `run` function for testing
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

78 changes: 52 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,29 +145,43 @@ async function run(
}

// Get the `html_url` for each notification and add it as `notification_html_url`
notifications = await Promise.all(notifications.map(
async (
notification: Endpoints["GET /notifications"]["response"]["data"][0]
) => {
let notification_html_url;
try {
const notificationSubject = await octokit.request(
notification.subject.url
);
notification_html_url = notificationSubject?.data?.html_url;
} catch (error) {
core.warning(
`Unable to fetch URL for notification\nid:${
notification.id
}\nsubject:${JSON.stringify(notification.subject, null, 2)}`
);
notifications = await Promise.all(
notifications.map(
async (
notification: Endpoints["GET /notifications"]["response"]["data"][0]
) => {
let notification_html_url;
try {
const notificationSubject = await octokit.request(
notification.subject.url
);
notification_html_url = notificationSubject?.data?.html_url;
// If there still isn't an html_url, it lives on another key
if (!notification_html_url) {
core.warning(
`Unable to find URL from linked api url for notification\nid :${
notification.id
}\nsubject:${JSON.stringify(
notification.subject,
null,
2
)}\subject.url request: ${JSON.stringify(notificationSubject.data, null, 2)}`
);
}
} catch (error) {
core.warning(
`Unable to fetch URL for notification\nid :${
notification.id
}\nsubject:${JSON.stringify(notification.subject, null, 2)}`
);
}
return {
...notification,
notification_html_url,
};
}
return {
...notification,
notification_html_url,
};
}
));
)
);

// Default return is DESC, we want ASC to show oldest first
if (inputs.sortOldestFirst) {
Expand Down Expand Up @@ -201,13 +215,25 @@ function displayFilters(inputs) {
return `
<filter-only-unread>: ${inputs.filterOnlyUnread}
<filter-only-participating>: ${inputs.filterOnlyParticipating}
<filter-include-reasons>: ${inputs.filterIncludeReasons.length ? inputs.filterIncludeReasons.join(", ") : "[]"}
<filter-exclude-reasons>: ${inputs.filterExcludeReasons.length ? inputs.filterExcludeReasons.join(", ") : "[]"}
<filter-include-reasons>: ${
inputs.filterIncludeReasons.length
? inputs.filterIncludeReasons.join(", ")
: "[]"
}
<filter-exclude-reasons>: ${
inputs.filterExcludeReasons.length
? inputs.filterExcludeReasons.join(", ")
: "[]"
}
<filter-include-repositories>: ${
inputs.filterIncludeRepositories.length ? inputs.filterIncludeRepositories.join(", ") : "[]"
inputs.filterIncludeRepositories.length
? inputs.filterIncludeRepositories.join(", ")
: "[]"
}
<filter-exclude-repositories>: ${
inputs.filterExcludeRepositories.length ? inputs.filterExcludeRepositories.join(", ") : "[]"
inputs.filterExcludeRepositories.length
? inputs.filterExcludeRepositories.join(", ")
: "[]"
}
`;
}
Expand Down

0 comments on commit 27f6b91

Please sign in to comment.