From 5ce84429562953ce57aaef7f31f8987bd383f61f Mon Sep 17 00:00:00 2001 From: bendtherules Date: Tue, 12 Jun 2018 13:31:50 +0530 Subject: [PATCH] Export main 2 functions from gh + Use in index Also reformatted gh --- src/gh.ts | 75 +++++++++++++++++++++++++++------------------------- src/index.ts | 5 +++- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/gh.ts b/src/gh.ts index 3d283e0..8703b31 100644 --- a/src/gh.ts +++ b/src/gh.ts @@ -73,7 +73,7 @@ interface ResponseWithMetaLink { interface ResponseWithDataArrayAndMeta extends ResponseWithDataArray, - ResponseWithMetaLink {} + ResponseWithMetaLink { } interface ResponseFromGetUserRepo extends ResponseWithMetaLink { data: RepoFromGetUserRepo[]; @@ -163,7 +163,7 @@ interface RepoNameWithParentRepo { interface RepoNameWithBranchesAndParent extends RepoNameWithBranches, - RepoNameWithParentRepo {} + RepoNameWithParentRepo { } const username = 'rousan'; @@ -204,13 +204,13 @@ async function fetchRepoNameWithBranches( const branchesResponse: ResponseWithDataArray< BranchFromGetBranches - > = await paginate((tmpFirstParam: Octokit.ReposGetBranchesParams): Promise< - ResponseFromGetBranches - > => { - return (octokit.repos.getBranches(tmpFirstParam) as any) as Promise< + > = await paginate((tmpFirstParam: Octokit.ReposGetBranchesParams): Promise< ResponseFromGetBranches - >; - }, params); + > => { + return (octokit.repos.getBranches(tmpFirstParam) as any) as Promise< + ResponseFromGetBranches + >; + }, params); return { repoName, @@ -319,31 +319,31 @@ async function fetchUserIsNotContributor( const responseFromGetContributors: ResponseWithDataArray< OwnerFromGetContributors - > = await paginate( - async ( - tmpFirstParam: Octokit.ReposGetContributorsParams - ): Promise> => { - // Modify getContributors to return empty contributor data array instead of undefined for empty repos - const response = await ((octokit.repos.getContributors( - tmpFirstParam - ) as any) as Promise); + > = await paginate( + async ( + tmpFirstParam: Octokit.ReposGetContributorsParams + ): Promise> => { + // Modify getContributors to return empty contributor data array instead of undefined for empty repos + const response = await ((octokit.repos.getContributors( + tmpFirstParam + ) as any) as Promise); - let dataNormalized = response.data; - if (dataNormalized === undefined) { - dataNormalized = []; - } + let dataNormalized = response.data; + if (dataNormalized === undefined) { + dataNormalized = []; + } - const responseNormalized: ResponseWithDataArrayAndMeta< - OwnerFromGetContributors - > = { - data: dataNormalized, - meta: response.meta, - }; + const responseNormalized: ResponseWithDataArrayAndMeta< + OwnerFromGetContributors + > = { + data: dataNormalized, + meta: response.meta, + }; - return responseNormalized; - }, - params - ); + return responseNormalized; + }, + params + ); const contributors = responseFromGetContributors.data; @@ -358,7 +358,7 @@ async function fetchUserIsNotContributor( }; } -async function fetchUnusedForkedRepos() { +export async function fetchUnusedForkedRepos() { const params: Octokit.ReposGetForUserParams = { username, }; @@ -369,7 +369,7 @@ async function fetchUnusedForkedRepos() { ): Promise => { return (octokit.repos.getForUser(tmpFirstParam) as any) as Promise< ResponseFromGetUserRepo - >; + >; }, params ); @@ -514,10 +514,13 @@ async function fetchUnusedForkedRepos() { return unusedRepoNames; } -fetchUnusedForkedRepos().then(unusedRepoNames => { - // tslint:disable-next-line:no-console - console.log(unusedRepoNames); -}); + +export function runMain() { + fetchUnusedForkedRepos().then(unusedRepoNames => { + // tslint:disable-next-line:no-console + console.log(unusedRepoNames); + }); +} // Next steps // diff --git a/src/index.ts b/src/index.ts index 116ff33..b9ed9bb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,10 @@ import { Greeter } from './greeter'; +// tslint:disable-next-line:ordered-imports +import { fetchUnusedForkedRepos, runMain } from './gh'; export * from './greeter'; // tslint:disable-next-line:only-arrow-functions -(function(currentWindow: Window) { +(function (currentWindow: Window) { // execute when load index.js // tslint:disable-next-line:no-console @@ -11,6 +13,7 @@ export * from './greeter'; // assign Greeter to global const myWindow = currentWindow as any; myWindow.Greeter = Greeter; + myWindow.runMain = runMain; // we can use Greeter , execute following in console // var greet = new Greeter('myName'); // greet.greet();