Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts to automatically detect deleted tests #427

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions auto-check-deleted/find_all_deleted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import pandas as pd
import subprocess
from glob import glob
import os
import shutil
from tqdm import tqdm
import json

archieved = [
"https://github.com/gooddata/GoodData-CL"
]


df = pd.read_csv("../pr-data.csv")
error_log = []
test_file_deleted = []
test_method_deleted = []
base_dir = os.getcwd()

df = df.groupby("Project URL").agg(lambda x: list(x))

for url, row in tqdm(df.iterrows(), total=df.shape[0]):

testname_list, status_list, note_list = row["Fully-Qualified Test Name (packageName.ClassName.methodName)"], row["Status"], row["Notes"]
print("url", url)
if url in archieved:
print("this url has been archieved! skip")
continue

clone_cmd = "git clone --quiet {} tmp && cd tmp".format(url)
subprocess.run(clone_cmd, shell=True, stdout=open(os.devnull, 'wb'))
print("clone done!!!")
for full_testname, status, note in zip(testname_list, status_list, note_list):
testfile_name, test_method_name = full_testname.split(".")[-2], full_testname.split(".")[-1]

if pd.isna(status) and pd.isna(note):

if "[" in test_method_name or "\"" in test_method_name:
print("{}, {} is a PUT; skip".format(url, full_testname))
continue
if testfile_name[-4:] != "Test":

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many tests in pr-data.csv have "Test" in the beginning instead of the end.

error_log.append("{}, {}".format(url, full_testname))
continue

fnames = glob("**/{}.java".format(testfile_name), recursive=True)
if len(fnames) == 0:
# try to get the commit id
git_find_SHA = "cd tmp && git rev-list -n 1 HEAD -- **/{}.java".format(testfile_name)
commit_SHA = subprocess.check_output(git_find_SHA, shell=True).decode("utf-8")

if len(commit_SHA) > 0:
test_file_deleted.append("{}, {}, {}".format(url, full_testname, url+"/commit/"+commit_SHA))
print("[INFO]:detected Test File " + "{}, {} was deleted at SHA {}".format(url, full_testname, commit_SHA))
# test file not found; add to log
else:
print("[INFO]: detected deleted Test File WITHOUT FINDING SHA: ", "{}, {}".format(url, full_testname))


# clean the repo and repeat
os.chdir(base_dir)
shutil.rmtree("tmp")


with open("new_test_file_deleted.json", "w") as f:
json.dump(test_file_deleted, f)






2 changes: 2 additions & 0 deletions auto-check-deleted/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandas
tqdm