Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Github API allows me to get the list of events by author:

API Link - 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.

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. html_url

I need to know how i can tackle it? since the commit url links are not in the in the API Link

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

But they are in the following api

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

This makes bit more complicate to access to the latest commits url link html_url

This is a good example of what i am trying to do

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

It streams in the push events the latest commits message with links

like image 500
Koala7 Avatar asked Jun 12 '26 01:06

Koala7


1 Answers

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. 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

like image 159
Rudolf Avatar answered Jun 13 '26 15:06

Rudolf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!