Skip to content

Commit 713b688

Browse files
committed
Swapping from master to default_branch (fixes #10)
1 parent f77d2d6 commit 713b688

File tree

3 files changed

+71
-44
lines changed

3 files changed

+71
-44
lines changed

docs/src/queries-logic.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ function badge_width(number) {
3737

3838
/** Credits to https://shields.io/ */
3939
function ahead_badge(amount) {
40-
return '<svg xmlns="http://www.w3.org/2000/svg" width="88" height="24" role="img"><title>How far ahead this fork\'s master branch is compared to its parent\'s master branch</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="r"><rect width="88" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="43" height="18" fill="#555"/><rect x="43" width="45" height="18" fill="#007ec6"/><rect width="88" height="18" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="225" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="330">ahead</text><text x="225" y="130" transform="scale(.1)" fill="#fff" textLength="330">ahead</text><text x="645" y="130" transform="scale(.1)" fill="#fff" textLength="' + badge_width(amount) + '">' + amount + '</text></g></svg>';
40+
return '<svg xmlns="http://www.w3.org/2000/svg" width="88" height="24" role="img"><title>How far ahead this fork\'s default branch is compared to its parent\'s default branch</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="r"><rect width="88" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="43" height="18" fill="#555"/><rect x="43" width="45" height="18" fill="#007ec6"/><rect width="88" height="18" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="225" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="330">ahead</text><text x="225" y="130" transform="scale(.1)" fill="#fff" textLength="330">ahead</text><text x="645" y="130" transform="scale(.1)" fill="#fff" textLength="' + badge_width(amount) + '">' + amount + '</text></g></svg>';
4141
}
4242

4343
/** Credits to https://shields.io/ */
4444
function behind_badge(amount) {
4545
const color = amount === 0 ? '#4c1' : '#007ec6'; // green only when not behind, blue otherwise
46-
return '<svg xmlns="http://www.w3.org/2000/svg" width="92" height="24" role="img"><title>How far behind this fork\'s master branch is compared to its parent\'s master branch</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="r"><rect width="92" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="47" height="18" fill="#555"/><rect x="47" width="45" height="18" fill="'+ color +'"/><rect width="92" height="18" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="245" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="370">behind</text><text x="245" y="130" transform="scale(.1)" fill="#fff" textLength="370">behind</text><text x="685" y="130" transform="scale(.1)" fill="#fff" textLength="' + badge_width(amount) + '">' + amount + '</text></g></svg>';
46+
return '<svg xmlns="http://www.w3.org/2000/svg" width="92" height="24" role="img"><title>How far behind this fork\'s default branch is compared to its parent\'s default branch</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="r"><rect width="92" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="47" height="18" fill="#555"/><rect x="47" width="45" height="18" fill="'+ color +'"/><rect width="92" height="18" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="245" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="370">behind</text><text x="245" y="130" transform="scale(.1)" fill="#fff" textLength="370">behind</text><text x="685" y="130" transform="scale(.1)" fill="#fff" textLength="' + badge_width(amount) + '">' + amount + '</text></g></svg>';
4747
}
4848

4949
function getElementById_$(id) {
@@ -197,7 +197,7 @@ function build_fork_element_html(table_body, combined_name, num_stars, num_forks
197197
}
198198

199199
/** Prepares, appends, and updates dynamically a table row. */
200-
function add_fork_elements(forkdata_array, user, repo) {
200+
function add_fork_elements(forkdata_array, user, repo, parentDefaultBranch) {
201201
if (isEmpty(forkdata_array))
202202
return;
203203

@@ -206,16 +206,16 @@ function add_fork_elements(forkdata_array, user, repo) {
206206

207207
let table_body = getTableBody();
208208
for (let i = 0; i < forkdata_array.length; i++) {
209-
const elem_ref = forkdata_array[i];
209+
const currFork = forkdata_array[i];
210210

211211
/* Basic data (name/stars/forks). */
212-
const NEW_ROW = build_fork_element_html(table_body, elem_ref.full_name, elem_ref.stargazers_count, elem_ref.forks_count);
212+
const NEW_ROW = build_fork_element_html(table_body, currFork.full_name, currFork.stargazers_count, currFork.forks_count);
213213

214214
if (RATE_LIMIT_EXCEEDED) // we can skip everything below because they are only requests
215215
continue;
216216

217217
/* Commits diff data (ahead/behind). */
218-
const API_REQUEST_URL = `https://api.github.com/repos/${user}/${repo}/compare/master...${extract_username_from_fork(elem_ref.full_name)}:master`;
218+
const API_REQUEST_URL = `https://api.github.com/repos/${user}/${repo}/compare/${parentDefaultBranch}...${extract_username_from_fork(currFork.full_name)}:${currFork.default_branch}`;
219219
let request = authenticatedRequestHeaderFactory(API_REQUEST_URL);
220220
request.onreadystatechange = onreadystatechangeFactory(request,
221221
() => {
@@ -241,8 +241,8 @@ function add_fork_elements(forkdata_array, user, repo) {
241241
send(request);
242242

243243
/* Forks of forks. */
244-
if (elem_ref.forks_count > 0) {
245-
request_fork_page(1, elem_ref.owner.login, elem_ref.name);
244+
if (currFork.forks_count > 0) {
245+
request_fork_page(1, currFork.owner.login, currFork.name, currFork.default_branch);
246246
}
247247
}
248248
}
@@ -281,7 +281,7 @@ function initial_request(user, repo) {
281281
getElementById_$(UF_ID_HEADER).html('<b>Queried repository</b>:&nbsp;&nbsp;&nbsp;' + html_txt);
282282

283283
if (TOTAL_FORKS > 0) {
284-
request_fork_page(1, user, repo);
284+
request_fork_page(1, user, repo, response.default_branch);
285285
} else {
286286
setMsg(UF_MSG_NO_FORKS);
287287
enableQueryFields();
@@ -293,7 +293,7 @@ function initial_request(user, repo) {
293293
}
294294

295295
/** Paginated request. Pages index start at 1. */
296-
function request_fork_page(page_number, user, repo) {
296+
function request_fork_page(page_number, user, repo, defaultBranch) {
297297
if (RATE_LIMIT_EXCEEDED)
298298
return;
299299

@@ -311,14 +311,14 @@ function request_fork_page(page_number, user, repo) {
311311
if (link_header) {
312312
let contains_next_page = link_header.indexOf('>; rel="next"');
313313
if (contains_next_page !== -1) {
314-
request_fork_page(++page_number, user, repo);
314+
request_fork_page(++page_number, user, repo, defaultBranch);
315315
}
316316
}
317317

318318
sortTable();
319319

320320
/* Populate the table. */
321-
add_fork_elements(response, user, repo);
321+
add_fork_elements(response, user, repo, defaultBranch);
322322
},
323323
() => setMsg(UF_MSG_ERROR)
324324
);

project/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Useful Forks",
3-
"version": "1.4",
3+
"version": "1.5",
44
"description": "Displays GitHub forks ordered by stars, and with additional information and automatic filters.",
55
"permissions": [
66
"*://github.com/*",

0 commit comments

Comments
 (0)