Skip to content

Commit

Permalink
Merge pull request #20 from eUgEntOptIc44/main
Browse files Browse the repository at this point in the history
integrate forks into git graph
  • Loading branch information
eUgEntOptIc44 authored Jul 5, 2023
2 parents c7abbd8 + ca29bef commit d6eee76
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ tasks:
- init: >
sudo apt update && sudo apt upgrade -y && sudo apt install graphviz -y && virtualenv venv && source venv/bin/activate && python -m pip install --upgrade pip && pip install -r requirements.txt
git clone https://codeberg.org/Starfish/TinyWeatherForecastGermany.git "TinyWeatherForecastGermany"
python git_log2graphviz.py
python __init__.py && python git_log2graphviz.py
vscode:
extensions:
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

Fetch all commits of [**TinyWeatherForecastGermany**](https://codeberg.org/Starfish/TinyWeatherForecastGermany/) and draw a graph for them using graphviz.

All forks of the repository are fetched from Codeberg and integrated in the git graph.

The results are located at the `pages` branch and also published using GitHub Pages.

* [`git_graph.svg`](https://tinyweatherforecastgermanygroup.github.io/git-graph/git_graph.svg)
* [`git_graph.dot`](https://tinyweatherforecastgermanygroup.github.io/git-graph/git_graph.dot)

**Merge** commits are highlighted in blue.
**Weblate** commits are highlighted in dark green.

**status**: work in progress

**author**: Jean-Luc Tibaux

## TODO

1. fetch all forks from codeberg api
2. compare branches of forks as github does it
Improve integration of forks in git graph.
26 changes: 20 additions & 6 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import concurrent.futures
import os
import json
import sys
from multiprocessing import cpu_count
Expand All @@ -14,7 +15,9 @@
if forks_req.ok:
forks_req_json = forks_req.json()
else:
print(f"failed to request forks -> received unexpected status code {forks_req.status_code} -> text: {forks_req.text}")
print(
f"failed to request forks -> received unexpected status code {forks_req.status_code} -> text: {forks_req.text}"
)
sys.exit(0)

with open("forks-api.json", "w+", encoding="utf-8") as fh:
Expand All @@ -23,6 +26,16 @@
# with open('forks-api.json','r',encoding='utf-8') as fh:
# forks_req_json = json.loads(str(fh.read()))

for fork_entry in forks_req_json:
clone_url = str(fork_entry["clone_url"])
fork_id = str(fork_entry["id"])
os.system(
f"cd TinyWeatherForecastGermany && git remote add fork_{fork_id} '{clone_url}'"
f" && git fetch -a fork_{fork_id} || true"
)

os.system("cd TinyWeatherForecastGermany && git fetch -a || true")


def get_commits_json(clone_url, fork_id):
print(f"analyzing '{clone_url}' ... ")
Expand Down Expand Up @@ -57,9 +70,10 @@ def get_commits_json(clone_url, fork_id):
fh.write(str(mermaid_str))


with concurrent.futures.ThreadPoolExecutor(max_workers=cpu_count()) as executor:
for fork_entry in forks_req_json:
clone_url = str(fork_entry["clone_url"])
def generate_mermaid_gitgraph():
with concurrent.futures.ThreadPoolExecutor(max_workers=cpu_count()) as executor:
for fork_entry in forks_req_json:
clone_url = str(fork_entry["clone_url"])

future = executor.submit(get_commits_json, clone_url, fork_entry["id"])
# print(future.result())
future = executor.submit(get_commits_json, clone_url, fork_entry["id"])
# print(future.result())
21 changes: 17 additions & 4 deletions git_log2graphviz.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import re
from multiprocessing import cpu_count
from pprint import pprint

from pydriller import Repository
Expand All @@ -13,7 +14,9 @@
dot_graph_2 = ""

# if repo not cloned yet -> Repository("https://codeberg.org/Starfish/TinyWeatherForecastGermany.git")
for commit in Repository("TinyWeatherForecastGermany/").traverse_commits():
for commit in Repository(
"TinyWeatherForecastGermany/", include_remotes=True, num_workers=cpu_count()
).traverse_commits():
commit_dict = {}
commit_dict["hash"] = str(commit.hash)
commit_dict["msg"] = str(commit.msg).replace('"', "'")
Expand All @@ -29,7 +32,17 @@
if commit_dict["merge"]: #'merge pull' in str(commit_dict['msg']).lower():
c_color = ",color=blue"

dot_graph_1 += f"\t\"{commit_dict['hash']}\" [label=<<B>{commit_dict['hash'][0:6]}</B>{commit_dict['author_name']}>, comment=\"{commit_dict['timestamp']}\", tooltip=\"{commit_dict['timestamp']}\n{commit_dict['msg']}\", shape=box{c_color}, URL=\"https://codeberg.org/Starfish/TinyWeatherForecastGermany/commit/{commit_dict['hash']}\"];\n"
if " using weblate" in commit_dict["msg"].lower():
c_color = ",color=darkgreen"

dot_graph_1 += f"\t\"{commit_dict['hash']}\" [label=<<B>{commit_dict['hash'][0:6]}</B>"
dot_graph_1 += f"{commit_dict['author_name']}>, comment=\"{commit_dict['timestamp']}\","
dot_graph_1 += f" tooltip=\"{commit_dict['timestamp']}\n{commit_dict['msg']}\", shape=box{c_color},"

if "origin/master" in commit_dict["branches"] or "origin/main" in commit_dict["branches"]:
dot_graph_1 += f" URL=\"https://codeberg.org/Starfish/TinyWeatherForecastGermany/commit/{commit_dict['hash']}\""

dot_graph_1 += "];\n"

c_parents_len = len(commit_dict["parents"])
if c_parents_len > 0:
Expand All @@ -39,8 +52,8 @@
commits_list.append(commit_dict)
del commit_dict

# with open(f"test.json",'w+',encoding='utf-8') as fh:
# fh.write(str(json.dumps(commits_list, indent=4)))
with open("commit_list.json",'w+',encoding='utf-8') as fh:
fh.write(str(json.dumps(commits_list, indent=4)))

dot_graph_1 += "\n\n" + dot_graph_2 + "}"

Expand Down

0 comments on commit d6eee76

Please sign in to comment.