feat: Implement automatic git repository configuration detection for Gitea
Some checks failed
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / code-quality (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled

- Add GiteaConfig.from_git_repository() method for auto-detection
- Support HTTP(S) and SSH git remote URL formats
- Parse gitea_url, repo_owner, repo_name from git remote origin
- Only requires GITEA_API_TOKEN environment variable
- Update GiteaClient to use auto-detection as primary method
- Maintain backward compatibility with environment variables
- Fix issue creation API to use label IDs instead of names
- Add comprehensive error handling and validation
- Successfully tested with issues #33 and #34

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-28 23:27:13 +02:00
parent ad355f970c
commit ad25b2a7d7
4 changed files with 221 additions and 6 deletions

View File

@@ -55,7 +55,8 @@ class GiteaApiClient:
if issue_data.milestone:
payload["milestone"] = issue_data.milestone
if issue_data.labels:
payload["labels"] = issue_data.labels
# Convert label names to label IDs
payload["labels"] = self._resolve_label_ids(issue_data.labels)
data = self.http.post(self.config.issues_api_url, payload)
return self._parse_issue(data)
@@ -148,8 +149,17 @@ class GiteaApiClient:
if data.get('milestone'):
milestone = self._parse_milestone(data['milestone'])
# Check if this is an error response
if 'message' in data and 'url' in data and 'number' not in data and 'id' not in data:
raise GiteaError(f"API Error: {data.get('message', 'Unknown error')} (URL: {data.get('url', 'N/A')})")
# Handle both 'number' and 'id' fields (Gitea API might use either)
issue_number = data.get('number') or data.get('id')
if issue_number is None:
raise GiteaError(f"Issue response missing both 'number' and 'id' fields. Available fields: {list(data.keys())}")
return Issue(
number=data['number'],
number=issue_number,
title=data['title'],
body=data.get('body', ''),
state=data['state'],
@@ -200,4 +210,32 @@ class GiteaApiClient:
"""Parse datetime from API response."""
# Remove Z and microseconds for consistent parsing
date_str = date_str.replace('Z', '').split('.')[0]
return datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S')
return datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S')
def _resolve_label_ids(self, label_names: List[str]) -> List[int]:
"""Convert label names to label IDs for API calls."""
try:
# Get all labels for the repository
labels_data = self.http.get(self.config.labels_api_url)
if not isinstance(labels_data, list):
raise GiteaError("Invalid labels response format")
# Create name-to-ID mapping
label_map = {label_data['name']: label_data['id'] for label_data in labels_data}
# Resolve names to IDs
label_ids = []
for name in label_names:
if name in label_map:
label_ids.append(label_map[name])
else:
# If label doesn't exist, we could create it or skip it
# For now, let's skip non-existent labels
print(f"Warning: Label '{name}' not found, skipping")
return label_ids
except Exception as e:
# If label resolution fails, proceed without labels rather than failing entirely
print(f"Warning: Could not resolve labels: {e}")
return []