Skip to content

Commit 2a93f51

Browse files
committed
Add date of last pushed commit in any branch (closes #32)
1 parent 9b095e4 commit 2a93f51

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

plugin/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.6",
3+
"version": "1.7",
44
"description": "Displays GitHub forks ordered by stars, with additional information and automatic filtering of irrelevant ones.",
55
"permissions": [
66
"*://github.com/*",

plugin/useful-forks.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ const UF_ID_MSG = 'useful_forks_msg';
66
const UF_ID_DATA = 'useful_forks_data';
77
const UF_ID_TABLE = 'useful_forks_table';
88

9-
const svg_literal_fork = '<svg class="octicon octicon-repo-forked v-align-text-bottom" viewBox="0 0 10 16" width="10" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M8 1a1.993 1.993 0 00-1 3.72V6L5 8 3 6V4.72A1.993 1.993 0 002 1a1.993 1.993 0 00-1 3.72V6.5l3 3v1.78A1.993 1.993 0 005 15a1.993 1.993 0 001-3.72V9.5l3-3V4.72A1.993 1.993 0 008 1zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3 10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3-10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>';
10-
const svg_literal_star = '<svg aria-label="star" height="16" class="octicon octicon-star v-align-text-bottom" viewBox="0 0 14 16" width="14" role="img"><path fill-rule="evenodd" d="M14 6l-4.9-.64L7 1 4.9 5.36 0 6l3.6 3.26L2.67 14 7 11.67 11.33 14l-.93-4.74L14 6z"></path></svg>';
9+
const svg_literal_fork = '<svg class="octicon octicon-repo-forked v-align-text-bottom" viewBox="0 0 10 16" width="10" height="16" aria-hidden="true" role="img"><title>Amount of forks, or name of the repository</title><path fill-rule="evenodd" d="M8 1a1.993 1.993 0 00-1 3.72V6L5 8 3 6V4.72A1.993 1.993 0 002 1a1.993 1.993 0 00-1 3.72V6.5l3 3v1.78A1.993 1.993 0 005 15a1.993 1.993 0 001-3.72V9.5l3-3V4.72A1.993 1.993 0 008 1zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3 10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3-10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>';
10+
const svg_literal_star = '<svg class="octicon octicon-star v-align-text-bottom" viewBox="0 0 14 16" width="14" height="16" aria-label="star" role="img"><title>Amount of stars</title><path fill-rule="evenodd" d="M14 6l-4.9-.64L7 1 4.9 5.36 0 6l3.6 3.26L2.67 14 7 11.67 11.33 14l-.93-4.74L14 6z"></path></svg>';
11+
const svg_literal_date = '<svg class="octicon octicon-history text-gray" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" role="img"><title>Date of the most recent push in ANY branch of the repository</title><path fill-rule="evenodd" d="M1.643 3.143L.427 1.927A.25.25 0 000 2.104V5.75c0 .138.112.25.25.25h3.646a.25.25 0 00.177-.427L2.715 4.215a6.5 6.5 0 11-1.18 4.458.75.75 0 10-1.493.154 8.001 8.001 0 101.6-5.684zM7.75 4a.75.75 0 01.75.75v2.992l2.028.812a.75.75 0 01-.557 1.392l-2.5-1A.75.75 0 017 8.25v-3.5A.75.75 0 017.75 4z"></path></svg>';
1112

1213
const UF_MSG_HEADER = "<b>Useful forks</b>";
1314
const UF_MSG_NO_FORKS = "No one forked this specific repository.";
@@ -32,6 +33,10 @@ function checkIfAllRequestsAreDone() {
3233
}
3334
}
3435

36+
function getOnlyDate(full) {
37+
return full.split('T')[0];
38+
}
39+
3540
function extract_username_from_fork(combined_name) {
3641
return combined_name.split('/')[0];
3742
}
@@ -93,7 +98,7 @@ function sortTableColumn(table_id, sortColumn){
9398
}
9499

95100
/** The secondary request which appends the badges. */
96-
function commits_count(request, table_body, table_row) {
101+
function commits_count(request, table_body, table_row, pushed_at) {
97102
return () => {
98103
const response = JSON.parse(request.responseText);
99104

@@ -107,8 +112,9 @@ function commits_count(request, table_body, table_row) {
107112
$('<td>').html(UF_TABLE_SEPARATOR),
108113
$('<td>', {class: "uf_badge"}).html(ahead_badge(response.ahead_by)),
109114
$('<td>').html(UF_TABLE_SEPARATOR),
110-
$('<td>', {class: "uf_badge"}).html(behind_badge(response.behind_by))
111-
)
115+
$('<td>', {class: "uf_badge"}).html(behind_badge(response.behind_by)),
116+
$('<td>').html(UF_TABLE_SEPARATOR + svg_literal_date + ' ' + pushed_at)
117+
);
112118
}
113119

114120
/* Detection of final request. */
@@ -156,7 +162,7 @@ function onreadystatechangeFactory(xhr, successFn, failureFn) {
156162
};
157163
}
158164

159-
/** Dynamically fills the second part of the rows. */
165+
/** Fills the first part of the rows. */
160166
function build_fork_element_html(table_body, combined_name, num_stars, num_forks) {
161167
const NEW_ROW = $('<tr>', {id: extract_username_from_fork(combined_name), class: "useful_forks_repo"});
162168
table_body.append(
@@ -186,7 +192,7 @@ function add_fork_elements(forkdata_array, user, repo, parentDefaultBranch) {
186192
/* Commits diff data (ahead/behind). */
187193
const API_REQUEST_URL = `https://api.github.com/repos/${user}/${repo}/compare/${parentDefaultBranch}...${extract_username_from_fork(currFork.full_name)}:${currFork.default_branch}`;
188194
let request = authenticatedRequestHeaderFactory(API_REQUEST_URL);
189-
request.onreadystatechange = onreadystatechangeFactory(request, commits_count(request, table_body, NEW_ROW), commits_count_failure(NEW_ROW));
195+
request.onreadystatechange = onreadystatechangeFactory(request, commits_count(request, table_body, NEW_ROW, getOnlyDate(currFork.pushed_at)), commits_count_failure(NEW_ROW));
190196
request.send();
191197

192198
/* Forks of forks. */

website/src/queries-init.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ const LANDING_PAGE_INIT_MSG = "<h1 class='title'>Introducing:</h1>"
3535
+ "For more information, check out " + BODY_REPO_LINK + ".";
3636

3737

38-
const SVG_FORK = '<svg class="octicon octicon-repo-forked v-align-text-bottom" viewBox="0 0 10 16" width="10" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M8 1a1.993 1.993 0 00-1 3.72V6L5 8 3 6V4.72A1.993 1.993 0 002 1a1.993 1.993 0 00-1 3.72V6.5l3 3v1.78A1.993 1.993 0 005 15a1.993 1.993 0 001-3.72V9.5l3-3V4.72A1.993 1.993 0 008 1zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3 10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3-10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>';
39-
const SVG_STAR = '<svg aria-label="star" height="16" class="octicon octicon-star v-align-text-bottom" viewBox="0 0 14 16" width="14" role="img"><path fill-rule="evenodd" d="M14 6l-4.9-.64L7 1 4.9 5.36 0 6l3.6 3.26L2.67 14 7 11.67 11.33 14l-.93-4.74L14 6z"></path></svg>';
40-
const SVG_EYE = '<svg class="octicon octicon-eye v-align-text-bottom" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"></path></svg>';
38+
const SVG_FORK = '<svg class="octicon octicon-repo-forked v-align-text-bottom" viewBox="0 0 10 16" width="10" height="16" aria-hidden="true" role="img"><title>Amount of forks, or name of the repository</title><path fill-rule="evenodd" d="M8 1a1.993 1.993 0 00-1 3.72V6L5 8 3 6V4.72A1.993 1.993 0 002 1a1.993 1.993 0 00-1 3.72V6.5l3 3v1.78A1.993 1.993 0 005 15a1.993 1.993 0 001-3.72V9.5l3-3V4.72A1.993 1.993 0 008 1zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3 10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zm3-10c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>';
39+
const SVG_STAR = '<svg class="octicon octicon-star v-align-text-bottom" viewBox="0 0 14 16" width="14" height="16" aria-label="star" role="img"><title>Amount of stars</title><path fill-rule="evenodd" d="M14 6l-4.9-.64L7 1 4.9 5.36 0 6l3.6 3.26L2.67 14 7 11.67 11.33 14l-.93-4.74L14 6z"></path></svg>';
40+
const SVG_EYE = '<svg class="octicon octicon-eye v-align-text-bottom" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" role="img"><title>Amount of watchers</title><path fill-rule="evenodd" d="M8.06 2C3 2 0 8 0 8s3 6 8.06 6C13 14 16 8 16 8s-3-6-7.94-6zM8 12c-2.2 0-4-1.78-4-4 0-2.2 1.8-4 4-4 2.22 0 4 1.8 4 4 0 2.22-1.78 4-4 4zm2-4c0 1.11-.89 2-2 2-1.11 0-2-.89-2-2 0-1.11.89-2 2-2 1.11 0 2 .89 2 2z"></path></svg>';
41+
const SVG_DATE = '<svg class="octicon octicon-history text-gray" viewBox="0 0 16 16" width="16" height="16" aria-hidden="true" role="img"><title>Date of the most recent push in ANY branch of the repository</title><path fill-rule="evenodd" d="M1.643 3.143L.427 1.927A.25.25 0 000 2.104V5.75c0 .138.112.25.25.25h3.646a.25.25 0 00.177-.427L2.715 4.215a6.5 6.5 0 11-1.18 4.458.75.75 0 10-1.493.154 8.001 8.001 0 101.6-5.684zM7.75 4a.75.75 0 01.75.75v2.992l2.028.812a.75.75 0 01-.557 1.392l-2.5-1A.75.75 0 017 8.25v-3.5A.75.75 0 017.75 4z"></path></svg>';
4142

4243
function getRepoCol(full_name, isInitialRepo) {
4344
return SVG_FORK + ` <a href="${buildGithubRepoURL(full_name)}" target="_blank" rel="noopener noreferrer"
@@ -52,6 +53,9 @@ function getForkCol(num_forks) {
5253
function getWatchCol(num_watchers) {
5354
return SVG_EYE + ' x ' + num_watchers;
5455
}
56+
function getDateCol(date) {
57+
return SVG_DATE + ' ' + date;
58+
}
5559

5660
function buildAutoQueryURL(repo) {
5761
return `${SELF_URL}?repo=${repo}`;

website/src/queries-logic.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function clear_old_data() {
2323
shouldTriggerQueryOnTokenSave = false;
2424
}
2525

26+
function getOnlyDate(full) {
27+
return full.split('T')[0];
28+
}
29+
2630
function extract_username_from_fork(combined_name) {
2731
return combined_name.split('/')[0];
2832
}
@@ -127,7 +131,7 @@ function send(requestPromise, successFn, failureFn) {
127131
() => decrementCounters());
128132
}
129133

130-
/** Dynamically fills the second part of a row. */
134+
/** Fills the first part of a row. */
131135
function build_fork_element_html(table_body, combined_name, num_stars, num_forks) {
132136
const NEW_ROW = $('<tr>', {id: extract_username_from_fork(combined_name), class: "useful_forks_repo"});
133137
table_body.append(
@@ -173,11 +177,13 @@ function add_fork_elements(forkdata_array, user, repo, parentDefaultBranch) {
173177
}
174178
} else {
175179
/* Appending the commit badges to the new row. */
180+
let pushed_at = getOnlyDate(currFork.pushed_at);
176181
NEW_ROW.append(
177182
$('<td>').html(UF_TABLE_SEPARATOR),
178183
$('<td>', {class: "uf_badge"}).html(ahead_badge(responseData.ahead_by)).attr("value", responseData.ahead_by),
179184
$('<td>').html(UF_TABLE_SEPARATOR),
180-
$('<td>', {class: "uf_badge"}).html(behind_badge(responseData.behind_by)).attr("value", responseData.behind_by)
185+
$('<td>', {class: "uf_badge"}).html(behind_badge(responseData.behind_by)).attr("value", responseData.behind_by),
186+
$('<td>').html(UF_TABLE_SEPARATOR + getDateCol(pushed_at)).attr("value", pushed_at)
181187
);
182188
}
183189
};
@@ -242,6 +248,7 @@ function initial_request(user, repo) {
242248
html_txt += UF_TABLE_SEPARATOR + getStarCol(responseData.stargazers_count);
243249
html_txt += UF_TABLE_SEPARATOR + getWatchCol(responseData.subscribers_count);
244250
html_txt += UF_TABLE_SEPARATOR + getForkCol(TOTAL_FORKS);
251+
html_txt += UF_TABLE_SEPARATOR + getDateCol(getOnlyDate(responseData.pushed_at));
245252

246253
/* Warning the user if he's not scanning from the root. */
247254
if (responseData.source) { // guarantees both 'source' and 'parent' are present

0 commit comments

Comments
 (0)