Skip to content

Draw complete graph with JS #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: spring2020
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ GEM
erubi (1.8.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
git (1.5.0)
git (1.7.0)
rchardet (~> 1.8)
github_api (0.18.2)
addressable (~> 2.4)
descendants_tracker (~> 0.0.4)
Expand Down Expand Up @@ -81,6 +82,7 @@ GEM
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rake (12.3.2)
rchardet (1.8.0)
rdoc (3.12.2)
json (~> 1.4)
rspec (3.5.0)
Expand Down
130 changes: 130 additions & 0 deletions lib/views/log.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.js"></script>
<canvas id="gitGraph"></canvas>
<script>
var gitgraph = new GitGraph({
template: "metro", // or blackarrow
orientation: "vertical-reverse",
author: "John Doe",
mode: "extended" // or compact if you don't want the messages
});

<% created_branches = []%>
<% @graph.commit_order.each do |sha| %>
<% commit_info = @graph.graph_order[sha] %>
<% commit_info %>
<% if @graph.commit_order.index(sha) == 0 %>
var master = gitgraph.branch("master");

gitgraph.commit({ sha1: "<%= sha %>", message: "<%= commit_info[:message] %>", author: "<%= commit_info[:author] %>"});

<% created_branches.push "master" %>
<% else %>
<% if !created_branches.include? commit_info[:branch] %>
const <%= commit_info[:branch].gsub("-", "_") %> = gitgraph.branch("<%= commit_info[:branch].gsub("-", "_") %>");
<% end %>

<% created_branches.push commit_info[:branch] %>
<% if commit_info[:merge_between].size > 0 %>
<% merge_commits = commit_info[:merge_between] %>
<% branch_1 = @graph.graph_order[merge_commits.first][:branch].gsub("-", "_") %>
<% branch_2 = @graph.find_merging_branch_name(merge_commits.first, merge_commits.last).gsub("-", "_") %>
<%= branch_2 %>.merge(
<%= branch_1%>,
{
sha1: "<%= sha %>",
message: "<%= commit_info[:message] %>",
author: "<%= commit_info[:author] %>"
}
);
<% else %>
<%= commit_info[:branch].gsub("-", "_") %>.commit({message: "<%= commit_info[:message] %>", sha1: "<%= sha %>", author: "<%= commit_info[:author] %>"});
<% end %>
<% if commit_info[:branches_to].size > 0 %>
<% commit_info[:branches_to].each do |branch| %>
<% if !created_branches.include? branch %>
const <%= branch.gsub("-", "_") %> = gitgraph.branch("<%= branch.gsub("-", "_") %>");

<% created_branches.push branch %>
<% end %>
<% end %>
<% end %>


<% end %>
<% end %>
</script>
<% created_branches = []%>
<% @graph.commit_order.each do |sha| %>
<% commit_info = @graph.graph_order[sha] %>
<% commit_info %>
<% if @graph.commit_order.index(sha) == 0 %>
var master = gitgraph.branch("master");
<br>
gitgraph.commit({ sha1: "<%= sha %>"", message: ""}});
<br>
<% created_branches.push "master" %>
<% else %>
<% if !created_branches.include? commit_info[:branch] %>
const <%= commit_info[:branch] %> = gitgraph.branch("<%= commit_info[:branch] %>");
<br>
<% end %>
<% created_branches.push commit_info[:branch] %>
<%= commit_info[:branch] %>.commit({message: "", sha1: "<%= sha %>"});
<% if commit_info[:branches_to].size > 0 %>
<% commit_info[:branches_to].each do |branch| %>
const <%= branch %> = gitgraph.branch("<%= branch %>");
<br>
<% created_branches.push branch %>
<br>
<% end %>
<% end %>

<br>
<% end %>
<% end %>
<hr>


<% created_branches = []%>
<% @graph.commit_order.each do |sha| %>
<% commit_info = @graph.graph_order[sha] %>
<% commit_info %>
<% if @graph.commit_order.index(sha) == 0 %>
var master = gitgraph.branch("master");
<br>
gitgraph.commit({ sha1: "<%= sha %>", message: "<%= commit_info[:message] %>", author: "<%= commit_info[:author] %>"});
<br>

<% created_branches.push "master" %>
<% else %>
<% if !created_branches.include? commit_info[:branch] %>
const <%= commit_info[:branch].gsub("-", "_") %> = gitgraph.branch("<%= commit_info[:branch].gsub("-", "_") %>");
<br>
<% end %>

<% created_branches.push commit_info[:branch] %>
<% if commit_info[:merge_between].size > 0 %>
<% merge_commits = commit_info[:merge_between] %>
<%# @graph.graph_order %>
<% branch_1 = @graph.graph_order[merge_commits.first][:branch] %>
<% branch_2 = @graph.find_merging_branch_name(merge_commits.first, merge_commits.last)%>
<%= branch_1 %>.merge(<%= branch_2%>);
<br>
<% else %>
<%= commit_info[:branch].gsub("-", "_") %>.commit({message: "<%= commit_info[:message] %>", sha1: "<%= sha %>", author: "<%= commit_info[:author] %>"});
<br>
<% end %>
<% if commit_info[:branches_to].size > 0 %>
<% commit_info[:branches_to].each do |branch| %>
<% if !created_branches.include? branch %>
const <%= branch.gsub("-", "_") %> = gitgraph.branch("<%= branch.gsub("-", "_") %>");
<br>

<% created_branches.push branch %>
<% end %>
<% end %>
<% end %>


<% end %>
<% end %>
37 changes: 37 additions & 0 deletions lib/views/status.erb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,43 @@
<% end%>
</form>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gitgraph.js/1.11.4/gitgraph.min.js"></script>
<canvas id="gitGraph"></canvas>
<script>
var gitgraph = new GitGraph({
template: "metro", // or blackarrow
orientation: "vertical-reverse",
author: "John Doe",
mode: "extended" // or compact if you don't want the messages
});
<% commits = @graph.to_array %>
<% commits.each_with_index do |commit, index| %>
//first <%= index %>
<% if index > 0 %>
//<%= index %>
<% previous_branches = commits.first(index)%>
<% if !previous_branches.map{|c| c[:branch_name]}.include?(commit[:branch_name]) %>
let branch_<%= commit[:branch_name].gsub("-", "_") %> = gitgraph.branch("<%= commit[:branch_name] %>");
<% end %>
<% else%>
let branch_<%= commit[:branch_name].gsub("-", "_") %> = gitgraph.branch("<%= commit[:branch_name] %>");
<% end %>
branch_<%= commit[:branch_name].gsub("-", "_") %>.commit({message: '<%= commit[:message].to_s.gsub("\n", " ") %>', author: "<%= commit[:author] %>", sha1: "<%= commit[:sha] %>"});

<% end %>
// gitgraph.commit("My first commit"); // 1 commit upon HEAD
// var develop = gitgraph.branch("develop"); // New branch from HEAD
// var myfeature = develop.branch("myfeature"); // New branch from develop
// develop.commit("Develop a feature - part 1");
// develop.commit("Develop a feature - part 2");

// master.commit({message: "Fast bugfix", author: "John Fixer"});
// myfeature.commit({message: "New cool feature", author: "John Feature"});

// develop.merge(master);
// myfeature.merge(master);
// master.commit({message: "Release of version 0.1", tag: "0.1", author: "John Releaser", sha1: "abcdef0"});
</script>
<% @graph_branches.each do |branch_hash| %>
<h4 class="p-4"><%= branch_hash[:branch] %></h4>
<code class="bg-dark text-white p-3">
Expand Down
13 changes: 8 additions & 5 deletions lib/web_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ class Server < Sinatra::Base
working_dir = File.exist?(Dir.pwd + "/.git") ? Dir.pwd : Dir.pwd + "/.."
g = Git.open(working_dir)

graph = WebGit::Graph.new(g)
graph.to_hash.to_json
@graph = WebGit::Graph.new(g)
# graph.find_common_shas.to_json
# graph.tree_traversal.to_json
@graph.build_backwards#.to_json
# graph.to_hash.to_json
#sha = commit.sha.slice(0..7)
# commit_date = Date.parse commit.date
# strftime("%a, %d %b %Y, %H:%M %z") -> time_ago_in_words(commit_date)
# * 76eff73 - Wed, 11 Mar 2020 19:58:21 +0000 (13 days ago) (HEAD -> current_branch)
# | blease - Jelani Woods

erb :log
# " * " + sha + " - " + commit_date + " (" + time_ago_in_words(commit_date) + ") " + "\n\t| " + commit.message
end

Expand Down Expand Up @@ -67,8 +70,8 @@ class Server < Sinatra::Base
# (origin/master, origin/jw-non-sweet, origin/HEAD)
# g.branches[:master].gcommit

graph = WebGit::Graph.new(g)
@graph_hash = graph.to_hash
@graph = WebGit::Graph.new(g)
@graph_hash = @graph.to_hash
@graph_branches = @graph_hash.sort do |branch_a, branch_b|
branch_b[:log].last[:date] <=> branch_a[:log].last[:date]
end
Expand Down
Loading