@@ -37,13 +37,13 @@ function badge_width(number) {
37
37
38
38
/** Credits to https://shields.io/ */
39
39
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>' ;
41
41
}
42
42
43
43
/** Credits to https://shields.io/ */
44
44
function behind_badge ( amount ) {
45
45
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>' ;
47
47
}
48
48
49
49
function getElementById_$ ( id ) {
@@ -197,7 +197,7 @@ function build_fork_element_html(table_body, combined_name, num_stars, num_forks
197
197
}
198
198
199
199
/** 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 ) {
201
201
if ( isEmpty ( forkdata_array ) )
202
202
return ;
203
203
@@ -206,16 +206,16 @@ function add_fork_elements(forkdata_array, user, repo) {
206
206
207
207
let table_body = getTableBody ( ) ;
208
208
for ( let i = 0 ; i < forkdata_array . length ; i ++ ) {
209
- const elem_ref = forkdata_array [ i ] ;
209
+ const currFork = forkdata_array [ i ] ;
210
210
211
211
/* 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 ) ;
213
213
214
214
if ( RATE_LIMIT_EXCEEDED ) // we can skip everything below because they are only requests
215
215
continue ;
216
216
217
217
/* 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 } ` ;
219
219
let request = authenticatedRequestHeaderFactory ( API_REQUEST_URL ) ;
220
220
request . onreadystatechange = onreadystatechangeFactory ( request ,
221
221
( ) => {
@@ -241,8 +241,8 @@ function add_fork_elements(forkdata_array, user, repo) {
241
241
send ( request ) ;
242
242
243
243
/* 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 ) ;
246
246
}
247
247
}
248
248
}
@@ -281,7 +281,7 @@ function initial_request(user, repo) {
281
281
getElementById_$ ( UF_ID_HEADER ) . html ( '<b>Queried repository</b>: ' + html_txt ) ;
282
282
283
283
if ( TOTAL_FORKS > 0 ) {
284
- request_fork_page ( 1 , user , repo ) ;
284
+ request_fork_page ( 1 , user , repo , response . default_branch ) ;
285
285
} else {
286
286
setMsg ( UF_MSG_NO_FORKS ) ;
287
287
enableQueryFields ( ) ;
@@ -293,7 +293,7 @@ function initial_request(user, repo) {
293
293
}
294
294
295
295
/** 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 ) {
297
297
if ( RATE_LIMIT_EXCEEDED )
298
298
return ;
299
299
@@ -311,14 +311,14 @@ function request_fork_page(page_number, user, repo) {
311
311
if ( link_header ) {
312
312
let contains_next_page = link_header . indexOf ( '>; rel="next"' ) ;
313
313
if ( contains_next_page !== - 1 ) {
314
- request_fork_page ( ++ page_number , user , repo ) ;
314
+ request_fork_page ( ++ page_number , user , repo , defaultBranch ) ;
315
315
}
316
316
}
317
317
318
318
sortTable ( ) ;
319
319
320
320
/* Populate the table. */
321
- add_fork_elements ( response , user , repo ) ;
321
+ add_fork_elements ( response , user , repo , defaultBranch ) ;
322
322
} ,
323
323
( ) => setMsg ( UF_MSG_ERROR )
324
324
) ;
0 commit comments