How do I get notifications for commits to a repository?

前端 未结 8 1683
孤城傲影
孤城傲影 2021-02-05 02:04

I\'d like to know what kind of commits are being made to the Lithium framework so I can update (or rollback) when there is something major.

I\'m already watching the re

8条回答
  •  青春惊慌失措
    2021-02-05 02:42

    You can leverage the GitHub Events API to perform such task and retrieve a JSON formatted response.

    • syntax: GET /repos/:user/:repo/events
    • example: https://api.github.com/repos/UnionOfRAD/lithium/events

    Note: In order to retrieve the commits, you'll have to filter out the events of type PushEvents.

    Below a quick sample

    $(function() {
        $.getJSON('https://api.github.com/repos/UnionOfRAD/lithium/events?callback=?', function(data) {
            var list = $('#push-events');
    
            $.each(data.data, function(key, val) {
                if (val.type == "PushEvent") {
                    $.each(val.payload.commits, function(key2, val2) {
                        list.append('
  • ' + val2.message + ' [' + val.actor.login + ' @ ' + val.created_at + ']
  • '); }); } }); if (list.children().size() == 0) { list.append('
  • No pushes in last ' + data.data.length + ' events.
  • '); } }); });
    
    

    提交回复
    热议问题