-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
1347966
commit cf237e9
Showing
5 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
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 {Request, Response} from "express"; | ||
import getRepoPages from "../githubapi/getRepoPages"; | ||
import {internalErrorHandler} from "../types/errorHandler"; | ||
|
||
export const getNumRepoPages = (req: Request, res: Response) => { | ||
getRepoPages(req.headers.token as string) | ||
.then(lastPageNumber => { | ||
res.json({ | ||
lastPageNumber | ||
}); | ||
}) | ||
.catch(internalErrorHandler(req, res)); | ||
}; |
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,34 @@ | ||
import axios from "axios"; | ||
import {GithubRepo, isGithubRepo} from "../types/github"; | ||
import {GITHUB_BASE_URL, createGithubHeader} from "./util"; | ||
|
||
export default (token: string): Promise<GithubRepo[]> => | ||
new Promise<GithubRepo[]>((resolve, reject) => { | ||
//we want to get the total number of pages of repos | ||
//so that in the frontend we can click the page buttons and have the correct number of pages | ||
let lastPageNumber = 1; | ||
axios | ||
.get(`${GITHUB_BASE_URL}/user/repos`, createGithubHeader(token)) //get the first page of repos | ||
.then(resp => { | ||
//check resp.headers.link for rel="last" | ||
//once we have the link, extract the page number using a regex | ||
//this will be the number of total pages of repos | ||
|
||
//get the link header | ||
const linkHeader = resp.headers.link; | ||
//get the last page number | ||
if (linkHeader != null) { | ||
//if there is a link header, extract the last page number | ||
const lastPageRegex = /<(.*)>; rel="last"/; | ||
const lastPageMatch = linkHeader.match(lastPageRegex); | ||
if (lastPageMatch != null) { | ||
//if there is a match, extract the last page number | ||
lastPageNumber = parseInt( | ||
lastPageMatch[1].split("=")[1] | ||
); | ||
} | ||
} | ||
console.dir(lastPageNumber); | ||
}) | ||
.catch(reject); | ||
}); |
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