Skip to content

Commit

Permalink
use dev/reformat fix linit
Browse files Browse the repository at this point in the history
  • Loading branch information
wlrnet committed Sep 11, 2024
1 parent 9917730 commit fea858e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
18 changes: 10 additions & 8 deletions api/core/tools/provider/builtin/gitlab/tools/gitlab_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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}
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -137,4 +139,4 @@ def fetch_commits(
except requests.RequestException as e:
print(f"Error fetching data from GitLab: {e}")

return results
return results
22 changes: 10 additions & 12 deletions api/core/tools/provider/builtin/gitlab/tools/gitlab_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
return None

0 comments on commit fea858e

Please sign in to comment.