90 lines
3.2 KiB
Python
90 lines
3.2 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to verify Gitea integration with Nomad MCP.
|
|
This script tests the basic functionality of the Gitea client.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from dotenv import load_dotenv
|
|
from app.services.gitea_client import GiteaClient
|
|
|
|
# Load environment variables from .env file
|
|
load_dotenv()
|
|
|
|
def main():
|
|
print("Testing Gitea integration with Nomad MCP...")
|
|
|
|
# Check if Gitea API URL is configured
|
|
gitea_api_url = os.getenv("GITEA_API_URL")
|
|
if not gitea_api_url:
|
|
print("Error: GITEA_API_URL is not configured in .env file.")
|
|
print("Please configure the Gitea API URL and try again.")
|
|
sys.exit(1)
|
|
|
|
# Check if authentication is configured
|
|
gitea_token = os.getenv("GITEA_API_TOKEN")
|
|
gitea_username = os.getenv("GITEA_USERNAME")
|
|
gitea_password = os.getenv("GITEA_PASSWORD")
|
|
|
|
if not gitea_token and not (gitea_username and gitea_password):
|
|
print("Warning: No authentication configured for Gitea API.")
|
|
print("You might not be able to access protected repositories.")
|
|
|
|
# Initialize the Gitea client
|
|
gitea_client = GiteaClient()
|
|
|
|
# Test listing repositories
|
|
print("\nTesting repository listing...")
|
|
repositories = gitea_client.list_repositories(limit=5)
|
|
|
|
if not repositories:
|
|
print("No repositories found or error occurred.")
|
|
else:
|
|
print(f"Found {len(repositories)} repositories:")
|
|
for repo in repositories:
|
|
print(f" - {repo.get('full_name')}: {repo.get('html_url')}")
|
|
|
|
# Test parsing repository URLs
|
|
print("\nTesting repository URL parsing...")
|
|
test_urls = [
|
|
f"{gitea_api_url.replace('/api/v1', '')}/username/repo-name",
|
|
"http://gitea.internal.example.com/org/project",
|
|
"https://gitea.example.com/user/repository",
|
|
]
|
|
|
|
for url in test_urls:
|
|
try:
|
|
owner, repo = gitea_client.parse_repo_url(url)
|
|
print(f" {url} -> Owner: {owner}, Repo: {repo}")
|
|
except ValueError as e:
|
|
print(f" {url} -> Error: {str(e)}")
|
|
|
|
# If we have repositories, test getting repository info for the first one
|
|
if repositories:
|
|
print("\nTesting repository info retrieval...")
|
|
first_repo = repositories[0]
|
|
repo_url = first_repo.get("html_url")
|
|
|
|
repo_info = gitea_client.get_repository_info(repo_url)
|
|
if repo_info:
|
|
print(f"Repository info for {repo_url}:")
|
|
print(f" Name: {repo_info.get('name')}")
|
|
print(f" Description: {repo_info.get('description')}")
|
|
print(f" Default branch: {repo_info.get('default_branch')}")
|
|
print(f" Stars: {repo_info.get('stars_count')}")
|
|
print(f" Forks: {repo_info.get('forks_count')}")
|
|
|
|
# Test getting branches
|
|
branches = gitea_client.get_repository_branches(repo_url)
|
|
if branches:
|
|
print(f" Branches: {', '.join([b.get('name') for b in branches])}")
|
|
else:
|
|
print(" No branches found or error occurred.")
|
|
else:
|
|
print(f"Error retrieving repository info for {repo_url}")
|
|
|
|
print("\nGitea integration test completed.")
|
|
|
|
if __name__ == "__main__":
|
|
main() |