简体   繁体   English

使用GitHub Api和Ember检索最新的Commit链接和消息

[英]Retrieve latest Commit links and message with GitHub Api and Ember

I have reproduced my case with this jsbin http://emberjs.jsbin.com/xeninaceze/edit?js,output 我用这个jsbin http://emberjs.jsbin.com/xeninaceze/edit?js,output转载了我的案例

Github API allows me to get the list of events by author: Github API允许我通过作者获取事件列表:

API Link - api.github.com/users/:user/events API链接 - api.github.com/users/:user/events

I can access to the commit message filtering the events “PushEvent”, and it s perfectly fine because i cam stream my latest commit message. 我可以访问过滤事件“PushEvent”的提交消息,它完全正常,因为我可以通过我的最新提交消息流式传输。

var gitactivitiesPromise = function() {
  return new Ember.RSVP.Promise(function (resolve) {
    Ember.$.ajax(eventsAct, {
      success: function(events) {
        var result = [];
        events.filter(function(event) {
          return event.type == 'PushEvent';
        }).forEach(function(item){
          item.payload.commits.map(function(commit){
            result.push(store.createRecord('commit', {
              message: commit.message,
            }));
          });


        });
        resolve(result);
      },  
      error: function(reason) {
        reject(reason);
      }
    });
  });
};

The problem is that i want to stream beside the msg also his own url link . 问题是我想在msg旁边流式传输他自己的url链接 html_url

I need to know how i can tackle it ? 我需要知道如何解决它 since the commit url links are not in the in the API Link 因为提交URL链接不在API链接中

  • api.github.com/users/:user/events api.github.com/users/:user/events

But they are in the following api 但它们在以下API中

  • api.github.com/repos/:user/repo/commits/branch api.github.com/repos/:user/repo/commits/branch

This makes bit more complicate to access to the latest commits url link html_url 这使得访问最新提交url link html_url变得更加复杂

This is a good example of what i am trying to do 这是我想要做的一个很好的例子

http://zmoazeni.github.io/gitspective/# http://zmoazeni.github.io/gitspective/#

It streams in the push events the latest commits message with links 它在推送事件中流式传输带有链接的最新提交消息

It seems to me that all the relevant data is already there: 在我看来,所有相关数据已经存在:

{
    "id": "3414229549",
    "type": "PushEvent",
    "actor": {
      ...
      "login": "paulirish"
    },
    "repo": {
      ...
      "name": "GoogleChrome/devtools-docs"
    },
    "payload": {
      ...
      "commits": [
        {
          ...
          "message": "fish shell. really liking it.",
          "sha": "1f9740c9dd07f166cb4b92ad053b17dbc014145b"
        },
    ...

You can access the author URL as actor and the repository as repo . 您可以将作者URL作为actor访问,将存储库作为repo With this it's easy to construct the relevant links: 有了这个,很容易构建相关链接:

...
.forEach(function(item) {
  var repoUrl = 'https://github.com/' + item.repo.name;
  var authorUrl = 'https://github.com/' + item.actor.login;

  item.payload.commits.map(function(commit) {
    result.push(store.createRecord('commit', {
      authorUrl: authorUrl,
      repositoryUrl: repoUrl,
      commitUrl: repoUrl + '/commit/' + commit.sha,
      message: commit.message
    }));
  });
})
...

Updated JSBin: http://emberjs.jsbin.com/feyedujulu/1/edit?js,output 更新了JSBin: http ://emberjs.jsbin.com/feyedujulu/1/edit?js,output

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM