簡體   English   中英

使用GitHub Api和Ember檢索最新的Commit鏈接和消息

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

我用這個jsbin http://emberjs.jsbin.com/xeninaceze/edit?js,output轉載了我的案例

Github API允許我通過作者獲取事件列表:

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

我可以訪問過濾事件“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);
      }
    });
  });
};

問題是我想在msg旁邊流式傳輸他自己的url鏈接 html_url

我需要知道如何解決它 因為提交URL鏈接不在API鏈接中

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

但它們在以下API中

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

這使得訪問最新提交url link html_url變得更加復雜

這是我想要做的一個很好的例子

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

它在推送事件中流式傳輸帶有鏈接的最新提交消息

在我看來,所有相關數據已經存在:

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

您可以將作者URL作為actor訪問,將存儲庫作為repo 有了這個,很容易構建相關鏈接:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM