1

I would like to display all of my recent commit messages from github on a website. Is this possible?

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
Connor Leech
  • 18,052
  • 30
  • 105
  • 150

1 Answers1

3

To get the public events of a user, you should use the /users/:user/events endpoint (Events performed by a user):

curl https://api.github.com/users/IonicaBizau/events

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 . 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
  • How about listing all commit messages for a repository ? – Amr Lotfy Sep 13 '21 at 09:13