-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciftt.py
106 lines (91 loc) · 3.35 KB
/
ciftt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
"""
CIFTT - CSV Input for Feature Triage and Tracking
A tool to create or update GitHub issues from CSV input.
"""
import typer
from csv_data import CSVData
from github import (
GitHubClient,
NewIssue,
UpdatedIssue,
extract_issue_number,
parse_repo,
)
from settings import Settings
app = typer.Typer(help="CIFTT - CSV Input for Feature Triage and Tracking")
settings = Settings()
@app.command()
def main(
csv_file: str = typer.Argument(
..., help="Path to the CSV file containing issue data"
),
repo: str = typer.Argument(..., help="GitHub repository in format 'owner/repo'"),
dry_run: bool = typer.Option(
False, "--dry-run", "-d", help="Print actions without executing them"
),
):
"""
Create or update GitHub issues from a CSV file.
"""
typer.echo(f"🔍 Reading CSV file: {csv_file}")
try:
# Load and validate the CSV data
csv_data = CSVData(csv_file)
typer.echo(f"💾 Successfully loaded CSV with {len(csv_data.data)} rows")
except Exception as e:
typer.echo(f"❌ Error: {e}")
raise typer.Exit(code=1)
try:
# Parse the repository string
owner, repo_name = parse_repo(repo)
except ValueError as e:
typer.echo(f"❌ Error: {e}")
raise typer.Exit(code=1)
typer.echo(f"🎯 Target repository: {owner}/{repo_name}")
if dry_run:
typer.echo("🧪 DRY RUN MODE: No changes will be made on GitHub")
for index, row in csv_data.data.iterrows():
issue_number = extract_issue_number(row.get("url"))
if issue_number:
typer.echo(f"Would update issue #{issue_number}: {row['title']}")
else:
typer.echo(f"Would create issue: {row['title']}")
return
# Initialize GitHub client
try:
github_client = GitHubClient(api_key=settings.github_token.get_secret_value())
typer.echo("🐙 Connected to GitHub API")
except Exception as e:
typer.echo(f"❌ Failed to initialize GitHub client: {e}")
raise typer.Exit(code=1)
# Process issues (create or update)
created_issues = []
updated_issues = []
from transform import transform_csv_to_issues
# Transform CSV data into issue instances
issues = transform_csv_to_issues(csv_data.data)
for issue in issues:
try:
if isinstance(issue, NewIssue):
# Create new issue
response = github_client.create_issue(owner, repo_name, issue)
created_issues.append(response)
typer.echo(
f"✅ Created issue #{response['number']}: {response['title']}"
)
elif isinstance(issue, UpdatedIssue):
# Update existing issue
response = github_client.update_issue(owner, repo_name, issue)
updated_issues.append(response)
typer.echo(
f"✅ Updated issue #{response['number']}: {response['title']}"
)
except Exception as e:
issue_title = getattr(issue, "title", "Unknown")
typer.echo(f"❌ Failed to process issue '{issue_title}': {e}")
typer.echo(
f"🎉 Created {len(created_issues)} issues and updated {len(updated_issues)} issues successfully"
)
if __name__ == "__main__":
app()