-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/cbus-sea-lions-2015/DEVOLIO…
… into setup-tests
- Loading branch information
Showing
7 changed files
with
131 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
$(document).ready(function() { | ||
|
||
$('#ghsubmitbtn').on('click', function(e){ | ||
e.preventDefault(); | ||
var username = $('#ghusername').val(); | ||
getGitHubData(username); | ||
debugger; | ||
}); | ||
|
||
|
||
|
||
}); | ||
|
||
var getGitHubData = function(username){ | ||
var githubResults = {test: "test"} | ||
var user_uri = 'https://api.github.com/users/'+username; | ||
var events_uri = 'https://api.github.com/users/'+username+'/events'; | ||
|
||
var test; | ||
requestJSON(user_uri, function(json){ | ||
if(json.message == "Not Found" || username == '') { | ||
$('#ghapidata').html("<h2>No User Info Found</h2>"); | ||
} | ||
|
||
else { | ||
// else we have a user and we display their info | ||
githubResults.username = json.login; | ||
githubResults.fullName = json.name || githubResults.username; | ||
githubResults.aviurl = json.avatar_url; | ||
githubResults.profileurl = json.html_url; | ||
githubResults.location = json.location; | ||
githubResults.followersnum = json.followers; | ||
githubResults.followingnum = json.following; | ||
githubResults.reposnum = json.public_repos; | ||
|
||
var events; | ||
var pushEvents = 0; | ||
var pullEvents = 0; | ||
var gistEvents = 0; | ||
var forkEvents = 0; | ||
var mostRecentEventDate; | ||
var oldestEventDate; | ||
var eventDates = []; | ||
var languages = {}; | ||
var commits = 0; | ||
var additions = 0; | ||
var deletions = 0; | ||
var commitMessages = []; | ||
|
||
$.getJSON(events_uri, function(json){ | ||
console.log("Checking inside JSON") | ||
console.log(githubResults); | ||
events = json; | ||
for (var i = 0; i < events.length; i++) { | ||
if (events[i].type === "PushEvent") { | ||
var commitsCollection = events[i].payload.commits | ||
for (var j = 0; j < commitsCollection.length; j++){ | ||
commitMessages.push({message: commitsCollection[j].message, url: events[i].repo.url}); | ||
} | ||
pushEvents += 1; | ||
} | ||
else if (events[i].type === "PullRequestEvent") { | ||
var language = events[i].payload.pull_request.head.repo.language; | ||
if (language in languages) { | ||
languages[language]++; | ||
} | ||
else { | ||
languages[language] = 1; | ||
} | ||
pullEvents += 1; | ||
commits += events[i].payload.pull_request.commits; | ||
additions += events[i].payload.pull_request.additions; | ||
deletions += events[i].payload.pull_request.deletions; | ||
} | ||
else if (events[i].type === "GistEvent") { | ||
gistEvents++; | ||
} | ||
else if (events[i].type === "ForkEvent") { | ||
forkEvents++; | ||
} | ||
eventDates.push({date: events[i].created_at, eventType: events[i].type}); | ||
} | ||
mostRecentEventDate = events[0].created_at; | ||
oldestEventDate = events[events.length-1].created_at; | ||
|
||
githubResults.pushEvents = pushEvents; | ||
githubResults.pullEvents = pullEvents; | ||
githubResults.gistEvents = gistEvents; | ||
githubResults.forkEvents = forkEvents; | ||
githubResults.mostRecentEventDate = mostRecentEventDate; | ||
githubResults.oldestEventDate = oldestEventDate; | ||
githubResults.commits = commits; | ||
githubResults.lineAdditions = additions; | ||
githubResults.lineDeletions = deletions; | ||
githubResults.commitMessages = commitMessages; | ||
githubResults.languages = languages; | ||
console.log(githubResults); | ||
saveGithubResults(githubResults); | ||
}) | ||
} // end else statement | ||
}); // end requestJSON Ajax call | ||
}; // end click event handler | ||
|
||
function requestJSON(url, callback) { | ||
var otherTest = $.getJSON(url, { | ||
format: "json", | ||
}).error(function(error) { | ||
$('#ghapidata').html("<h2>"+ error +"</h2>"); | ||
}).done(function(data) { | ||
callback.call(null, data); | ||
// return data; | ||
}); | ||
debugger; | ||
return otherTest; | ||
} | ||
|
||
function saveGithubResults(githubResults) { | ||
console.log("inside save"); | ||
console.log(githubResults); | ||
$.ajax({ | ||
url: '/store_github', | ||
type: 'POST', | ||
data: githubResults | ||
}).done(function(data){ | ||
//DO SOMETHING! | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +0,0 @@ | ||
$(document).ready(function() { | ||
$(function(){ | ||
$('#ghsubmitbtn').on('click', function(e){ | ||
e.preventDefault(); | ||
$('#ghapidata').html('Loading...'); | ||
|
||
var username = $('#ghusername').val(); | ||
var user_uri = 'https://api.github.com/users/'+username; | ||
var repo_uri = 'https://api.github.com/users/'+username+'/repos'; | ||
|
||
requestJSON(user_uri, function(json) { | ||
console.log("My json") | ||
console.log(json) | ||
if(json.message == "Not Found" || username == '') { | ||
$('#ghapidata').html("<h2>No User Info Found</h2>"); | ||
} | ||
|
||
else { | ||
// else we have a user and we display their info | ||
var fullname = json.name; | ||
var username = json.login; | ||
var aviurl = json.avatar_url; | ||
var profileurl = json.html_url; | ||
var location = json.location; | ||
var followersnum = json.followers; | ||
var followingnum = json.following; | ||
var reposnum = json.public_repos; | ||
|
||
if(fullname == undefined) { fullname = username; } | ||
|
||
var outhtml = '<h2>'+fullname+' <span class="smallname">(@<a href="'+profileurl+'" target="_blank">'+username+'</a>)</span></h2>'; | ||
outhtml = outhtml + '<div class="ghcontent"><div class="avi"><a href="'+profileurl+'" target="_blank"><img src="'+aviurl+'" width="80" height="80" alt="'+username+'"></a></div>'; | ||
outhtml = outhtml + '<p>Followers: '+followersnum+' - Following: '+followingnum+'<br>Repos: '+reposnum+'</p></div>'; | ||
outhtml = outhtml + '<div class="repolist clearfix">'; | ||
|
||
var repositories; | ||
$.getJSON(repo_uri, function(json){ | ||
repositories = json; | ||
outputPageContent(); | ||
}); | ||
|
||
function outputPageContent() { | ||
if(repositories.length == 0) { outhtml = outhtml + '<p>No repos!</p></div>'; } | ||
else { | ||
outhtml = outhtml + '<p><strong>Repos List:</strong></p> <ul>'; | ||
$.each(repositories, function(index) { | ||
outhtml = outhtml + '<li><a href="'+repositories[index].html_url+'" target="_blank">'+repositories[index].name + '</a></li>'; | ||
}); | ||
outhtml = outhtml + '</ul></div>'; | ||
} | ||
$('#ghapidata').html(outhtml); | ||
} // end outputPageContent() | ||
} // end else statement | ||
}); // end requestJSON Ajax call | ||
}); // end click event handler | ||
|
||
function requestJSON(url, callback) { | ||
$.getJSON(url, { | ||
format: "json", | ||
}).error(function(error) { | ||
$('#ghapidata').html("<h2>"+ error +"</h2>"); | ||
}).done(function(data) { | ||
console.log("my xhr") | ||
console.log(data) | ||
callback.call(null, data); | ||
}); | ||
} | ||
}); | ||
}); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.