Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Refactor Azure DevOps adapter and fix code formatting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetkca committed Dec 11, 2023
1 parent f7e5f89 commit 0e01c16
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
56 changes: 30 additions & 26 deletions llama_hub/github_repo/azure_devops.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

from typing import Any, Dict, List, Optional
from llama_hub.github_repo.github_client import (
BaseGithubClient,
GitBlobResponseModel,
GitBranchResponseModel,
GitCommitResponseModel,
GitTreeResponseModel
BaseGithubClient,
GitBlobResponseModel,
GitBranchResponseModel,
GitCommitResponseModel,
GitTreeResponseModel,
)

from azure.devops.v7_0.git.git_client import GitClient
Expand Down Expand Up @@ -39,9 +39,8 @@ class AzureDevOpsAdapter(BaseGithubClient):
- `ImportError`: If azure-devops package is not installed.
- `ValueError`: If base_url, username or password is not provided.
"""
def __init__(self,
*args: Any,
**kwargs: Any) -> None:

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
try:
from azure.devops.connection import Connection
Expand All @@ -51,12 +50,17 @@ def __init__(self,
"Please install azure-devops package to use Azure DevOps adapter"
)
if kwargs.get("base_url") is None:
raise ValueError("Azure DevOps base_url is required. Example: 'https://dev.azure.com/YOURORG'")
raise ValueError(
"Azure DevOps base_url is required. Example: 'https://dev.azure.com/YOURORG'"
)
if kwargs.get("username") is None:
raise ValueError("Azure DevOps username is required. You can leave this blank if you are using a PAT. ex: ''")
raise ValueError(
"Azure DevOps username is required. You can leave this blank if you are using a PAT. ex: ''"
)
if kwargs.get("password") is None:
raise ValueError("Azure DevOps password is required. Personal Access Token (PAT) is recommended.")

raise ValueError(
"Azure DevOps password is required. Personal Access Token (PAT) is recommended."
)

self.connection = Connection(
base_url=kwargs.get("base_url"),
Expand Down Expand Up @@ -105,13 +109,15 @@ async def get_tree(
git_tree_object_list: List[GitTreeResponseModel.GitTreeObject] = []
tree_entry: GitTreeEntryRef
for tree_entry in _git_tree_response.tree_entries:
git_tree_object: GitTreeResponseModel.GitTreeObject = GitTreeResponseModel.GitTreeObject(
path=tree_entry.relative_path,
mode=tree_entry.mode,
type=tree_entry.git_object_type,
sha=tree_entry.object_id,
url=tree_entry.url,
size=tree_entry.size,
git_tree_object: GitTreeResponseModel.GitTreeObject = (
GitTreeResponseModel.GitTreeObject(
path=tree_entry.relative_path,
mode=tree_entry.mode,
type=tree_entry.git_object_type,
sha=tree_entry.object_id,
url=tree_entry.url,
size=tree_entry.size,
)
)
git_tree_object_list.append(git_tree_object)
return GitTreeResponseModel(
Expand All @@ -121,7 +127,6 @@ async def get_tree(
truncated=False,
)


async def get_blob(
self,
owner: str,
Expand Down Expand Up @@ -167,7 +172,7 @@ async def get_blob(
encoding="utf-8",
sha=_git_blob_response.object_id,
url=_git_blob_response.url,
node_id=None
node_id=None,
)

async def get_commit(
Expand Down Expand Up @@ -200,7 +205,8 @@ async def get_commit(
tree=GitCommitResponseModel.Commit.Tree(
sha=_git_commit_response.tree_id,
),
))
),
)

async def get_branch(
self,
Expand All @@ -221,9 +227,7 @@ async def get_branch(
- `branch (GitBranchResponseModel)`: Branch response model.
"""
_git_branch_response: GitBranchStats = self._git_client.get_branch(
repository_id=repo,
project=owner,
name=branch
repository_id=repo, project=owner, name=branch
)

# get the latest commit for the branch
Expand All @@ -243,4 +247,4 @@ async def get_branch(
),
),
_links=None,
)
)
4 changes: 1 addition & 3 deletions llama_hub/github_repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from llama_index.readers.file.base import DEFAULT_FILE_READER_CLS
from llama_index.readers.schema.base import Document
from llama_hub.github_repo import github_client
from llama_hub.github_repo.azure_devops import AzureDevOpsAdapter

from llama_hub.github_repo.github_client import (
BaseGithubClient,
Expand Down Expand Up @@ -407,13 +406,12 @@ async def _generate_documents(
)
# tried to decode the content that was base64 encoded but failed
# continue
if blob_data.encoding == "base64":
if blob_data.encoding == "base64":
continue
# if the content was not base64 encoded and we failed to decode it
# as base64, then we assume it is raw text
decoded_bytes = blob_data.content


if self._use_parser:
document = self._parse_supported_file(
file_path=full_path,
Expand Down

0 comments on commit 0e01c16

Please sign in to comment.