Skip to content

Commit

Permalink
Merge pull request #19 from eUgEntOptIc44/main
Browse files Browse the repository at this point in the history
upgrade dependencies
  • Loading branch information
eUgEntOptIc44 authored Jun 6, 2023
2 parents 65a6257 + 37e9f54 commit c7abbd8
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 65 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/gitgraph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ name: generate git graph

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
# Triggers the workflow on push events and only for the main branch
push:
branches: [ main ]
branches: [main]
pull_request:
branches-ignore: [ main ]
branches-ignore: [main]
schedule:
- cron: "5 7 * * */2" # every two days at 7:05am UTC

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

repository_dispatch: # run workflow on api request

# prevent concurrent jobs
Expand All @@ -27,33 +27,33 @@ jobs:
steps:
- name: clone remote repo
run: git clone https://codeberg.org/Starfish/TinyWeatherForecastGermany.git TinyWeatherForecastGermany

- name: clone this repo
run: git clone https://github.com/${{ github.repository }}.git "git-graph"

- name: update apt packages
run: timeout 120s sudo apt update || true

- name: upgrade apt packages
run: timeout 120s sudo apt upgrade -y || true

- name: Setup Python 3.x
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: install virtualenv
run: pip install virtualenv

- name: init virtualenv
run: virtualenv venv

- name: activate virtualenv
run: source venv/bin/activate

- name: upgrade pip
run: python -m pip install --upgrade pip

- name: install graphviz
run: sudo apt install -y graphviz

Expand All @@ -65,18 +65,18 @@ jobs:

- name: generate git graph using Python and graphviz
run: python git-graph/git_log2graphviz.py

- name: list directory contents
run: ls -lisha

- name: archive generated svg
uses: actions/upload-artifact@v3
with:
name: generated-svg
path: |
*.svg
*.dot
- name: copy artifacts to git repo directory
run: |
cp *.svg git-graph/ || true
Expand All @@ -95,4 +95,3 @@ jobs:
git commit -m "update git graph"
git remote add github-pages "https://${{ github.repository_owner }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
git push -u -f github-pages
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.mermaid
#*.dot
#*.svg
TinyWeatherForecastGermany/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
9 changes: 8 additions & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@

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
vscode:
extensions:
- ms-python.python
- ms-python.black-formatter
- charliermarsh.ruff
- SonarSource.sonarlint-vscode
- eamodio.gitlens
50 changes: 29 additions & 21 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@

import concurrent.futures
from multiprocessing import cpu_count
import json
import sys
from multiprocessing import cpu_count
from pprint import pprint

from pydriller import Repository

import requests
from pydriller import Repository

forks_req = requests.get(f"https://codeberg.org/api/v1/repos/Starfish/TinyWeatherForecastGermany/forks", timeout=10)
forks_req_json = forks_req.json()
forks_req = requests.get(
"https://codeberg.org/api/v1/repos/Starfish/TinyWeatherForecastGermany/forks",
timeout=10,
)
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}")
sys.exit(0)

with open('forks-api.json','w+',encoding='utf-8') as fh:
with open("forks-api.json", "w+", encoding="utf-8") as fh:
fh.write(str(json.dumps(forks_req_json, indent=4)))

#with open('forks-api.json','r',encoding='utf-8') as fh:
# with open('forks-api.json','r',encoding='utf-8') as fh:
# forks_req_json = json.loads(str(fh.read()))


def get_commits_json(clone_url, fork_id):
print(f"analyzing '{clone_url}' ... ")

Expand All @@ -28,30 +35,31 @@ def get_commits_json(clone_url, fork_id):

for commit in Repository(clone_url).traverse_commits():
commit_dict = {}
commit_dict['hash'] = str(commit.hash)
commit_dict['msg'] = str(commit.msg)
commit_dict['author_name'] = str(commit.author.name)
#commit_dict['branches'] = commit.branches
commit_dict["hash"] = str(commit.hash)
commit_dict["msg"] = str(commit.msg)
commit_dict["author_name"] = str(commit.author.name)
# commit_dict['branches'] = commit.branches

#commit_dict['mod_files'] = []
#for file in commit.modified_files:
# commit_dict['mod_files'] = []
# for file in commit.modified_files:
# commit_dict['mod_files'].append(str(file.filename))
mermaid_str += ' commit id:"'+str(commit.hash)[0:6]+'"\n'

mermaid_str += ' commit id:"' + str(commit.hash)[0:6] + '"\n'

commits_list.append(commit_dict)
del commit_dict

with open(f"fork-{fork_id}.json",'w+',encoding='utf-8') as fh:
with open(f"fork-{fork_id}.json", "w+", encoding="utf-8") as fh:
fh.write(str(json.dumps(commits_list, indent=4)))
del commits_list

with open(f"fork-{fork_id}.mermaid",'w+',encoding='utf-8') as fh:
with open(f"fork-{fork_id}.mermaid", "w+", encoding="utf-8") as fh:
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'])
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())
53 changes: 27 additions & 26 deletions git_log2graphviz.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

from pprint import pprint
import json
import os
import re
from pprint import pprint

from pydriller import Repository

Expand All @@ -11,50 +10,52 @@
dot_graph_1 = """
digraph G {
"""
dot_graph_2 = ''
dot_graph_2 = ""

# if repo not cloned yet -> Repository("https://codeberg.org/Starfish/TinyWeatherForecastGermany.git")
for commit in Repository(f"TinyWeatherForecastGermany/").traverse_commits():
for commit in Repository("TinyWeatherForecastGermany/").traverse_commits():
commit_dict = {}
commit_dict['hash'] = str(commit.hash)
commit_dict['msg'] = str(commit.msg).replace('"',"'")

commit_dict['timestamp'] = str(commit.committer_date)

commit_dict['author_name'] = str(commit.author.name)
commit_dict['branches'] = list(commit.branches)
commit_dict['parents'] = list(commit.parents)
commit_dict['merge'] = commit.merge
c_color = ''
if commit_dict['merge']: #'merge pull' in str(commit_dict['msg']).lower():
c_color = ',color=blue'
commit_dict["hash"] = str(commit.hash)
commit_dict["msg"] = str(commit.msg).replace('"', "'")

commit_dict["timestamp"] = str(commit.committer_date)

commit_dict["author_name"] = str(commit.author.name)
commit_dict["branches"] = list(commit.branches)
commit_dict["parents"] = list(commit.parents)
commit_dict["merge"] = commit.merge

c_color = ""
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"

c_parents_len = len(commit_dict['parents'])
c_parents_len = len(commit_dict["parents"])
if c_parents_len > 0:
for c_parent in commit_dict['parents']:
for c_parent in commit_dict["parents"]:
dot_graph_2 += f"\t \"{c_parent}\" -> \"{commit_dict['hash']}\";\n"

commits_list.append(commit_dict)
del commit_dict

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

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

with open(f"git_graph.dot",'w+',encoding='utf-8') as fh:
with open("git_graph.dot", "w+", encoding="utf-8") as fh:
fh.write(str(dot_graph_1))

os.system("dot -Tsvg -o git_graph.svg git_graph.dot")

svg_contents = ''
with open(f"git_graph.svg",'r',encoding='utf-8') as fh:
svg_contents = ""
with open("git_graph.svg", "r", encoding="utf-8") as fh:
svg_contents = str(fh.read())

svg_contents = re.sub(r'(?im)[\r\n]*\<!\-\-[\w \?\&\#\;\,\:\+]+\-\-\>[\r\n]*','',str(svg_contents))
svg_contents = re.sub(
r"(?im)[\r\n]*\<!\-\-[\w \?\&\#\;\,\:\+]+\-\-\>[\r\n]*", "", str(svg_contents)
)

with open(f"git_graph.svg",'w+',encoding='utf-8') as fh:
with open("git_graph.svg", "w+", encoding="utf-8") as fh:
fh.write(str(svg_contents))
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PyDriller==2.4.1
requests==2.30.0
PyDriller==2.5
requests==2.31.0

0 comments on commit c7abbd8

Please sign in to comment.