如何从 github 获取我最近的所有提交消息?

how do I get all my recent commit messages from github?

我想在网站上显示来自 github 的所有最近提交消息。这可能吗?

要获取用户的 public 事件,您应该使用 /users/:user/events 端点 (Events performed by a user):

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

这会给你一个 JSON 这样的回应:

[
  {
    "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": {...}
  },
  ...
]

现在,您只需过滤响应以仅包含 PushEvent 项。

既然您想在网站上显示这些事件,您可能想在 . Here is an example how to do it using gh.js 中对其进行编码——JavaScript/Node.js 的同构 GitHub API 包装器我写的:

// 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
});