Skip to content

Commit 1077b91

Browse files
committed
chore: debug mode for test
1 parent b3a8180 commit 1077b91

10 files changed

Lines changed: 119 additions & 66 deletions

File tree

.github/workflows/main.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
on: [push, pull_request]
1+
on: [ push, pull_request ]
22

33
permissions:
44
pull-requests: write
@@ -13,17 +13,8 @@ jobs:
1313
with:
1414
fetch-depth: 0
1515

16-
- name: Python Diff Context
16+
- name: Test Action
1717
uses: ./
1818
with:
1919
lang: "python"
20-
21-
- name: Golang Diff Context
22-
uses: ./
23-
with:
24-
lang: "golang"
25-
26-
- name: Java Diff Context
27-
uses: ./
28-
with:
29-
lang: "java"
20+
debug_mode: "true"

Dockerfile

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

3-
RUN apk add --no-cache graphviz curl
3+
RUN apk add --no-cache graphviz curl git
44

55
COPY . /action_internal
66

@@ -10,15 +10,22 @@ RUN apk add --no-cache python3 py3-pip && \
1010
pip3 install --upgrade git+https://github.com/sourcegraph/lsif-py.git
1111

1212
# scip converter
13-
RUN curl -fLo scip-linux-amd64.tar.gz https://github.com/sourcegraph/scip/releases/download/v0.2.3/scip-linux-amd64.tar.gz \
14-
&& tar xf ./scip-linux-amd64.tar.gz \
15-
&& chmod +x ./scip
13+
RUN git clone https://github.com/sourcegraph/scip.git --depth=1 ./scip_repo && \
14+
cd scip_repo && \
15+
go build -o scip ./cmd && \
16+
cd .. && \
17+
cp ./scip_repo/scip . && \
18+
rm -rf ./scip_repo && \
19+
chmod +x ./scip && \
20+
scip --help
1621

1722
# java/kotlin/scala scip/lsif
18-
RUN apk add openjdk17 \
23+
RUN apk add openjdk8 gradle maven \
1924
&& curl -fLo coursier https://git.io/coursier-cli \
2025
&& chmod +x coursier \
2126
&& ./coursier bootstrap --standalone -o scip-java com.sourcegraph:scip-java_2.13:0.8.18 --main com.sourcegraph.scip_java.ScipJava \
2227
&& ./scip-java --help
2328

29+
ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk
30+
2431
ENTRYPOINT ["python3", "/action_internal/main.py"]

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ inputs:
2929
description: "api key for openai"
3030
default: ""
3131
required: false
32+
debug_mode:
33+
description: "enable debug mode if not empty"
34+
default: ""
35+
required: false
36+
lsif_file:
37+
description: "specific lsif file input"
38+
default: ""
39+
required: false
3240
runs:
3341
using: 'docker'
3442
image: 'Dockerfile'
@@ -39,3 +47,5 @@ runs:
3947
- ${{ inputs.repo_token }}
4048
- ${{ inputs.issue_number }}
4149
- ${{ inputs.openai_api_key }}
50+
- ${{ inputs.debug_mode }}
51+
- ${{ inputs.lsif_file }}

debug.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
from diff import gen_diff
4+
from index import gen_index
5+
from utils import check_call
6+
import shutil
7+
8+
9+
def debug_main():
10+
# pull some repos for test
11+
check_call(["git", "clone", "--depth=2", "https://github.com/gin-gonic/gin.git"])
12+
check_call(["git", "clone", "--depth=2", "https://github.com/google/guava.git"])
13+
14+
gen_index("golang", "gin")
15+
gen_index("java", "guava")
16+
17+
os.chdir("gin")
18+
gen_diff("HEAD~1", "HEAD", "")
19+
os.chdir("..")
20+
21+
os.chdir("guava")
22+
gen_diff("HEAD~1", "HEAD", "")
23+
os.chdir("..")
24+
25+
# clean up
26+
shutil.rmtree("gin")
27+
shutil.rmtree("guava")

diff.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@
22
from utils import check_call
33

44

5-
def gen_diff(before_sha: str, after_sha: str):
5+
def gen_diff(before_sha: str, after_sha: str, lsif_file: str):
66
# gen diff
77
set_safe_git_dir()
8-
check_call(
9-
[
10-
"srctx",
11-
"diff",
12-
"--src",
13-
user_dir,
14-
"--before",
15-
before_sha,
16-
"--after",
17-
after_sha,
18-
"--outputCsv",
19-
csv_result_file,
20-
"--outputJson",
21-
json_result_file,
22-
"--outputDot",
23-
dot_result_file,
24-
]
25-
)
8+
9+
cmds = [
10+
"srctx",
11+
"diff",
12+
"--src",
13+
user_dir,
14+
"--before",
15+
before_sha,
16+
"--after",
17+
after_sha,
18+
"--outputCsv",
19+
csv_result_file,
20+
"--outputJson",
21+
json_result_file,
22+
"--outputDot",
23+
dot_result_file,
24+
]
25+
if lsif_file:
26+
cmds += ["--lsif", lsif_file]
27+
check_call(cmds)
2628

2729

2830
def set_safe_git_dir():

index.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22

33
from loguru import logger
44

5-
from diff import set_safe_git_dir
6-
from config import user_dir
75
from utils import check_call
86

97

10-
def gen_index(lang: str):
11-
set_safe_git_dir()
12-
files = os.listdir(user_dir)
13-
logger.info(f"files: {files}")
14-
15-
if lang == "golang":
16-
gen_golang_index()
17-
elif lang == "python":
18-
gen_py_index()
19-
else:
20-
logger.error("no index mapping")
21-
return
8+
def gen_index(lang: str, directory: str):
9+
current_directory = os.getcwd()
10+
try:
11+
os.chdir(directory)
12+
if lang == "golang":
13+
gen_golang_index()
14+
elif lang == "python":
15+
gen_py_index()
16+
elif lang == "java":
17+
gen_java_and_kotlin_index()
18+
elif lang == "kotlin":
19+
gen_java_and_kotlin_index()
20+
else:
21+
logger.error("no index mapping")
22+
return
23+
finally:
24+
os.chdir(current_directory)
2225

2326

2427
def gen_golang_index():

main.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@
1010

1111
from ai import process_with_ai
1212
from comment import send_comment
13-
from config import support_langs, csv_result_file, json_result_file, dot_result_file
14-
from diff import gen_diff
13+
from config import (
14+
support_langs,
15+
csv_result_file,
16+
json_result_file,
17+
dot_result_file,
18+
user_dir,
19+
)
20+
from debug import debug_main
21+
from diff import gen_diff, set_safe_git_dir
1522
from index import gen_index
1623
from object import FileList
1724

@@ -24,6 +31,13 @@ def main():
2431
repo_token = args[3]
2532
issue_number = args[4]
2633
openai_api_key = args[5]
34+
debug_mode = args[6]
35+
lsif_file = args[7]
36+
37+
if debug_mode:
38+
logger.warning("in debug mode, start testing")
39+
debug_main()
40+
logger.warning("debug mode end")
2741

2842
# check
2943
if lang not in support_langs:
@@ -38,8 +52,13 @@ def main():
3852
return
3953

4054
# data prepare
41-
gen_index(lang)
42-
gen_diff(before_sha, after_sha)
55+
set_safe_git_dir()
56+
files = os.listdir(user_dir)
57+
logger.info(f"files: {files}")
58+
59+
if not lsif_file:
60+
gen_index(lang, user_dir)
61+
gen_diff(before_sha, after_sha, lsif_file)
4362

4463
with open(csv_result_file, encoding="utf-8") as f:
4564
content = f.read()

test_index.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from index import gen_index
2+
3+
4+
def test_index_py():
5+
gen_index("python", ".")

test_main.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import subprocess
22

3-
from config import user_dir
4-
53

64
def check_call(commands: list):
7-
subprocess.check_call(commands, cwd=user_dir)
5+
subprocess.check_call(commands)

0 commit comments

Comments
 (0)