From f87f33b5915f20aef429f42061045ae5ccf5120c Mon Sep 17 00:00:00 2001 From: Nicholas Zuber Date: Sat, 4 Feb 2023 19:48:44 -0500 Subject: [PATCH] dont break on ci alerts --- package.json | 2 +- src/providers/Notifications.js | 45 +++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index d4a1ff8..e4153ca 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "private": true, "engines": { - "node": "12.x" + "node": "16.x" }, "dependencies": { "@emotion/core": "^10.0.10", diff --git a/src/providers/Notifications.js b/src/providers/Notifications.js index a5af7ae..6b2c002 100644 --- a/src/providers/Notifications.js +++ b/src/providers/Notifications.js @@ -8,10 +8,14 @@ const BASE_GITHUB_API_URL = 'https://api.github.com'; const PER_PAGE = 50; function transformUrlFromResponse(url) { - return url - .replace('api.github.com', 'github.com') - .replace('/repos/', '/') - .replace('/pulls/', '/pull/'); + try { + return url + .replace('api.github.com', 'github.com') + .replace('/repos/', '/') + .replace('/pulls/', '/pull/'); + } catch (err) { + return url || "" + } } function processHeadersAndBodyJson(response) { @@ -171,10 +175,7 @@ class NotificationsProvider extends React.Component { // // 1 month is pretty arbitrary, we can raise this if we want. const since = - moment() - .subtract(1, 'month') - .toISOString() - .split('.')[0] + 'Z'; + moment().subtract(1, 'month').toISOString().split('.')[0] + 'Z'; const headers = { Authorization: `token ${this.props.token}`, @@ -209,7 +210,33 @@ class NotificationsProvider extends React.Component { if (links && links.next && links.next.page) { nextPage = links.next.page; } - return this.processNotificationsChunk(nextPage, json); + + const chunk = json.filter(notification => { + // 2/4/2023 + // New reasons have joined the party. + // Restrict some reasons to maintain backwards compat. + const allowedReasons = [ + "assign", + "author", + "comment", + // "ci_activity", + // "invitation", + // "manual", + "mention", + "review_requested", + // "security_alert", + "state_change", + "subscribed", + "team_mention" + ] + if (allowedReasons.includes(notification.reason)) { + return true + } else { + return false + } + }) + + return this.processNotificationsChunk(nextPage, chunk); }); };