I would like to display all of my recent commit messages from github on a website. Is this possible?
Asked
Active
Viewed 995 times
1

Ionică Bizău
- 109,027
- 88
- 289
- 474

Connor Leech
- 18,052
- 30
- 105
- 150
-
This does not seem to possible currently, q.v. [this SO post](http://stackoverflow.com/questions/18122628/how-to-search-for-a-commit-message-in-github). – Tim Biegeleisen Nov 18 '15 at 04:48
-
Do you want to get your recent commits across public repos? – Ionică Bizău Nov 18 '15 at 04:52
-
I'm sure it's possible, because sites like Slack and Gitter allow you to do it. – Sam Nov 18 '15 at 05:00
-
1@TimBiegeleisen It *is* possible! :-) See my answer. – Ionică Bizău Nov 18 '15 at 05:10
-
Nice detective work :-) – Tim Biegeleisen Nov 18 '15 at 05:10
-
@TimBiegeleisen Not detective at all. I pretty familiar with the GitHub API. Check out my [`cli-github` app](https://github.com/IonicaBizau/cli-github). :-) – Ionică Bizău Nov 18 '15 at 05:16
1 Answers
3
To get the public events of a user, you should use the /users/:user/events
endpoint (Events performed by a user):
This will give you back a JSON response like this:
[
{
"type": "IssueCommentEvent",
...
}
{
"id": "3349705833",
"type": "PushEvent",
"actor": {...},
"repo": {...},
"payload": {
"push_id": 868451162,
"size": 13,
"distinct_size": 1,
"ref": "refs/heads/master",
"head": "0ea1...12162",
"before": "548...d4bd",
"commits": [
{
"sha": "539...0892e",
"author": {...},
"message": "Some message",
"distinct": false,
"url": "https://api.github.com/repos/owner/repo/commits/53.....92e"
},
...
]
},
"public": true,
"created_at": "2015-11-17T11:05:04Z",
"org": {...}
},
...
]
Now, you only need to filter the response to include only the PushEvent
items.
Since you want to display these events on a website, probably you want to code it in javascript. Here is an example how to do it using gh.js
–an isomorphic GitHub API wrapper for JavaScript/Node.js written by me:
// Include gh.js
const GitHub = require("gh.js");
// Create the GitHub instance
var gh = new GitHub();
// Get my public events
gh.get("users/IonicaBizau/events", (err, res) => {
if (err) { return console.error(err); }
// Filter by PushEvent type
var pushEvents = res.filter(c => {
return c.type === "PushEvent";
});
// Show the date and the repo name
console.log(pushEvents.map(c => {
return "Pushed at " + c.created_at + " in " + c.repo.name;
}).join("\n"));
// => Pushed at 2015-11-17T11:05:04Z in jillix/jQuery-json-editor
// => Pushed at 2015-11-16T18:56:05Z in IonicaBizau/html-css-examples
// => Pushed at 2015-11-16T16:36:37Z in jillix/node-cb-buffer
// => Pushed at 2015-11-16T16:35:57Z in jillix/node-cb-buffer
// => Pushed at 2015-11-16T16:34:58Z in jillix/node-cb-buffer
// => Pushed at 2015-11-16T13:39:33Z in IonicaBizau/ghosty
});

Ionică Bizău
- 109,027
- 88
- 289
- 474
-
Got it! So for my github info it would be https://api.github.com/users/cleechtech/events. the commit messages are nested deep which is kind of a pain but they are there! Thank you – Connor Leech Dec 27 '15 at 21:19
-