-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
123 additions
and
211 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Octokit } from "@octokit/rest"; | ||
import { GitHubNotification, GitHubNotifications } from "../github-types"; | ||
import { getGitHubAccessToken } from "../getters/get-github-access-token"; | ||
import { handleRateLimit } from "./handle-rate-limit"; | ||
import { RequestError } from "@octokit/request-error"; | ||
export const organizationImageCache = new Map<string, Blob | null>(); // this should be declared in image related script | ||
|
||
// Fetches notifications from GitHub, must be authenticated | ||
export async function fetchNotifications(): Promise<GitHubNotifications | null> { | ||
const providerToken = await getGitHubAccessToken(); | ||
const octokit = new Octokit({ auth: providerToken }); | ||
|
||
try { | ||
const response = ((await octokit.request("GET /notifications")).data) as GitHubNotifications; | ||
console.log("unfiltered", response); | ||
const filtered = filterNotifications(response); | ||
console.log("filtered", filtered); | ||
return filtered; | ||
} catch(error) { | ||
if (!!error && typeof error === "object" && "status" in error && error.status === 403) { | ||
await handleRateLimit(providerToken ? octokit : undefined, error as RequestError); | ||
} | ||
console.warn("You have been logged out. Please login again.", error); | ||
} | ||
return null; | ||
} | ||
|
||
function filterNotifications(notifications: GitHubNotification[]): GitHubNotifications { | ||
return notifications.filter(notification => { | ||
if (notification.reason === 'ci_activity') { | ||
return false; | ||
} | ||
|
||
const repoName = notification.repository.full_name.split('/')[0]; | ||
if (repoName !== 'ubiquity' && repoName !== 'ubiquity-os' && repoName !== 'ubiquity-os-marketplace') { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.