From 2a93f516295cb4818e6fd04e2c16ea2a65a6d876 Mon Sep 17 00:00:00 2001
From: payne911 <38117856+payne911@users.noreply.github.com>
Date: Sun, 4 Jul 2021 00:32:47 -0400
Subject: [PATCH] Add date of last pushed commit in any branch (closes #32)
---
plugin/manifest.json | 2 +-
plugin/useful-forks.js | 20 +++++++++++++-------
website/src/queries-init.js | 10 +++++++---
website/src/queries-logic.js | 11 +++++++++--
4 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/plugin/manifest.json b/plugin/manifest.json
index d20eff01..67d3c0be 100644
--- a/plugin/manifest.json
+++ b/plugin/manifest.json
@@ -1,6 +1,6 @@
{
"name": "Useful Forks",
- "version": "1.6",
+ "version": "1.7",
"description": "Displays GitHub forks ordered by stars, with additional information and automatic filtering of irrelevant ones.",
"permissions": [
"*://github.com/*",
diff --git a/plugin/useful-forks.js b/plugin/useful-forks.js
index 7993d721..056d0abf 100644
--- a/plugin/useful-forks.js
+++ b/plugin/useful-forks.js
@@ -6,8 +6,9 @@ const UF_ID_MSG = 'useful_forks_msg';
const UF_ID_DATA = 'useful_forks_data';
const UF_ID_TABLE = 'useful_forks_table';
-const svg_literal_fork = ' ';
-const svg_literal_star = ' ';
+const svg_literal_fork = 'Amount of forks, or name of the repository ';
+const svg_literal_star = 'Amount of stars ';
+const svg_literal_date = 'Date of the most recent push in ANY branch of the repository ';
const UF_MSG_HEADER = "Useful forks ";
const UF_MSG_NO_FORKS = "No one forked this specific repository.";
@@ -32,6 +33,10 @@ function checkIfAllRequestsAreDone() {
}
}
+function getOnlyDate(full) {
+ return full.split('T')[0];
+}
+
function extract_username_from_fork(combined_name) {
return combined_name.split('/')[0];
}
@@ -93,7 +98,7 @@ function sortTableColumn(table_id, sortColumn){
}
/** The secondary request which appends the badges. */
-function commits_count(request, table_body, table_row) {
+function commits_count(request, table_body, table_row, pushed_at) {
return () => {
const response = JSON.parse(request.responseText);
@@ -107,8 +112,9 @@ function commits_count(request, table_body, table_row) {
$('
').html(UF_TABLE_SEPARATOR),
$(' ', {class: "uf_badge"}).html(ahead_badge(response.ahead_by)),
$(' ').html(UF_TABLE_SEPARATOR),
- $(' ', {class: "uf_badge"}).html(behind_badge(response.behind_by))
- )
+ $(' ', {class: "uf_badge"}).html(behind_badge(response.behind_by)),
+ $(' ').html(UF_TABLE_SEPARATOR + svg_literal_date + ' ' + pushed_at)
+ );
}
/* Detection of final request. */
@@ -156,7 +162,7 @@ function onreadystatechangeFactory(xhr, successFn, failureFn) {
};
}
-/** Dynamically fills the second part of the rows. */
+/** Fills the first part of the rows. */
function build_fork_element_html(table_body, combined_name, num_stars, num_forks) {
const NEW_ROW = $(' ', {id: extract_username_from_fork(combined_name), class: "useful_forks_repo"});
table_body.append(
@@ -186,7 +192,7 @@ function add_fork_elements(forkdata_array, user, repo, parentDefaultBranch) {
/* Commits diff data (ahead/behind). */
const API_REQUEST_URL = `https://api.github.com/repos/${user}/${repo}/compare/${parentDefaultBranch}...${extract_username_from_fork(currFork.full_name)}:${currFork.default_branch}`;
let request = authenticatedRequestHeaderFactory(API_REQUEST_URL);
- request.onreadystatechange = onreadystatechangeFactory(request, commits_count(request, table_body, NEW_ROW), commits_count_failure(NEW_ROW));
+ request.onreadystatechange = onreadystatechangeFactory(request, commits_count(request, table_body, NEW_ROW, getOnlyDate(currFork.pushed_at)), commits_count_failure(NEW_ROW));
request.send();
/* Forks of forks. */
diff --git a/website/src/queries-init.js b/website/src/queries-init.js
index 98bad570..8b049d33 100644
--- a/website/src/queries-init.js
+++ b/website/src/queries-init.js
@@ -35,9 +35,10 @@ const LANDING_PAGE_INIT_MSG = "Introducing: "
+ "For more information, check out " + BODY_REPO_LINK + ".";
-const SVG_FORK = ' ';
-const SVG_STAR = ' ';
-const SVG_EYE = ' ';
+const SVG_FORK = 'Amount of forks, or name of the repository ';
+const SVG_STAR = 'Amount of stars ';
+const SVG_EYE = 'Amount of watchers ';
+const SVG_DATE = 'Date of the most recent push in ANY branch of the repository ';
function getRepoCol(full_name, isInitialRepo) {
return SVG_FORK + ` decrementCounters());
}
-/** Dynamically fills the second part of a row. */
+/** Fills the first part of a row. */
function build_fork_element_html(table_body, combined_name, num_stars, num_forks) {
const NEW_ROW = $('', {id: extract_username_from_fork(combined_name), class: "useful_forks_repo"});
table_body.append(
@@ -173,11 +177,13 @@ function add_fork_elements(forkdata_array, user, repo, parentDefaultBranch) {
}
} else {
/* Appending the commit badges to the new row. */
+ let pushed_at = getOnlyDate(currFork.pushed_at);
NEW_ROW.append(
$('').html(UF_TABLE_SEPARATOR),
$(' ', {class: "uf_badge"}).html(ahead_badge(responseData.ahead_by)).attr("value", responseData.ahead_by),
$(' ').html(UF_TABLE_SEPARATOR),
- $(' ', {class: "uf_badge"}).html(behind_badge(responseData.behind_by)).attr("value", responseData.behind_by)
+ $(' ', {class: "uf_badge"}).html(behind_badge(responseData.behind_by)).attr("value", responseData.behind_by),
+ $(' ').html(UF_TABLE_SEPARATOR + getDateCol(pushed_at)).attr("value", pushed_at)
);
}
};
@@ -242,6 +248,7 @@ function initial_request(user, repo) {
html_txt += UF_TABLE_SEPARATOR + getStarCol(responseData.stargazers_count);
html_txt += UF_TABLE_SEPARATOR + getWatchCol(responseData.subscribers_count);
html_txt += UF_TABLE_SEPARATOR + getForkCol(TOTAL_FORKS);
+ html_txt += UF_TABLE_SEPARATOR + getDateCol(getOnlyDate(responseData.pushed_at));
/* Warning the user if he's not scanning from the root. */
if (responseData.source) { // guarantees both 'source' and 'parent' are present