Skip to content

Commit

Permalink
Merge pull request techinpark#11 from wooogi123/master
Browse files Browse the repository at this point in the history
Refactor graphql query
  • Loading branch information
maxam2017 committed May 10, 2020
2 parents 620b846 + f47aac3 commit f364f89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 36 deletions.
28 changes: 8 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import { Octokit } from '@octokit/rest';

import githubQuery from './githubQuery';
import generateBarChart from './generateBarChart';
import {
userInfoQuery,
createContributedRepoQuery,
createOwnedRepoQuery,
createCommittedDateQuery,
} from './queries';
import { userInfoQuery, createContributedRepoQuery, createCommittedDateQuery } from './queries';
/**
* get environment variable
*/
Expand All @@ -32,21 +27,14 @@ interface IRepo {
* Second, get contributed repos
*/
const contributedRepoQuery = createContributedRepoQuery(username);
const ownedRepoQuery = createOwnedRepoQuery(username);

let repoResponse = await githubQuery(contributedRepoQuery)
const repoResponse = await githubQuery(contributedRepoQuery)
.catch(error => console.error(`Unable to get the contributed repo\n${error}`));
const repos: IRepo[] = repoResponse?.data?.user?.repositoriesContributedTo?.nodes.map(repoInfo => ({
name: repoInfo?.name,
owner: repoInfo?.owner?.login,
}));

repoResponse = await githubQuery(ownedRepoQuery)
.catch(error => console.error(`Unable to get the owned repo\n${error}`));
repos.push(...repoResponse?.data?.user?.repositories?.nodes.map(repoInfo => ({
name: repoInfo?.name,
owner: repoInfo?.owner?.login,
})));
const repos: IRepo[] = repoResponse?.data?.user?.repositoriesContributedTo?.nodes
.filter(repoInfo => (!repoInfo?.isFork))
.map(repoInfo => ({
name: repoInfo?.name,
owner: repoInfo?.owner?.login,
}));

/**
* Third, get commit time and parse into commit-time/hour diagram
Expand Down
18 changes: 2 additions & 16 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export const userInfoQuery = `
export const createContributedRepoQuery = (username: string) => `
query {
user(login: "${username}") {
repositoriesContributedTo(last: 100) {
repositoriesContributedTo(last: 100, includeUserRepositories: true) {
nodes {
isFork
name
owner {
login
Expand All @@ -22,21 +23,6 @@ export const createContributedRepoQuery = (username: string) => `
}
`;

export const createOwnedRepoQuery = (username: string) => `
query {
user(login: "${username}") {
repositories(last: 100, ownerAffiliations: OWNER, isFork: false) {
nodes {
name
owner {
login
}
}
}
}
}
`;

export const createCommittedDateQuery = (id: string, name: string, owner: string) => `
query {
repository(owner: "${owner}", name: "${name}") {
Expand Down

0 comments on commit f364f89

Please sign in to comment.