So I need to create an application to interact with Github
What I want…
- The Current Users Available Repos-Save the User ID
- Ability to access a specific Repo-Save the Repo ID
- Ability to show work done on that repo
Following the API, here are the basics
GET https://api.github.com/users/formula1/repos with a header specifying version 3
Click to get Current Repos
Click for something pretty
Click to hide
Now this is good for just me, but what about anyone who want to clock in? I need to authenticate… I’ll get to this later
Now, to be able to choose a repo and see the work Click Here
Now the instance work isn’t nearly as important since I can’t quantify that quite same as I can quantify times. However, that is possible as well.
Heres the Source code. Simple but straight forward.
jQuery(function(){ jQuery(".githubrepo").click(function(e){ e.preventDefault();
jQuery.ajax({
url: "https://api.github.com/users/formula1/repos",
type: "GET",
beforeSend: function(xhr){
xhr.setRequestHeader('Accept','application/vnd.github.v3.full');
},
}).done(function(content){
jQuery("#github-repos-example").text(JSON.stringify(content));
});
});
jQuery(".githubpretty").click(function(e){
e.preventDefault();
jQuery.ajax({
url: "https://api.github.com/users/formula1/repos",
type: "GET",
beforeSend: function(xhr){
xhr.setRequestHeader('Accept','application/vnd.github.v3.full');
},
}).done(function(content){
for(var i=0;i<content.length;i++){
jQuery("#github-repos-example").append("<span style='display:inline-block; padding:10px; background:#000; color: #FFF;margin:1px;'>"+content[i].full_name+"</span>");
}
});
});
jQuery(".githubhide").click(function(e){
e.preventDefault();
jQuery("#github-repos-example").text("");
});
jQuery(".githubproj").click(function(e){
e.preventDefault();
jQuery.ajax({
url: "https://api.github.com/users/formula1/repos",
type: "GET",
beforeSend: function(xhr){
xhr.setRequestHeader('Accept','application/vnd.github.v3.full');
},
}).done(function(content){
jQuery("#github-repos-example2").text("");
for(var i=0;i<content.length;i++){
jQuery("#github-repos-example2").append("<a href='"+content[i].url+"/commits' style='display:inline-block; padding:10px; background:#000; color: #FFF;margin:1px;'>"+content[i].full_name+"</a>"
);
}
jQuery("#github-repos-example2>a").click(function(e){
e.preventDefault();
jQuery.ajax({
url: jQuery(this).attr("href"),
type: "GET",
beforeSend: function(xhr){
xhr.setRequestHeader('Accept','application/vnd.github.v3.full');
},
}).done(function(content){
jQuery("#github-repos-example2").text("");
for(var i=0;i<content.length;i++){
jQuery("#github-repos-example2").append("<div style='border:1px solid #000;'><span>Date: "+content[i].commit.committer.date+"</span><br/><span>Name: "+content[i].commit.committer.name+"</span><br/><span>Message: "+content[i].commit.message+"</span></div>"
)
}
});
});
});
});
});