Skip to content

Instantly share code, notes, and snippets.

@maxparm
Last active April 19, 2016 21:19
Show Gist options
  • Save maxparm/c508b48902a2f90c9ac9 to your computer and use it in GitHub Desktop.
Save maxparm/c508b48902a2f90c9ac9 to your computer and use it in GitHub Desktop.
CJS extension - Remember the Changelog
$(function () {
$('.view-pull-request .js-new-comment-form').on('submit', function (e) {
var text = $('.js-comment-container:first .js-comment-body').text().toLowerCase();
if (text.indexOf('changelog') < 0) {
e.preventDefault();
alert('Please add a changelog!');
}
});
if ($('.pull-request-tab-content')) {
var html = $(
'<div id="" class="">' +
'<div class="js-ui-content columns"></div>' +
'</div>');
var currentUser = $('.header-nav-current-user strong').text();
var added = 0;
var deleted = 0;
if ($('.text-diff-added').length) {
var added = parseInt($('.text-diff-added').text().trim().substr(1).replace(/,/g, ''), 10);
var deleted = parseInt($('.text-diff-deleted').text().trim().substr(1).replace(/,/g, ''), 10);
}
var lines = added + deleted;
if (lines > 500) {
var placeholder = '\n!!!!!!!!!!!!\nCareful you have submitted more than 500 lines: ' + lines + '\n!!!!!!!!!!!!';
$('#new_comment_field').attr('placeholder', placeholder);
}
$('.js-ui-content', html).append('<div class="one-third column"><div class="flash"><strong>Changed lines:</strong> ' + lines + '</div><br/></div>')
// NB Commits
var commitsCount = $('.commit .author').filter(function () { return $(this).text() == currentUser}).length;
$('.js-ui-content', html).append('<div class="one-third column"><div class="flash"><strong>' + currentUser + ' Commits:</strong> ' + commitsCount + '</div><br/></div>');
// NB Comments
var commentsCount = $('.timeline-comment').length;
$('.js-ui-content', html).append('<div class="one-third column"><div class="flash"><strong>Comments:</strong> ' + commentsCount + '</div><br/></div>');
// NB Assignments
var assignementsCount = $('.discussion-item-assigned').length + $('.discussion-item-unassigned').length;
$('.js-ui-content', html).append('<div class="one-third column"><div class="flash"><strong>Assignments:</strong> ' + assignementsCount + '</div><br/></div>');
// Ratio Line/commits
var ratioLineCommits = 0;
if (lines && commitsCount) {
ratioLineCommits = Math.round(lines / commitsCount);
}
$('.js-ui-content', html).append('<div class="one-third column"><div class="flash"><strong>Ratio Line/Commits:</strong> ' + ratioLineCommits + '</div><br/></div>');
// Total Score
var score = assignementsCount + commentsCount + commitsCount + lines;
$('.js-ui-content', html).append('<div class="one-third column"><div class="flash"><strong>Score (Total):</strong> ' + score + '</div><br/></div>');
// Show UI
$('.timeline-new-comment').before(html);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment