Skip to content

Commit 9fec188

Browse files
committed
feat: graph display
1 parent 01ae24d commit 9fec188

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
FROM williamfzc/srctx:v0.4.1
1+
FROM williamfzc/srctx:v0.4.2
22

3-
RUN apk add --no-cache python3 py3-pip
3+
RUN apk add --no-cache python3 py3-pip graphviz
44

55
COPY . /action_internal
66

main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
import csv
23
import json
34
import os
@@ -15,6 +16,7 @@
1516
support_langs = {"golang", "python"}
1617
csv_result_file = "./output.csv"
1718
json_result_file = "./output.json"
19+
dot_result_file = "./output.dot"
1820

1921

2022
def gen_index(lang: str):
@@ -64,6 +66,8 @@ def gen_diff(before_sha: str, after_sha: str):
6466
csv_result_file,
6567
"--outputJson",
6668
json_result_file,
69+
"--outputDot",
70+
dot_result_file,
6771
]
6872
)
6973

@@ -132,6 +136,13 @@ def format_percentage(numerator, denominator):
132136
writer.writerow(row)
133137

134138

139+
def dot_to_svg_tag(dot_file):
140+
svg_bytes = subprocess.check_output(["dot", "-Tsvg", dot_file])
141+
svg_base64 = base64.b64encode(svg_bytes).decode()
142+
svg = f'<img src="data:image/svg+xml;base64,{svg_base64}"/>'
143+
return svg
144+
145+
135146
def main():
136147
args = sys.argv[1:]
137148
lang = args[0]
@@ -172,12 +183,15 @@ def main():
172183
logger.info(f"ai resp: {ai_content}")
173184

174185
repo_name = os.getenv("GITHUB_REPOSITORY")
175-
process_json(csv_result_file)
186+
process_json(json_result_file, csv_result_file)
176187
md_table_raw = convert_csv_to_md(csv_result_file)
188+
svg_tag = dot_to_svg_tag(dot_result_file)
177189

178190
final_content = f"""
179191
## [DiffCtx](https://github.com/williamfzc/diffctx) Report
180192
193+
{svg_tag}
194+
181195
{md_table_raw}
182196
"""
183197
logger.info(f"final comment: {final_content}")

0 commit comments

Comments
 (0)