| 61 | |
| 62 | |
| 63 | class CommitList: |
| 64 | # NB: Private ctor. Use `from_existing` or `create_new`. |
| 65 | def __init__(self, path: str, commits: List[Commit]): |
| 66 | self.path = path |
| 67 | self.commits = commits |
| 68 | |
| 69 | @staticmethod |
| 70 | def from_existing(path): |
| 71 | commits = CommitList.read_from_disk(path) |
| 72 | return CommitList(path, commits) |
| 73 | |
| 74 | @staticmethod |
| 75 | def create_new(path, base_version, new_version): |
| 76 | if os.path.exists(path): |
| 77 | raise ValueError( |
| 78 | "Attempted to create a new commitlist but one exists already!" |
| 79 | ) |
| 80 | commits = CommitList.get_commits_between(base_version, new_version) |
| 81 | return CommitList(path, commits) |
| 82 | |
| 83 | @staticmethod |
| 84 | def read_from_disk(path) -> List[Commit]: |
| 85 | with open(path) as csvfile: |
| 86 | reader = csv.DictReader(csvfile) |
| 87 | rows = [] |
| 88 | for row in reader: |
| 89 | if row.get("new_title", "") != "": |
| 90 | row["title"] = row["new_title"] |
| 91 | filtered_rows = {k: row.get(k, "") for k in commit_fields} |
| 92 | rows.append(Commit(**filtered_rows)) |
| 93 | return rows |
| 94 | |
| 95 | def write_result(self): |
| 96 | self.write_to_disk_static(self.path, self.commits) |
| 97 | |
| 98 | @staticmethod |
| 99 | def write_to_disk_static(path, commit_list): |
| 100 | os.makedirs(Path(path).parent, exist_ok=True) |
| 101 | with open(path, "w") as csvfile: |
| 102 | writer = csv.writer(csvfile) |
| 103 | writer.writerow(commit_fields) |
| 104 | for commit in commit_list: |
| 105 | writer.writerow(dataclasses.astuple(commit)) |
| 106 | |
| 107 | @staticmethod |
| 108 | def keywordInFile(file, keywords): |
| 109 | for key in keywords: |
| 110 | if key in file: |
| 111 | return True |
| 112 | return False |
| 113 | |
| 114 | @staticmethod |
| 115 | def gen_commit(commit_hash): |
| 116 | feature_item = get_commit_data_cache().get(commit_hash) |
| 117 | features = features_to_dict(feature_item) |
| 118 | category, topic = CommitList.categorize(features) |
| 119 | a1, a2, a3 = (features["accepters"] + ("", "", ""))[:3] |
| 120 | if features["pr_number"] is not None: |
no outgoing calls
no test coverage detected
searching dependent graphs…