Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 69 additions & 7 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,64 @@ document.getElementById('form').addEventListener('submit', e => {
fetchData();
});

function getGraphQLSchema(owner, repo_name) {
const query = `
{
repository(owner: "${owner}", name: "${repo_name}") {
id
name
defaultBranchRef {
id
name
}
diskUsage
owner {
login
}
forkCount
issues(states: [OPEN]) {
totalCount
}
watchers {
totalCount
}
stargazers {
totalCount
}
pushedAt
forks(first: 100, orderBy: {field: STARGAZERS, direction: DESC}) {
edges {
node {
id
name
diskUsage
defaultBranchRef {
id
name
}
owner {
login
}
forkCount
issues(states: [OPEN]) {
totalCount
}
watchers {
totalCount
}
stargazers {
totalCount
}
pushedAt
}
}
}
}
}
`;
return JSON.stringify({ query });
}

function fetchData() {
const repo = document.getElementById('q').value;
const re = /[-_\w]+\/[-_.\w]+/;
Expand Down Expand Up @@ -97,13 +155,17 @@ function initDT() {
}

function fetchAndShow(repo) {
repo = repo.replace('https://github.com/', '');
repo = repo.replace('http://github.com/', '');
repo = repo.replace('.git', '');

fetch(
`https://api.github.com/repos/${repo}/forks?sort=stargazers&per_page=100`
)
const [owner, repo_name] = repo
.replace('https://github.com/', '')
.replace('http://github.com/', '')
.replace('.git', '')
.split('/');

fetch(`https://api.github.com/graphql`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: getGraphQLSchema(owner, repo_name),
})
.then(response => {
if (!response.ok) throw Error(response.statusText);
return response.json();
Expand Down