-
Notifications
You must be signed in to change notification settings - Fork 1
/
GitHub Code Review Checklist.user.js
233 lines (217 loc) · 10.6 KB
/
GitHub Code Review Checklist.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// ==UserScript==
// @name GitHub Code Review Checklist
// @author Paras Narang
// @version 2.0
// @namespace http://www.flipkart.com/
// @description Code Review Checklist for Flipkart Warehouse team
// @updateURL https://github.com/parasnarang/GitHub-Code-Review-Checklist/raw/master/GitHub%20Code%20Review%20Checklist.user.js
// @include http*://github.com/Flipkart/*/pull/*
// ==/UserScript==
function addReviewChecklists() {
var checklistHash = {
"Functional": [
"Is the code functionally accurate",
"Confirm that code must not use Active record",
"Are Unit tests written and coverage > 90%",
"FactoryGirl is not used for writing specs",
"Are Acceptance test written for all external APIs",
"Complete pull request is reviewed",
"For each comment are next steps mentioned",
"Have you gone through the design doc? Or the description in Jira ?",
"DB validations present?",
"Any Sync call in the flow validation present",
"Are necessary Alerts and Dashboard available",
"Bigfoot - should be treated as a data store. Is there any migration impacting BF",
"Metrics - Are right metrics being captured?",
"Error Handling - Make sure errors/exceptions are not being suppressed.",
"Logging - differentiate between what is needed and what is good to have."
],
"Technical": [
"Are OOP concepts followed",
"Is the code extensible",
"Is LA model followed, no deviations should be present",
"Exception handling vs over exception handling",
"Separation of concerns",
"Data structure added/used is appropriate for the flow",
"Have you gone through the design doc? Or the description in Jira ?",
"There should be no function with more than 10 logical lines of code",
"Make sure there is a clear segregation what is data and what is business. Likes of no business logic in VO’s."
],
"Performance": [
"Has the code introduced multi-threading, if so, does the code behave accurately or are there potential loop holes",
"Is more logging introduced in sync flow, affects of that understood and limited",
"Has the API response time increased",
"Dependency on external system introduced",
"Is a new GEM added, consequence of that additional understood from perf standpoint",
"Is there enough logging present to be able to root cause an issue, excessive logging is bad too",
"Are DB changes introduced, impact of that on performance, multi-write",
"Is the scenario applicable to caching - if caching is used, is it evaluated on cache miss as well",
"How much is QPS increasing due to the change",
"Have you gone through the design doc? Or the description in Jira ?",
"Any new SYNC call introduced? Is the latency of that accounted for ?",
"Check if things can be batched. We had to recently explicitly solve for n+1 queries.",
"Check for potential memory leaks.",
"Are DB queries optimised or do they have an underlying assumption. Example - a query in put away was initially a good query but became slow as operations started using a shelf for a bulk location."
]
};
$.each(checklistHash, function(reviewerType, checklistItemsArray) {
var checklistForm = $('<form class="menu" id="' + reviewerType + 'Form"> </form>');
checklistForm.css({
position: 'fixed',
bottom: 60,
right: 30,
width: "20%",
height: "50%",
overflow: 'scroll',
zIndex: 10,
display: 'none'
});
var checklistItems = [];
$.each(checklistItemsArray, function(index, value) {
var backgroundColor = (index % 2) ? "#f7f7f7" : "#fff";
checklistItems.push( $(
'<div class="menu-item columns" style="background: ' + backgroundColor + ';">' +
'<label class="four-fifths column" style="font-weight: normal; text-align: justify;" >' +
'<input type="checkbox" value="' + value + '"> ' + value +
'</label>' +
'<a id="' + reviewerType + index + 'CommentButton" class="one-fifth column octicon octicon-comment" style="cursor: pointer; cursor: hand;">' +
'<svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path d="M15 2H6c-0.55 0-1 0.45-1 1v2H1c-0.55 0-1 0.45-1 1v6c0 0.55 0.45 1 1 1h1v3l3-3h4c0.55 0 1-0.45 1-1V10h1l3 3V10h1c0.55 0 1-0.45 1-1V3c0-0.55-0.45-1-1-1zM9 12H4.5l-1.5 1.5v-1.5H1V6h4v3c0 0.55 0.45 1 1 1h3v2z m6-3H13v1.5l-1.5-1.5H6V3h9v6z"></path></svg>' +
'</a>' +
'</div>' +
'<input type="text" class="input-mini input-block" style="display: none;" id="' + reviewerType + index + 'CommentInput" placeholder="Enter Comments here..">'
));
});
var checklistTitle = $('<span class="menu-heading" style="">Checklist : ' + reviewerType + ' Review</span>').css('textTransform', 'capitalize');
checklistForm.append(checklistTitle);
$.each(checklistItems, function( index, checklistItem ) {
checklistForm.append(checklistItem);
});
var checklistSubmit = $('<center><a style="width:100%;" id="' +
reviewerType +
'ChecklistShipIt" class="btn btn-sm btn-primary tooltipped tooltipped-n" aria-label="Post Comment">Post Comment</a></center>');
checklistForm.append(checklistSubmit);
$('body').append(checklistForm);
$.each(checklistItems, function( index, checklistItem ) {
$('#' + reviewerType + index + 'CommentButton').click(function() {
$('#' + reviewerType + index + 'CommentInput').toggle();
if($('#' + reviewerType + index + 'CommentInput').is(':visible')){
$('#' + reviewerType + index + 'CommentInput').focus();
}
});
});
});
}
function addShipItButton() {
var shipItButton = $('<a id="shipItButton" class="btn btn-big tooltipped tooltipped-n" aria-label="Code Review Checklist">Review Checklist</a>');
shipItButton.css({
position: 'fixed',
bottom: 20,
right: 30
});
$('body').append(shipItButton);
}
function addReviewerTypeMenu() {
var reviewerTypeMenuHTML = (function reviewerTypeMenuHTML() {
var elements = [];
$.each(['Functional', 'Technical', 'Performance'], function( index, reviewerType ) {
elements.push('<a id="' + reviewerType + 'Reviewer" class="menu-item" style="cursor: pointer; cursor: hand;">' + reviewerType + 'Review</a>');
});
return '<nav class="menu">' +
'<span class="menu-heading">Choose</span>' +
elements.join("") +
'</nav>';
})();
var reviewerTypeMenu = document.createElement("div");
reviewerTypeMenu.innerHTML = reviewerTypeMenuHTML;
reviewerTypeMenu.id = "reviewerTypeMenu";
reviewerTypeMenu.style.position = "fixed";
reviewerTypeMenu.style.bottom = "60px";
reviewerTypeMenu.style.right = "30px";
reviewerTypeMenu.style.zIndex = 100;
reviewerTypeMenu.style.display = "none";
$('body').append(reviewerTypeMenu);
}
function registerMenuToggle() {
$('#shipItButton').click(function() {
$("#submitConfirmNotification").hide();
$('#reviewerTypeMenu').toggle();
$.each(['Functional', 'Technical', 'Performance'], function( index, reviewerType ) {
if($('#' + reviewerType + 'Form').is(":visible")){
$('#reviewerTypeMenu').hide();
$('#' + reviewerType + 'Form').hide();
}
});
});
}
function registerChecklistsToggle() {
$.each(['Functional', 'Technical', 'Performance'], function( index, reviewerType ) {
$('#' + reviewerType + 'Reviewer').click(function() {
$('#' + reviewerType + 'Form').show();
$('#reviewerTypeMenu').hide();
});
});
}
function createShipItComment(message) {
var commentForm = $( "textarea[name='comment[body]']" ).first();
commentForm.val(message);
commentForm.closest("form").submit();
var url = $(location).attr('href').replace("/files", "").replace("/commits", "") + $('.timeline-comment-header-text .timestamp').last().attr('href');
var submitConfirmNotification = $('<div id="submitConfirmNotification" class="flash text-center">'+
'<span class="octicon octicon-x flash-close js-flash-close"></span>'+
'Comment Posted at <a href="'+ url +'">' + url + '</a></div>');
submitConfirmNotification.css({
position: 'fixed',
width: '100%',
left: 0,
top: 0,
zIndex: 100,
borderTop: 0
});
$('body').prepend(submitConfirmNotification);
}
function constructShipItMessage(reviewerType) {
var username = $('.header-nav-current-user .css-truncate-target').first().text();
var message = reviewerType + " Review by " + username + "\n\n";
$.each($('#' + reviewerType +'Form').find(':input'), function (index, element) {
if(element.type == 'checkbox'){
value = element.checked ? " :white_check_mark: " : " :red_circle: ";
message = message + value + " | " + element.value + "\n";
}
if(element.type == 'text' && element.value.length > 0){
message = message + " Comments : " + element.value + "\n";
}
});
return message;
}
function registerChecklistShipIts() {
$.each(['Functional', 'Technical', 'Performance'], function( index, reviewerType ) {
$('#' + reviewerType + 'ChecklistShipIt').click(function() {
var message = constructShipItMessage(reviewerType);
createShipItComment(message);
$('#' + reviewerType + 'Form').hide();
$('#reviewerTypeMenu').hide();
});
});
}
function letsJQuery() {
//alert($); // check if the dollar (jquery) function works
//alert($().jquery); // check jQuery version
$(document).ready(function(){
addShipItButton();
addReviewerTypeMenu();
registerMenuToggle();
addReviewChecklists();
registerChecklistsToggle();
registerChecklistShipIts();
});
}
function jquery_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(jquery_wait, 10);
} else {
letsJQuery();
}
}
(function(){
jquery_wait();
})();