Template:KumaGithubChanges

  • Revision slug: Template:KumaGithubChanges
  • Revision title: Template:KumaGithubChanges
  • Revision id: 353797
  • Created:
  • Creator: lmorchard
  • Is current revision? No
  • Comment

Revision Content

<% var MAX_RECENT_PUSHES = 7; var GITHUB_API_BASE = 'https://api.github.com'; var GITHUB_COMPARE_BASE = GITHUB_API_BASE + '/repos/mozilla/kuma/compare/'; var GITHUB_COMMIT_BASE = 'https://github.com/mozilla/kuma/commit/'; var GITHUB_AUTHOR_BASE = 'https://github.com/'; var GITHUB_PERMALINK_BASE = 'https://github.com/mozilla/kuma/compare/'; /* For reference, this push log .txt is generated via cronjob on the cm-vpn01 jumphost with the following shell command: http://pastebin.mozilla.org/2134395 */ // TODO: Fix this - for some reason, people throws ECONNREFUSED // var PUSH_LOG_URL = 'https://people.mozilla.com/~lorchard/mdn-deploy-history.txt'; var PUSH_LOG_URL = 'http://lmorchard.com/mdn-deploy-history.txt'; var push_log_txt = mdn.fetchHTTPResource(PUSH_LOG_URL); // Extract the push records from the text log var lines = push_log_txt.split(/\n/); var pushes = []; for (var idx=0; idx<lines.length; %="" (!compare_data)="" (!lines[idx])="" +="" 0],="" 1],="" 2],="" 3],="" commit:="" compare_data="mdn.fetchJSONResource(compare_url);" compare_permalink="GITHUB_PERMALINK_BASE" compare_range)="" compare_range;="" compare_url="GITHUB_COMPARE_BASE" continue;="" function="" gen_report(mdn,="" idx+="5)" if="" lines[idx="" pushes.push({="" status:="" time:="" var="" who:="" {="" }="" });="">

Fetching data from GitHub failed. Try comparing on GitHub itself.

<% } else { %>
    <% if (0 === compare_data.commits.length) { %>
  • No changes.
  • <% } else { %> <% for (var i=0, c; c=compare_data.commits[i]; i++) { %>
  • <% if (c.author) { %> <%= c.author.login %> <% } else { %> <%= c.commit.author.name %> <% } %> <%= c.commit.message %>
  • <% } %> <% } %>
<% } } // Report on the next pending push var prev_push = pushes[0]; var compare_range = prev_push.commit + '...HEAD'; %>

Pending changes for the next push

<% gen_report(mdn, compare_range); // Report on pushes so far... // TODO: Maybe eventually show all pushes, but limit for now for (var idx=0; idx<=MAX_RECENT_PUSHES; idx++) { var curr_push = pushes[idx]; var prev_push = pushes[idx+1]; if (!prev_push) { continue; } var compare_range = prev_push.commit + '...' + curr_push.commit; var compare_permalink = GITHUB_PERMALINK_BASE + compare_range; %>

Changes for push by <%=curr_push.who %> at <%= curr_push.time %>

<% gen_report(mdn, compare_range); } %></lines.length;>

Revision Source

<%
var MAX_RECENT_PUSHES = 7;

var GITHUB_API_BASE    = 'https://api.github.com';
var GITHUB_COMPARE_BASE = GITHUB_API_BASE + '/repos/mozilla/kuma/compare/';
var GITHUB_COMMIT_BASE = 'https://github.com/mozilla/kuma/commit/';
var GITHUB_AUTHOR_BASE = 'https://github.com/';
var GITHUB_PERMALINK_BASE = 'https://github.com/mozilla/kuma/compare/';

/* For reference, this push log .txt is generated via cronjob on the 
   cm-vpn01 jumphost with the following shell command:
   http://pastebin.mozilla.org/2134395
*/

// TODO: Fix this - for some reason, people throws ECONNREFUSED 
// var PUSH_LOG_URL = 'https://people.mozilla.com/~lorchard/mdn-deploy-history.txt';
var PUSH_LOG_URL = 'http://lmorchard.com/mdn-deploy-history.txt';
var push_log_txt = mdn.fetchHTTPResource(PUSH_LOG_URL);

// Extract the push records from the text log
var lines = push_log_txt.split(/\n/);
var pushes = [];
for (var idx=0; idx<lines.length; idx+=5) {
    if (!lines[idx]) { continue; }
    pushes.push({
        time: lines[idx + 0],
        who: lines[idx + 1],
        commit: lines[idx + 2],
        status: lines[idx + 3],
    });
}

function gen_report(mdn, compare_range) {
    var compare_url = GITHUB_COMPARE_BASE + compare_range;
    var compare_permalink = GITHUB_PERMALINK_BASE + compare_range;
    var compare_data = mdn.fetchJSONResource(compare_url);
    if (!compare_data) { %>
        <p>Fetching data from GitHub failed. <a target="_blank" href="<%= compare_permalink %>">Try comparing on GitHub itself.</a></p>
    <% } else { %>
        <ul>
            <% if (0 === compare_data.commits.length) { %>
                <li>No changes.</li>
            <% } else { %>
                <% for (var i=0, c; c=compare_data.commits[i]; i++) { %>
                    <li>
                        <% if (c.author) { %>
                            <a href="<%= GITHUB_AUTHOR_BASE + c.author.login %>"><img src="<%= c.author.avatar_url %>" style="width: 2em; height: 2em;" alt="<%= c.author.login %>"></a>
                        <% } else { %>
                            <a href="<%= GITHUB_AUTHOR_BASE + c.commit.author.name %>"><img src="https://www.gravatar.com/avatar/<%= md5(c.commit.author.email) %>" style="width: 2em; height: 2em;" alt="<%= c.commit.author.name %>"></a>
                        <% } %>
                        <a href="<%= GITHUB_COMMIT_BASE + c.sha %>" title="<%= c.sha %>"><%= c.commit.message %></a>
                    </li>
                <% } %>
            <% } %>
        </ul>
    <% }
}

// Report on the next pending push
var prev_push = pushes[0];
var compare_range = prev_push.commit + '...HEAD';
%><h3>Pending changes for the next push</h3><%
gen_report(mdn, compare_range);

// Report on pushes so far...
// TODO: Maybe eventually show all pushes, but limit for now
for (var idx=0; idx<=MAX_RECENT_PUSHES; idx++) {
    var curr_push = pushes[idx];
    var prev_push = pushes[idx+1];
    
    if (!prev_push) { continue; }
    
    var compare_range = prev_push.commit + '...' + curr_push.commit;
    var compare_permalink = GITHUB_PERMALINK_BASE + compare_range;
    %><h3>Changes for <a target="_blank" href="<%= compare_permalink %>">push by <%=curr_push.who %> at <%= curr_push.time %></a></h3><%
    gen_report(mdn, compare_range);
}
%>
Revert to this revision