Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(filter): Filter notifications based on owner/repository (#192)
Co-authored-by: Laxman <notlmn@outlook.com>
- Loading branch information
Showing
20 changed files
with
602 additions
and
49 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,47 @@ | ||
import {parseLinkHeader, parseFullName} from '../util'; | ||
import repositoriesStorage from '../repositories-storage'; | ||
import {makeApiRequest} from './api'; | ||
|
||
export async function getRepositories( | ||
repos = [], | ||
params = { | ||
page: '1', | ||
per_page: '100' // eslint-disable-line camelcase | ||
} | ||
) { | ||
const {headers, json} = await makeApiRequest('/user/subscriptions', params); | ||
repos = [...repos, ...json]; | ||
|
||
const {next} = parseLinkHeader(headers.get('Link')); | ||
if (!next) { | ||
return repos; | ||
} | ||
|
||
const {searchParams} = new URL(next); | ||
return getRepositories(repos, { | ||
page: searchParams.get('page'), | ||
per_page: searchParams.get('per_page') // eslint-disable-line camelcase | ||
}); | ||
} | ||
|
||
export async function listRepositories(update) { | ||
const stored = await repositoriesStorage.getAll(); | ||
|
||
let tree = stored; | ||
if (update || !tree || Object.keys(tree).length <= 0) { | ||
const fetched = await getRepositories(); | ||
/* eslint-disable camelcase */ | ||
tree = fetched.reduce((tree, {full_name}) => { | ||
const {owner, repository} = parseFullName(full_name); | ||
return Object.assign({}, tree, { | ||
[owner]: Object.assign(tree[owner] || {}, { | ||
[repository]: Boolean(stored && stored[owner] && stored[owner][repository]) | ||
}) | ||
}); | ||
}, {}); | ||
/* eslint-enable camelcase */ | ||
await repositoriesStorage.set(tree); | ||
} | ||
|
||
return tree; | ||
} |
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,13 @@ | ||
import {makeApiRequest} from './api'; | ||
import localStore from './local-store'; | ||
|
||
export async function getUser(update) { | ||
let user = await localStore.get('user'); | ||
if (update || !user) { | ||
const {json} = await makeApiRequest('/user'); | ||
await localStore.set('user', json); | ||
user = json; | ||
} | ||
|
||
return user; | ||
} |
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.