From fea858ec7541d1d812e82d46350067b32ade0e57 Mon Sep 17 00:00:00 2001 From: "leo.wang" Date: Wed, 11 Sep 2024 11:40:21 +0800 Subject: [PATCH] use dev/reformat fix linit --- .../builtin/gitlab/tools/gitlab_commits.py | 18 ++++++++------- .../builtin/gitlab/tools/gitlab_files.py | 22 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/api/core/tools/provider/builtin/gitlab/tools/gitlab_commits.py b/api/core/tools/provider/builtin/gitlab/tools/gitlab_commits.py index 29f1baa21b85cc..45ab15f437e19a 100644 --- a/api/core/tools/provider/builtin/gitlab/tools/gitlab_commits.py +++ b/api/core/tools/provider/builtin/gitlab/tools/gitlab_commits.py @@ -38,9 +38,13 @@ def _invoke( # Get commit content if repository: - result = self.fetch_commits(site_url, access_token, repository, employee, start_time, end_time, change_type, is_repository=True) + result = self.fetch_commits( + site_url, access_token, repository, employee, start_time, end_time, change_type, is_repository=True + ) else: - result = self.fetch_commits(site_url, access_token, project, employee, start_time, end_time, change_type, is_repository=False) + result = self.fetch_commits( + site_url, access_token, project, employee, start_time, end_time, change_type, is_repository=False + ) return [self.create_json_message(item) for item in result] @@ -53,7 +57,7 @@ def fetch_commits( start_time: str, end_time: str, change_type: str, - is_repository: bool + is_repository: bool, ) -> list[dict[str, Any]]: domain = site_url headers = {"PRIVATE-TOKEN": access_token} @@ -62,7 +66,7 @@ def fetch_commits( try: if is_repository: # URL encode the repository path - encoded_identifier = urllib.parse.quote(identifier, safe='') + encoded_identifier = urllib.parse.quote(identifier, safe="") commits_url = f"{domain}/api/v4/projects/{encoded_identifier}/repository/commits" else: # Get all projects @@ -116,9 +120,7 @@ def fetch_commits( if line.startswith("+") and not line.startswith("+++") ] ) - results.append( - {"commit_sha": commit_sha, "author_name": author_name, "diff": final_code} - ) + results.append({"commit_sha": commit_sha, "author_name": author_name, "diff": final_code}) else: if total_changes > 1: final_code = "".join( @@ -137,4 +139,4 @@ def fetch_commits( except requests.RequestException as e: print(f"Error fetching data from GitLab: {e}") - return results \ No newline at end of file + return results diff --git a/api/core/tools/provider/builtin/gitlab/tools/gitlab_files.py b/api/core/tools/provider/builtin/gitlab/tools/gitlab_files.py index c010101d6f4b29..7606eee7af6cfb 100644 --- a/api/core/tools/provider/builtin/gitlab/tools/gitlab_files.py +++ b/api/core/tools/provider/builtin/gitlab/tools/gitlab_files.py @@ -40,13 +40,7 @@ def _invoke( return [self.create_json_message(item) for item in result] def fetch_files( - self, - site_url: str, - access_token: str, - identifier: str, - branch: str, - path: str, - is_repository: bool + self, site_url: str, access_token: str, identifier: str, branch: str, path: str, is_repository: bool ) -> list[dict[str, Any]]: domain = site_url headers = {"PRIVATE-TOKEN": access_token} @@ -55,7 +49,7 @@ def fetch_files( try: if is_repository: # URL encode the repository path - encoded_identifier = urllib.parse.quote(identifier, safe='') + encoded_identifier = urllib.parse.quote(identifier, safe="") tree_url = f"{domain}/api/v4/projects/{encoded_identifier}/repository/tree?path={path}&ref={branch}" else: # Get project ID from project name @@ -71,13 +65,17 @@ def fetch_files( for item in items: item_path = item["path"] if item["type"] == "tree": # It's a directory - results.extend(self.fetch_files(site_url, access_token, identifier, branch, item_path, is_repository)) + results.extend( + self.fetch_files(site_url, access_token, identifier, branch, item_path, is_repository) + ) else: # It's a file if is_repository: file_url = f"{domain}/api/v4/projects/{encoded_identifier}/repository/files/{item_path}/raw?ref={branch}" else: - file_url = f"{domain}/api/v4/projects/{project_id}/repository/files/{item_path}/raw?ref={branch}" - + file_url = ( + f"{domain}/api/v4/projects/{project_id}/repository/files/{item_path}/raw?ref={branch}" + ) + file_response = requests.get(file_url, headers=headers) file_response.raise_for_status() file_content = file_response.text @@ -99,4 +97,4 @@ def get_project_id(self, site_url: str, access_token: str, project_name: str) -> return project["id"] except requests.RequestException as e: print(f"Error fetching project ID from GitLab: {e}") - return None \ No newline at end of file + return None