Skip to content

Commit

Permalink
Version 1.2.0 - Firefox release
Browse files Browse the repository at this point in the history
  • Loading branch information
NirmalScaria authored Aug 4, 2023
2 parents 8104d04 + f3243b1 commit 4dd337a
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 63 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
A browser extension that displays the git graph for any GitHub repository.

[![Version](https://img.shields.io/badge/License-MIT-yellow)]()
[![Version](https://img.shields.io/badge/Version-1.1.5-yellowgreen)]()
[![Version](https://img.shields.io/badge/Version-1.2.0-yellowgreen)]()
[![Version](https://img.shields.io/badge/Chrome_CI/CD-Success-green)]()
[![Version](https://img.shields.io/badge/Firefox_CI/CD-Success-green)]()

Expand Down
18 changes: 12 additions & 6 deletions html/branchSelection.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
justify-content: space-between;">
<div style="display: flex">
<details class="details-reset details-overlay mr-0 mb-0 " id="branch-select-menu">
<summary class="btn css-truncate" data-hotkey="w" title="Switch branches or tags">
<summary id="branch-select-menu-button" class="btn css-truncate" data-hotkey="w"
title="Switch branches or tags">
<svg text="gray" aria-hidden="true" height="16" viewBox="0 0 16 16" version="1.1" width="16"
data-view-component="true" class="octicon octicon-git-branch">
<path fill-rule="evenodd"
d="M11.75 2.5a.75.75 0 100 1.5.75.75 0 000-1.5zm-2.25.75a2.25 2.25 0 113 2.122V6A2.5 2.5 0 0110 8.5H6a1 1 0 00-1 1v1.128a2.251 2.251 0 11-1.5 0V5.372a2.25 2.25 0 111.5 0v1.836A2.492 2.492 0 016 7h4a1 1 0 001-1v-.628A2.25 2.25 0 019.5 3.25zM4.25 12a.75.75 0 100 1.5.75.75 0 000-1.5zM3.5 3.25a.75.75 0 111.5 0 .75.75 0 01-1.5 0z">
</path>
</svg>
<span class="css-truncate-target" data-menu-button="">All branches</span>
<span class="css-truncate-target" data-menu-button="" id="branches-dropdown-button">All branches</span>
<span class="dropdown-caret"></span>
</summary>
<div class="SelectMenu">
<div class="SelectMenu-modal">
<div class="SelectMenu-modal" id="branches-selection-menu">
<header class="SelectMenu-header">
<span class="SelectMenu-title">Select branches to show</span>
<button class="SelectMenu-closeButton" type="button" data-toggle-for="branch-select-menu"><svg
Expand Down Expand Up @@ -73,16 +74,21 @@
<span hidden="{{ isNotDefault }}" class="Label Label--secondary flex-self-start">default</span>
</a>
</template>
<footer class="SelectMenu-footer"><a aria-disabled="true">Show selected branches</a>
<footer class="SelectMenu-footer">
<a class="Button--primary Button--medium Button btn-block mb-2"
data-toggle-for="branch-select-menu" id="branch-filter-button" style="justify-content: center;">
<span class="Button-label"><span class="d-none d-md-block">Show selected branches</span>
<span class="d-block d-md-none">Apply</span></span>
</a>
</footer>
</ref-selector>
</div>
</input-demux>
</div>
</div>
</details>
<img src="https://github.com/NirmalScaria/NirmalScaria.github.io/raw/master/assets/prompt.png" height="32px" class="ml-3" id="promptImage"
style="border-radius: 5px; display: none; cursor: pointer;">
<img src="https://github.com/NirmalScaria/NirmalScaria.github.io/raw/master/assets/prompt.png" height="32px"
class="ml-3" id="promptImage" style="border-radius: 5px; display: none; cursor: pointer;">
</div>
<div id="legendContainer" style="display: none;">
<summary class="btn css-truncate ml-2" value="" style=" pointer-events: none !important;" id="branchButton">
Expand Down
4 changes: 3 additions & 1 deletion js/fetchCommits.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,16 @@ async function fetchCommits() {
if (await fetchCommitsPage(repoOwner, repoName, "NONE")) {
console.log("--FETCHED BRANCHES--");
console.log("--COST : '" + APIcost + "'--");
var allBranchesObject = {}
branches = branches.map(branch => {
heads.push({
name: branch.name,
oid: branch.target.history.edges[0].node.oid,
});
allBranchesObject[branch.name] = branch.target.history.edges[0].node.oid;
branch.target.history.edges[0].node.isHead = true;
return branch;
})
await sortCommits(branches, heads);
await sortCommits(branches, heads, allBranchesObject);
}
}
185 changes: 185 additions & 0 deletions js/fetchFilteredCommits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@


async function fetchFilteredCommits(selectedBranchNames, selectedBranches, allBranches) {
var branches = [];
// Recurcively call this function unti all the branches are fetched
// (GitHub API has a limit of 100 branches per request)

var APIcost = 0;

// The cost depends on the complexity of query that GitHub will have to do
// First, fetch the commits with just the time, so that top ones to show can be found
// Then request the rest of the details (like parents) of commits in another request.
// NOTE : Return true if the request is successful, false otherwise
async function fetchCommitsPageFiltered(repoOwner, repoName, lastFetched) {
if (lastFetched == "NONE") {
console.log("--FETCHING COMMITS STARTED--");
}
else {
console.log("--STILL FETCHING... TOO MANY BRANCHES--");
}
var endpoint = "https://api.github.com/graphql";
if (lastFetched == "NONE") {
var initialQuery = `
fragment branch on Commit {
history(first: 10) {
edges {
node {
... on Commit {
oid
messageHeadlineHTML
committedDate
}
}
}
}
}
{
repository(owner: "` + repoOwner + `", name: "` + repoName + `") {
`;
for (var i = 0; i < selectedBranches.length; i++) {
initialQuery += encode(selectedBranchNames[i]) + ` : object(oid: "` + selectedBranches[i] + `") {
...branch
}
`;
}
initialQuery += `
}
rateLimit {
limit
cost
remaining
resetAt
}
}`;
}
else {
var initialQuery = `
{
repository(owner: "`+ repoOwner + '", name: "' + repoName + `") {
refs(refPrefix: "refs/heads/", orderBy: {direction: DESC, field: TAG_COMMIT_DATE}, first:100, after: "` + lastFetched + `") {
edges {
cursor
node {
... on Ref {
name
target {
... on Commit {
history(first: 10) {
edges {
node {
... on Commit {
oid
messageHeadlineHTML
committedDate
}
}
}
}
}
}
}
}
}
}
}
rateLimit {
limit
cost
remaining
resetAt
}
}`;
}
var headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + getLocalToken()
};
var body = {
query: initialQuery
};
var response = await fetch(endpoint, {
method: "POST",
headers: headers,
body: JSON.stringify(body)
});
if ((response.status != 200 && response.status != 201)) {
console.log("--ERROR FETCHING GRAPHQL--");
addAuthorizationPrompt("Failed to fetch commits. Make sure your GitHub account has access to the repository.");
return (false);
}
var data = await response.json();
if (data.error || data.errors) {
console.log("--ERROR FETCHING GRAPHQL--");
addAuthorizationPrompt("Failed to fetch commits. Make sure your GitHub account has access to the repository.");
return (false);
}
var fetchedBranches = [];
for (var branch in data.data.repository) {
var thisBranch = data.data.repository[branch];
thisBranch.name = decode(branch)
fetchedBranches.push(thisBranch);
}
fetchedBranches.forEach(branch => {
var commit = branch;
branches.push(commit);
});
if (fetchedBranches.length >= 100) {
var lastFetchedCursor = fetchedBranches[fetchedBranches.length - 1].cursor;
if (await fetchCommitsPageFiltered(repoOwner, repoName, lastFetchedCursor) == false) {
return (false);
};
}
APIcost += data.data.rateLimit.cost;
return (true);
}

var currentUrl = window.location.href;
var splitUrl = currentUrl.split('/');
var repoOwner = splitUrl[3]
var repoName = splitUrl[4];

var heads = [];

// fetchCommitsPage returns true only if the fetch was successful
if (await fetchCommitsPageFiltered(repoOwner, repoName, "NONE")) {
console.log("--FETCHED BRANCHES--");
console.log("--COST : '" + APIcost + "'--");
branches = branches.map(branch => {
heads.push({
name: branch.name,
oid: branch.history.edges[0].node.oid,
});
branch.target = {}
branch.target.history = branch.history;
branch.target.history.edges[0].node.isHead = true;
return branch;
})
await sortCommits(branches, heads, allBranches);
}
else {
console.log("Fetch failure");
}
}

// Branch names of git allows a lot of flexibiliity in variable naming
// Many special characters are allowed. But, graphql doesnt seem to accept all of it
// Hence, converting the UTF-8 characters to a 4 digit number for each character
// And decoding back.
function encode(string) {
var res = "XX"
for (var i = 0; i < string.length; i++) {
res += string.charCodeAt(i).toString().padStart(4, 0)
}
return (res)
}

function decode(string) {
string = string.substr(2)
var res = ""
for (var i = 0; i < string.length; i += 4) {
res += String.fromCharCode(parseInt(string.substr(i, 4)))
}
return (res)
}
4 changes: 2 additions & 2 deletions js/fetchFurther.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// The idea is to fetch the last 20 commits in the history
// of each of the last 10 commits that are displayed.
async function fetchFurther(commits, allCommits, heads, pageNo, branchNames) {
async function fetchFurther(commits, allCommits, heads, pageNo, branchNames, allBranches) {
// commits array just contains the last 10 commits so that their
// 10 levels of history can be fetched.

Expand Down Expand Up @@ -119,6 +119,6 @@ async function fetchFurther(commits, allCommits, heads, pageNo, branchNames) {
});
pageNo += 1;
var commitsToShow = (allCommits.slice(0, 10 * pageNo));
await showCommits(commitsToShow, branchNames, allCommits, heads, pageNo);
await showCommits(commitsToShow, branchNames, allCommits, heads, pageNo, allBranches);
showLegend(heads);
}
64 changes: 29 additions & 35 deletions js/fre/updateFre.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,46 @@ async function updateFre(resume) {
async function updateFreStep1() {
createOverlay();
clearToolTip();
var secondCommitDot = document.getElementsByClassName("commitDot")[1];
var secondsha = secondCommitDot.attributes.circlesha.value;
await hoverOnCommit(secondsha);
var hovercard = document.getElementById("head-indication-section").parentElement.parentElement.parentElement.parentElement;
focusOnItem(hovercard, [70, 10, 10, 10]);
var branchSelectButton = document.getElementById("branch-select-menu-button");
var branchesSelectionMenu = document.getElementById("branches-selection-menu");
branchSelectButton.click();
focusOnItem(branchesSelectionMenu, [10, 40, 10, 10]);
showToolTip(
hovercard,
branchesSelectionMenu,
"left-top",
"Welcome to Le Git Graph 1.1.1",
"Hover on any commit to see details ✨",
"Now you can put your mouse pointer on any commit dot and it opens this tooltip which contains detailed information about that commit",
["Continue [1/2]"],
"Welcome to Le Git Graph 1.2.0",
"Now you can apply filters to branches ✨",
"You can select which branches to show in the graph by selecting the branch names in the branches selection menu",
["Continue"],
["btn-primary"],
[nextFrom3]
[nextFrom1]
);
function nextFrom3() {
removeHoverFrom(secondCommitDot);
function nextFrom1() {
var branchSelectButton = document.getElementById("branch-select-menu-button");
branchSelectButton.click();
updateFreStep2();
}

}
function updateFreStep2() {
clearToolTip();
var starButton = document.getElementsByClassName("starring-container d-flex")[0];
var clickStarButton = starButton.querySelectorAll(".rounded-left-2")[1];
console.log(clickStarButton);
focusOnItem(starButton, 5, step3withStar);

async function updateFreStep2() {
clearToolTip();
createOverlay();
focusOnItem(null, [0, 0, 0, 0]);
showToolTip(
starButton,
"top-right",
"",
"Please consider starring this repository!",
"This is the project repository of Le Git Graph extension. If you like it so far, please consider starring it!",
["Previous", "Do not star", "Star and Finish"],
document,
"cover",
"Please rate on Chrome Web Store",
"Enjoying the extension so far? ✨",
"Please rate the extension on Chrome Web Store. It will take less than a minute, but will help me reach more people.",
["Previous", "Maybe later", "Rate on Chrome Web Store"],
["btn-secondary", "btn-secondary", "btn-primary"],
[updateFreStep1, step3withoutStar, step3withStar]
);

function step3withoutStar() {
[updateFreStep1, finishFre, openChromeWebstore]
)
function openChromeWebstore() {
window.open("https://chrome.google.com/webstore/detail/le-git-graph-commits-grap/joggkdfebigddmaagckekihhfncdobff/reviews", "_blank");
clearToolTip();
}
function step3withStar() {
if (starButton.classList.contains("on") == false) {
clickStarButton.click();
}
function finishFre() {
clearToolTip();
}
}
}
2 changes: 1 addition & 1 deletion js/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ try {
else if (details.reason == "update") {
// TODO: [URGENT] Remove this part with next version release.
// Else every version update will trigger an FRE.
// freTab = await chrome.tabs.create({ url: "https://www.github.com/NirmalScaria/le-git-graph/?fre=true&reason=" + details.reason });
freTab = await chrome.tabs.create({ url: "https://www.github.com/NirmalScaria/le-git-graph/?fre=true&reason=" + details.reason });
}
});
}
Expand Down
Loading

0 comments on commit 4dd337a

Please sign in to comment.