Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions integrations/github/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ name = "github-haystack"
dynamic = ["version"]
description = 'Haystack components for interacting with GitHub repositories'
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.10"
license = "Apache-2.0"
keywords = []
authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
classifiers = [
"License :: OSI Approved :: Apache Software License",
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = ["haystack-ai>=2.12.0"]
dependencies = ["haystack-ai>=2.22.0"]

[project.urls]
Source = "https://github.com/deepset-ai/haystack-core-integrations/github"
Expand Down Expand Up @@ -77,7 +76,6 @@ check_untyped_defs = true
disallow_incomplete_defs = true

[tool.ruff]
target-version = "py39"
line-length = 120

[tool.ruff.lint]
Expand Down Expand Up @@ -124,10 +122,6 @@ ignore = [
"B008",
"S101",
]
unfixable = [
# Don't touch unused imports
"F401",
]

[tool.ruff.lint.isort]
known-first-party = ["haystack_integrations"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
from base64 import b64decode, b64encode
from enum import Enum
from typing import Any, Optional, Union
from typing import Any

import requests
from haystack import component, default_from_dict, default_to_dict, logging
Expand Down Expand Up @@ -79,7 +79,7 @@ def __init__(
self,
*,
github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
repo: Optional[str] = None,
repo: str | None = None,
branch: str = "main",
raise_on_failure: bool = True,
):
Expand Down Expand Up @@ -145,7 +145,7 @@ def _update_file(self, owner: str, repo: str, path: str, content: str, message:
def _check_last_commit(self, owner: str, repo: str, branch: str) -> bool:
"""Check if last commit was made by the current token user."""
url = f"https://api.github.com/repos/{owner}/{repo}/commits"
params: dict[str, Union[str, int]] = {"per_page": 1, "sha": branch}
params: dict[str, str | int] = {"per_page": 1, "sha": branch}
response = requests.get(url, headers=self._get_request_headers(), params=params, timeout=10)
response.raise_for_status()
last_commit = response.json()[0]
Expand Down Expand Up @@ -191,7 +191,7 @@ def _undo_changes(self, owner: str, repo: str, payload: dict[str, Any], branch:
commits_url = f"https://api.github.com/repos/{owner}/{repo}/commits"

# Get the previous commit SHA
params: dict[str, Union[str, int]] = {"per_page": 2, "sha": branch}
params: dict[str, str | int] = {"per_page": 2, "sha": branch}
commits = requests.get(commits_url, headers=self._get_request_headers(), params=params, timeout=10).json()
previous_sha = commits[1]["sha"]

Expand Down Expand Up @@ -244,10 +244,10 @@ def _delete_file(self, owner: str, repo: str, payload: dict[str, str], branch: s
@component.output_types(result=str)
def run(
self,
command: Union[Command, str],
command: Command | str,
payload: dict[str, Any],
repo: Optional[str] = None,
branch: Optional[str] = None,
repo: str | None = None,
branch: str | None = None,
) -> dict[str, str]:
"""
Process GitHub file operations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0
import re
from typing import Any, Optional
from typing import Any

import requests
from haystack import Document, component, default_from_dict, default_to_dict, logging
Expand Down Expand Up @@ -37,7 +37,7 @@ class GitHubIssueViewer:
def __init__(
self,
*,
github_token: Optional[Secret] = None,
github_token: Secret | None = None,
raise_on_failure: bool = True,
retry_attempts: int = 2,
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0
import re
from typing import Any, Optional
from typing import Any

import requests
from haystack import component, default_from_dict, default_to_dict, logging
Expand Down Expand Up @@ -102,7 +102,7 @@ def _check_fork_exists(self, repo: str, fork_owner: str) -> bool:
except requests.RequestException:
return False

def _create_fork(self, owner: str, repo: str) -> Optional[str]:
def _create_fork(self, owner: str, repo: str) -> str | None:
"""Create a fork of the repository."""
url = f"https://api.github.com/repos/{owner}/{repo}/forks"
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
import re
import time
from typing import Any, Optional
from typing import Any

import requests
from haystack import component, default_from_dict, default_to_dict, logging
Expand Down Expand Up @@ -137,7 +137,7 @@ def _get_authenticated_user(self) -> str:
response.raise_for_status()
return response.json()["login"]

def _get_existing_repository(self, repo_name: str) -> Optional[str]:
def _get_existing_repository(self, repo_name: str) -> str | None:
"""
Check if a repository with the given name already exists in the authenticated user's account.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0
import base64
from dataclasses import dataclass
from typing import Any, Optional
from typing import Any

import requests
from haystack import Document, component, default_from_dict, default_to_dict, logging
Expand All @@ -21,7 +21,7 @@ class GitHubItem:
path: str
size: int
url: str
content: Optional[str] = None
content: str | None = None


@component
Expand Down Expand Up @@ -71,10 +71,10 @@ class GitHubRepoViewer:
def __init__(
self,
*,
github_token: Optional[Secret] = None,
github_token: Secret | None = None,
raise_on_failure: bool = True,
max_file_size: int = 1_000_000, # 1MB default limit
repo: Optional[str] = None,
repo: str | None = None,
branch: str = "main",
):
"""
Expand Down Expand Up @@ -207,7 +207,7 @@ def _create_error_document(self, error: Exception, path: str) -> Document:
)

@component.output_types(documents=list[Document])
def run(self, path: str, repo: Optional[str] = None, branch: Optional[str] = None) -> dict[str, list[Document]]:
def run(self, path: str, repo: str | None = None, branch: str | None = None) -> dict[str, list[Document]]:
"""
Process a GitHub repository path and return documents.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Callable, Optional, Union
from collections.abc import Callable
from typing import Any

from haystack.core.serialization import generate_qualified_class_name
from haystack.tools import ComponentTool
Expand All @@ -20,16 +21,16 @@ class GitHubFileEditorTool(ComponentTool):
def __init__(
self,
*,
name: Optional[str] = "file_editor",
description: Optional[str] = FILE_EDITOR_PROMPT,
parameters: Optional[dict[str, Any]] = FILE_EDITOR_SCHEMA,
name: str | None = "file_editor",
description: str | None = FILE_EDITOR_PROMPT,
parameters: dict[str, Any] | None = FILE_EDITOR_SCHEMA,
github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
repo: Optional[str] = None,
repo: str | None = None,
branch: str = "main",
raise_on_failure: bool = True,
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
inputs_from_state: Optional[dict[str, str]] = None,
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
inputs_from_state: dict[str, str] | None = None,
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
):
"""
Initialize the GitHub file editor tool.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Callable, Optional, Union
from collections.abc import Callable
from typing import Any

from haystack.core.serialization import generate_qualified_class_name
from haystack.tools import ComponentTool
Expand All @@ -20,15 +21,15 @@ class GitHubIssueCommenterTool(ComponentTool):
def __init__(
self,
*,
name: Optional[str] = "issue_commenter",
description: Optional[str] = ISSUE_COMMENTER_PROMPT,
parameters: Optional[dict[str, Any]] = ISSUE_COMMENTER_SCHEMA,
name: str | None = "issue_commenter",
description: str | None = ISSUE_COMMENTER_PROMPT,
parameters: dict[str, Any] | None = ISSUE_COMMENTER_SCHEMA,
github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
raise_on_failure: bool = True,
retry_attempts: int = 2,
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
inputs_from_state: Optional[dict[str, str]] = None,
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
inputs_from_state: dict[str, str] | None = None,
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
):
"""
Initialize the GitHub issue commenter tool.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Callable, Optional, Union
from collections.abc import Callable
from typing import Any

from haystack.core.serialization import generate_qualified_class_name
from haystack.tools import ComponentTool
Expand All @@ -20,15 +21,15 @@ class GitHubIssueViewerTool(ComponentTool):
def __init__(
self,
*,
name: Optional[str] = "issue_viewer",
description: Optional[str] = ISSUE_VIEWER_PROMPT,
parameters: Optional[dict[str, Any]] = ISSUE_VIEWER_SCHEMA,
github_token: Optional[Secret] = None,
name: str | None = "issue_viewer",
description: str | None = ISSUE_VIEWER_PROMPT,
parameters: dict[str, Any] | None = ISSUE_VIEWER_SCHEMA,
github_token: Secret | None = None,
raise_on_failure: bool = True,
retry_attempts: int = 2,
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
inputs_from_state: Optional[dict[str, str]] = None,
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
inputs_from_state: dict[str, str] | None = None,
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
):
"""
Initialize the GitHub issue viewer tool.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Callable, Optional, Union
from collections.abc import Callable
from typing import Any

from haystack.core.serialization import generate_qualified_class_name
from haystack.tools import ComponentTool
Expand All @@ -20,14 +21,14 @@ class GitHubPRCreatorTool(ComponentTool):
def __init__(
self,
*,
name: Optional[str] = "pr_creator",
description: Optional[str] = PR_CREATOR_PROMPT,
parameters: Optional[dict[str, Any]] = PR_CREATOR_SCHEMA,
name: str | None = "pr_creator",
description: str | None = PR_CREATOR_PROMPT,
parameters: dict[str, Any] | None = PR_CREATOR_SCHEMA,
github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
raise_on_failure: bool = True,
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
inputs_from_state: Optional[dict[str, str]] = None,
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
inputs_from_state: dict[str, str] | None = None,
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
):
"""
Initialize the GitHub PR creator tool.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Callable, Optional, Union
from collections.abc import Callable
from typing import Any

from haystack.core.serialization import generate_qualified_class_name
from haystack.tools import ComponentTool
Expand All @@ -20,14 +21,14 @@ class GitHubRepoForkerTool(ComponentTool):
def __init__(
self,
*,
name: Optional[str] = "repo_forker",
description: Optional[str] = REPO_FORKER_PROMPT,
parameters: Optional[dict[str, Any]] = REPO_FORKER_SCHEMA,
name: str | None = "repo_forker",
description: str | None = REPO_FORKER_PROMPT,
parameters: dict[str, Any] | None = REPO_FORKER_SCHEMA,
github_token: Secret = Secret.from_env_var("GITHUB_TOKEN"),
raise_on_failure: bool = True,
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
inputs_from_state: Optional[dict[str, str]] = None,
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
inputs_from_state: dict[str, str] | None = None,
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
):
"""
Initialize the GitHub Repo Forker tool.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
#
# SPDX-License-Identifier: Apache-2.0
from typing import Any, Callable, Optional, Union
from collections.abc import Callable
from typing import Any

from haystack.core.serialization import generate_qualified_class_name
from haystack.tools import ComponentTool
Expand All @@ -20,17 +21,17 @@ class GitHubRepoViewerTool(ComponentTool):
def __init__(
self,
*,
name: Optional[str] = "repo_viewer",
description: Optional[str] = REPO_VIEWER_PROMPT,
parameters: Optional[dict[str, Any]] = REPO_VIEWER_SCHEMA,
github_token: Optional[Secret] = None,
repo: Optional[str] = None,
name: str | None = "repo_viewer",
description: str | None = REPO_VIEWER_PROMPT,
parameters: dict[str, Any] | None = REPO_VIEWER_SCHEMA,
github_token: Secret | None = None,
repo: str | None = None,
branch: str = "main",
raise_on_failure: bool = True,
max_file_size: int = 1_000_000, # 1MB default limit
outputs_to_string: Optional[dict[str, Union[str, Callable[[Any], str]]]] = None,
inputs_from_state: Optional[dict[str, str]] = None,
outputs_to_state: Optional[dict[str, dict[str, Union[str, Callable]]]] = None,
outputs_to_string: dict[str, str | Callable[[Any], str]] | None = None,
inputs_from_state: dict[str, str] | None = None,
outputs_to_state: dict[str, dict[str, str | Callable]] | None = None,
):
"""
Initialize the GitHub repository viewer tool.
Expand Down
Loading