Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
#567 Typescript Integration (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentrohde authored Oct 19, 2021
1 parent 48d9e23 commit 2bcdbf0
Show file tree
Hide file tree
Showing 34 changed files with 1,727 additions and 1,080 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Thumbs.db
public/js/main-compiled.js
public/js/main-compiled.js.map
build/
api/build
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore artifacts:
api/build
14 changes: 14 additions & 0 deletions api/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
},
};
18 changes: 0 additions & 18 deletions api/controllers/pr/errors.js

This file was deleted.

17 changes: 17 additions & 0 deletions api/controllers/pr/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const statusCodes: {
[key: string]: number;
} = {
notUser: 400,
};

const errorDescriptions: {
[key: string]: string;
} = {
notUser: 'Username must belong to a user account.',
};

export const getStatusCode = (error: string) => statusCodes[error] || 400;

export const getErrorDescription = (error: string) =>
errorDescriptions[error] ||
"Couldn't find any data or we hit an error, err try again?";
29 changes: 0 additions & 29 deletions api/controllers/pr/findPrs/github/getNextPage.js

This file was deleted.

35 changes: 35 additions & 0 deletions api/controllers/pr/findPrs/github/getNextPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Octokit } from '@octokit/rest';
import { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods/dist-types/generated/parameters-and-response-types';
import getPageLinks from './getPageLinks';
import hasNextPage from './hasNextPage';

const getNextPage = async (
response: RestEndpointMethodTypes['search']['issuesAndPullRequests']['response'],
github: Octokit,
pullRequestData: RestEndpointMethodTypes['search']['issuesAndPullRequests']['response']['data']['items']
) => {
try {
const baseUrl = process.env.GITHUB_API_BASE_URL
? process.env.GITHUB_API_BASE_URL
: 'https://api.github.com';
const nextPageLink = await getPageLinks(response).next.replace(baseUrl, '');

const githubResults = (await github.request(
'GET ' + nextPageLink
)) as RestEndpointMethodTypes['search']['issuesAndPullRequests']['response'];
const newPullRequestData = pullRequestData.concat(githubResults.data.items);
if (hasNextPage(githubResults)) {
return await getNextPage(githubResults, github, newPullRequestData);
}

if (process.env.NODE_ENV !== 'production') {
console.log(`Found ${pullRequestData.length} pull requests.`);
}
return newPullRequestData;
} catch (error: unknown) {
console.log('Error: ' + error);
return error;
}
};

export default getNextPage;
17 changes: 0 additions & 17 deletions api/controllers/pr/findPrs/github/getPageLinks.js

This file was deleted.

32 changes: 32 additions & 0 deletions api/controllers/pr/findPrs/github/getPageLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export interface GetPageLinksLink {
link?: string;
headers?: {
link?: string;
};
}

interface HasNextPage {
next?: string;
}

const getPageLinks = (link: GetPageLinksLink): HasNextPage => {
const extractedLink: string = link.link || link.headers.link || '';

const links: {
[key: string]: string[];
} = {};

// link format:
// '<https://api.github.com/users/aseemk/followers?page=2>; rel="next", <https://api.github.com/users/aseemk/followers?page=2>; rel="last"'
extractedLink.replace(
/<([^>]*)>;\s*rel="([\w]*)"/g,
// @ts-ignore
(m: string, uri: string[], type: string) => {
links[type] = uri;
}
);

return links;
};

export default getPageLinks;
9 changes: 0 additions & 9 deletions api/controllers/pr/findPrs/github/hasNextPage.js

This file was deleted.

7 changes: 7 additions & 0 deletions api/controllers/pr/findPrs/github/hasNextPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import getPageLinks, { GetPageLinksLink } from './getPageLinks';

const hasNextPage = (link: GetPageLinksLink) => {
return getPageLinks(link).next;
};

export default hasNextPage;
177 changes: 0 additions & 177 deletions api/controllers/pr/findPrs/github/index.js

This file was deleted.

Loading

0 comments on commit 2bcdbf0

Please sign in to comment.