mirror of
https://github.com/techgaun/active-forks.git
synced 2025-01-03 11:22:17 +01:00
add initial graphql stuff
This commit is contained in:
parent
ccea7c3df7
commit
d9e3224a7f
1 changed files with 68 additions and 6 deletions
74
js/main.js
74
js/main.js
|
@ -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]+/;
|
||||
|
@ -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', '');
|
||||
const [owner, repo_name] = repo
|
||||
.replace('https://github.com/', '')
|
||||
.replace('http://github.com/', '')
|
||||
.replace('.git', '')
|
||||
.split('/');
|
||||
|
||||
fetch(
|
||||
`https://api.github.com/repos/${repo}/forks?sort=stargazers&per_page=100`
|
||||
)
|
||||
fetch(`https://api.github.com/graphql`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: schemaToQuery,
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) throw Error(response.statusText);
|
||||
return response.json();
|
||||
|
|
Loading…
Reference in a new issue