mirror of
https://github.com/techgaun/active-forks.git
synced 2024-11-13 07:41:10 +01:00
initial working stuff
This commit is contained in:
commit
108c755313
3 changed files with 117 additions and 0 deletions
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# active-forks
|
||||
|
||||
> Find the active github forks of a project
|
||||
|
||||
This project allows you to find the most active forks of a repository.
|
35
index.html
Normal file
35
index.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Find Active Github Forks</title>
|
||||
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-offset-2 col-8">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading text-center">
|
||||
<h3>Find Active Github Forks</h3>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
<div class="input-group">
|
||||
<input id="repo" class="form-control" type="text" placeholder="techgaun/github-dorks">
|
||||
<span class="input-group-btn">
|
||||
<button onClick="fetchData()" type="button" class="btn btn-primary">Find</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div id='data-body' class="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-offset-2 col-md-8">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript" src="js/main.js"></script>
|
||||
</body>
|
77
js/main.js
Normal file
77
js/main.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
function fetchData() {
|
||||
const repo = document.getElementById('repo').value
|
||||
const re = /[-_\w]+\/[-_.\w]+/
|
||||
|
||||
if (re.test(repo)) {
|
||||
fetchAndShow(repo)
|
||||
} else {
|
||||
showError('Invalid github repo given. Format is <username>/<repo>')
|
||||
}
|
||||
}
|
||||
|
||||
function fetchAndShow(repo) {
|
||||
fetch(`https://api.github.com/repos/${repo}/forks?sort=stargazers`)
|
||||
.then(function(response) {
|
||||
response.json()
|
||||
.then(function(data) {
|
||||
showData(data)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function showError(msg) {
|
||||
document.getElementById('data-body').innerHTML = `<div class="alert alert-danger">${msg}</div>`
|
||||
}
|
||||
|
||||
function showData(data) {
|
||||
if (!Array.isArray(data)) {
|
||||
showError('Github Repo does not exist')
|
||||
return
|
||||
}
|
||||
if (data.length === 0) {
|
||||
document.getElementById('data-body').innerHTML = `<div class="alert alert-info">No forks exist</div>`
|
||||
return
|
||||
}
|
||||
const thead = '<thead><tr><th>Repository</th><th>Stargazers</th><th>Forks</th><th>Last Update</th></tr></thead>'
|
||||
const html = []
|
||||
for (const fork of data) {
|
||||
const item = `
|
||||
<tr>
|
||||
<td><a href="${fork.html_url}">${fork.full_name}</a></td>
|
||||
<td>${fork.stargazers_count}</td>
|
||||
<td>${fork.forks_count}</td>
|
||||
<td>${timeSince(fork.updated_at)} ago</td>
|
||||
</tr>
|
||||
`
|
||||
html.push(item)
|
||||
}
|
||||
document.getElementById('data-body').innerHTML = `<table class="table table-striped">${thead}<tbody>${html.join()}</tbody></table>`
|
||||
}
|
||||
|
||||
function timeSince(date_str) {
|
||||
const date = new Date(date_str)
|
||||
const seconds = Math.floor((new Date() - date) / 1000);
|
||||
|
||||
let interval = Math.floor(seconds / 31536000);
|
||||
|
||||
if (interval > 1) {
|
||||
return interval + " years";
|
||||
}
|
||||
interval = Math.floor(seconds / 2592000);
|
||||
if (interval > 1) {
|
||||
return interval + " months";
|
||||
}
|
||||
interval = Math.floor(seconds / 86400);
|
||||
if (interval > 1) {
|
||||
return interval + " days";
|
||||
}
|
||||
interval = Math.floor(seconds / 3600);
|
||||
if (interval > 1) {
|
||||
return interval + " hours";
|
||||
}
|
||||
interval = Math.floor(seconds / 60);
|
||||
if (interval > 1) {
|
||||
return interval + " minutes";
|
||||
}
|
||||
return Math.floor(seconds) + " seconds";
|
||||
}
|
Loading…
Reference in a new issue