Skip to content

Commit 75306ef

Browse files
committed
chore: debug mode for test
1 parent b3a8180 commit 75306ef

File tree

9 files changed

+64
-42
lines changed

9 files changed

+64
-42
lines changed

.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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ RUN curl -fLo scip-linux-amd64.tar.gz https://github.com/sourcegraph/scip/releas
1515
&& chmod +x ./scip
1616

1717
# java/kotlin/scala scip/lsif
18-
RUN apk add openjdk17 \
18+
RUN apk add openjdk11 gradle maven \
19+
&& echo $JAVA_HOME \
1920
&& curl -fLo coursier https://git.io/coursier-cli \
2021
&& chmod +x coursier \
2122
&& ./coursier bootstrap --standalone -o scip-java com.sourcegraph:scip-java_2.13:0.8.18 --main com.sourcegraph.scip_java.ScipJava \

action.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ 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
3236
runs:
3337
using: 'docker'
3438
image: 'Dockerfile'
@@ -39,3 +43,4 @@ runs:
3943
- ${{ inputs.repo_token }}
4044
- ${{ inputs.issue_number }}
4145
- ${{ inputs.openai_api_key }}
46+
- ${{ inputs.debug_mode }}

debug.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from index import gen_index
2+
from utils import check_call
3+
4+
5+
def debug_main():
6+
# pull some repos for test
7+
check_call(["git", "clone", "--depth=1", "https://github.com/gin-gonic/gin.git"])
8+
check_call(["git", "clone", "--depth=1", "https://github.com/alibaba/jvm-sandbox"])
9+
10+
gen_index("golang", "gin")
11+
gen_index("java", "jvm-sandbox")

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: 20 additions & 3 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,12 @@ def main():
2431
repo_token = args[3]
2532
issue_number = args[4]
2633
openai_api_key = args[5]
34+
debug_mode = args[6]
35+
36+
if debug_mode:
37+
logger.warning("in debug mode, start testing")
38+
debug_main()
39+
logger.warning("debug mode end")
2740

2841
# check
2942
if lang not in support_langs:
@@ -38,7 +51,11 @@ def main():
3851
return
3952

4053
# data prepare
41-
gen_index(lang)
54+
set_safe_git_dir()
55+
files = os.listdir(user_dir)
56+
logger.info(f"files: {files}")
57+
58+
gen_index(lang, user_dir)
4259
gen_diff(before_sha, after_sha)
4360

4461
with open(csv_result_file, encoding="utf-8") as f:

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)