Add gitea-shim integration and update workflow services

This commit is contained in:
2025-06-23 13:14:20 -03:00
parent b0e9dcf3a1
commit 1b62e9c3d4
19 changed files with 2856 additions and 7 deletions

View File

@ -1,8 +1,20 @@
import re
import requests
from github import Github
import os
import logging
import sys
from pathlib import Path
# Add the gitea-shim to the path
gitea_shim_path = Path(__file__).parent.parent.parent.parent.parent / "gitea-shim" / "python"
sys.path.insert(0, str(gitea_shim_path))
try:
from gitea_shim import get_github_client, is_gitea_mode
except ImportError:
# Fallback to regular GitHub if shim is not available
from github import Github as get_github_client
is_gitea_mode = lambda: False
logger = logging.getLogger(__name__)
@ -14,7 +26,11 @@ def verify_pr_ownership(
expected_repo,
):
try:
gh = Github(os.environ.get("GITHUB_TOKEN"))
# Use the shim to get GitHub-compatible client
gh = get_github_client()
# Log which API we're using
logger.info(f"Using {'Gitea' if is_gitea_mode() else 'GitHub'} API for PR verification")
match = re.match(r"https://github.com/([^/]+)/([^/]+)/pull/(\d+)", pr_url)
if not match:

View File

@ -1,7 +1,20 @@
"""Task decomposition workflow implementation."""
import os
from github import Github
import sys
from pathlib import Path
# Add the gitea-shim to the path
gitea_shim_path = Path(__file__).parent.parent.parent.parent.parent / "gitea-shim" / "python"
sys.path.insert(0, str(gitea_shim_path))
try:
from gitea_shim import get_github_client, is_gitea_mode
except ImportError:
# Fallback to regular GitHub if shim is not available
from github import Github as get_github_client
is_gitea_mode = lambda: False
import requests
from prometheus_swarm.workflows.base import Workflow
from prometheus_swarm.utils.logging import log_section, log_key_value, log_error
@ -99,9 +112,9 @@ class RepoSummarizerWorkflow(Workflow):
check_required_env_vars(["GITHUB_TOKEN", "GITHUB_USERNAME"])
validate_github_auth(os.getenv("GITHUB_TOKEN"), os.getenv("GITHUB_USERNAME"))
# Get the default branch from GitHub
# Get the default branch from GiteaGitHubShim
try:
gh = Github(os.getenv("GITHUB_TOKEN"))
gh = GiteaGitHubShim(os.getenv("GITHUB_TOKEN"), base_url=os.getenv("GITEA_URL"))
self.context["repo_full_name"] = (
f"{self.context['repo_owner']}/{self.context['repo_name']}"
)
@ -111,6 +124,7 @@ class RepoSummarizerWorkflow(Workflow):
)
self.context["base"] = repo.default_branch
log_key_value("Default branch", self.context["base"])
log_key_value("API Mode", "GiteaGitHubShim")
except Exception as e:
log_error(e, "Failed to get default branch, using 'main'")
self.context["base"] = "main"

View File

@ -1,7 +1,20 @@
"""Task decomposition workflow implementation."""
import os
from github import Github
import sys
from pathlib import Path
# Add the gitea-shim to the path
gitea_shim_path = Path(__file__).parent.parent.parent.parent.parent / "gitea-shim" / "python"
sys.path.insert(0, str(gitea_shim_path))
try:
from gitea_shim import get_github_client, is_gitea_mode
except ImportError:
# Fallback to regular GitHub if shim is not available
from github import Github as get_github_client
is_gitea_mode = lambda: False
from prometheus_swarm.workflows.base import Workflow
from prometheus_swarm.utils.logging import log_section, log_key_value, log_error
from src.workflows.repoSummarizerAudit import phases
@ -89,10 +102,15 @@ class repoSummarizerAuditWorkflow(Workflow):
self.context["github_token"] = os.getenv("GITHUB_TOKEN")
# Enter repo directory
os.chdir(self.context["repo_path"])
gh = Github(self.context["github_token"])
# Use the shim to get GitHub-compatible client
gh = get_github_client()
repo = gh.get_repo(f"{self.context['repo_owner']}/{self.context['repo_name']}")
pr = repo.get_pull(self.context["pr_number"])
self.context["pr"] = pr
log_key_value("API Mode", "Gitea" if is_gitea_mode() else "GitHub")
# Add remote for PR's repository and fetch the branch
os.system(
f"git remote add pr_source https://github.com/{pr.head.repo.full_name}"