|
5 | 5 | from typing import Optional, List |
6 | 6 | from git import Repo |
7 | 7 | from tqdm import tqdm |
| 8 | + |
| 9 | +from penify_hook.base_analyzer import BaseAnalyzer |
8 | 10 | from .api_client import APIClient |
9 | 11 |
|
10 | | -class CommitDocGenHook: |
| 12 | +class CommitDocGenHook(BaseAnalyzer): |
11 | 13 | def __init__(self, repo_path: str, api_client: APIClient, llm_client=None, jira_client=None): |
12 | | - self.repo_path = repo_path |
13 | | - self.api_client = api_client |
| 14 | + super().__init__(repo_path, api_client) |
| 15 | + |
14 | 16 | self.llm_client = llm_client # Add LLM client as an optional parameter |
15 | 17 | self.jira_client = jira_client # Add JIRA client as an optional parameter |
16 | | - self.repo = Repo(repo_path) |
17 | | - self.supported_file_types = set(self.api_client.get_supported_file_types()) |
18 | | - self.repo_details = self.get_repo_details() |
19 | | - |
20 | | - def get_repo_details(self): |
21 | | - """Get the details of the repository, including the hosting service, |
22 | | - organization name, and repository name. |
23 | | -
|
24 | | - This method checks the remote URL of the repository to determine whether |
25 | | - it is hosted on GitHub, Azure DevOps, Bitbucket, GitLab, or another |
26 | | - service. It extracts the organization (or user) name and the repository |
27 | | - name from the URL. If the hosting service is not recognized, it will |
28 | | - return "Unknown Hosting Service". The method handles potential errors |
29 | | - during the extraction process and returns a dictionary with the relevant |
30 | | - details. |
31 | | -
|
32 | | - Returns: |
33 | | - dict: A dictionary containing the organization name, repository name, and |
34 | | - hosting service. |
35 | | - """ |
36 | | - remote_url = None |
37 | | - hosting_service = "Unknown" |
38 | | - org_name = None |
39 | | - repo_name = None |
40 | | - |
41 | | - try: |
42 | | - # Get the remote URL |
43 | | - remote = self.repo.remotes.origin.url |
44 | | - remote_url = remote |
45 | | - |
46 | | - # Determine the hosting service based on the URL |
47 | | - if "github.com" in remote: |
48 | | - hosting_service = "GITHUB" |
49 | | - match = re.match(r".*github\.com[:/](.*?)/(.*?)(\.git)?$", remote) |
50 | | - elif "dev.azure.com" in remote: |
51 | | - hosting_service = "AZUREDEVOPS" |
52 | | - match = re.match(r".*dev\.azure\.com/(.*?)/(.*?)/_git/(.*?)(\.git)?$", remote) |
53 | | - elif "visualstudio.com" in remote: |
54 | | - hosting_service = "AZUREDEVOPS" |
55 | | - match = re.match(r".*@(.*?)\.visualstudio\.com/(.*?)/_git/(.*?)(\.git)?$", remote) |
56 | | - elif "bitbucket.org" in remote: |
57 | | - hosting_service = "BITBUCKET" |
58 | | - match = re.match(r".*bitbucket\.org[:/](.*?)/(.*?)(\.git)?$", remote) |
59 | | - elif "gitlab.com" in remote: |
60 | | - hosting_service = "GITLAB" |
61 | | - match = re.match(r".*gitlab\.com[:/](.*?)/(.*?)(\.git)?$", remote) |
62 | | - else: |
63 | | - hosting_service = "Unknown Hosting Service" |
64 | | - match = None |
65 | | - |
66 | | - if match: |
67 | | - org_name = match.group(1) |
68 | | - repo_name = match.group(2) |
69 | | - |
70 | | - # For Azure DevOps, adjust the group indices |
71 | | - if hosting_service == "AZUREDEVOPS": |
72 | | - repo_name = match.group(3) |
73 | | - |
74 | | - except Exception as e: |
75 | | - print(f"Error determining repo details: {e}") |
76 | | - |
77 | | - org_name = org_name if org_name else "UNKNOWN_ORG" |
78 | | - repo_name = repo_name if repo_name else "UNKNOWN_REPO" |
79 | | - |
80 | | - return { |
81 | | - "organization_name": org_name, |
82 | | - "repo_name": repo_name, |
83 | | - "vendor": hosting_service |
84 | | - } |
85 | 18 |
|
86 | 19 | def get_summary(self, instruction: str): |
87 | 20 | """Generate a summary for the commit based on the staged changes. |
|
0 commit comments