|
1 | 1 | import shutil |
| 2 | +from pathlib import Path |
2 | 3 |
|
3 | 4 | import click |
4 | 5 |
|
5 | 6 | import afterpython as ap |
6 | 7 |
|
7 | 8 |
|
8 | | -def create_workflow(workflow_name: str): |
9 | | - if ".yml" in workflow_name: |
10 | | - workflow_name = workflow_name.replace(".yml", "") |
11 | | - |
12 | | - user_path = ap.paths.user_path |
13 | | - workflow_dir = user_path / ".github" / "workflows" |
14 | | - workflow_path = workflow_dir / f"{workflow_name}.yml" |
15 | | - |
16 | | - if workflow_path.exists(): |
17 | | - click.echo( |
18 | | - f"GitHub Actions {workflow_name} workflow {workflow_path} already exists" |
19 | | - ) |
| 9 | +def _copy_github_template(template_name: str, target_path: Path): |
| 10 | + """Helper to copy GitHub-related templates""" |
| 11 | + if target_path.exists(): |
| 12 | + click.echo(f"{target_path} already exists") |
20 | 13 | return |
21 | 14 |
|
22 | | - # Create .github/workflows directory if it doesn't exist |
23 | | - workflow_dir.mkdir(parents=True, exist_ok=True) |
| 15 | + # Create parent directory if it doesn't exist |
| 16 | + target_path.parent.mkdir(parents=True, exist_ok=True) |
24 | 17 |
|
25 | 18 | # Copy template from package |
26 | | - template_path = ap.paths.templates_path / f"{workflow_name}-workflow-template.yml" |
| 19 | + template_path = ap.paths.templates_path / template_name |
27 | 20 | if not template_path.exists(): |
28 | 21 | raise FileNotFoundError( |
29 | 22 | f"Template file not found: {template_path}\n" |
30 | 23 | "This might indicate a corrupted installation. Please reinstall afterpython." |
31 | 24 | ) |
32 | 25 |
|
33 | | - shutil.copy(template_path, workflow_path) |
34 | | - click.echo(f"Created {workflow_path}") |
| 26 | + shutil.copy(template_path, target_path) |
| 27 | + click.echo(f"Created {target_path}") |
| 28 | + |
| 29 | + |
| 30 | +def create_workflow(workflow_name: str): |
| 31 | + """Create a GitHub Actions workflow from template""" |
| 32 | + if ".yml" in workflow_name: |
| 33 | + workflow_name = workflow_name.replace(".yml", "") |
| 34 | + |
| 35 | + user_path = ap.paths.user_path |
| 36 | + workflow_path = user_path / ".github" / "workflows" / f"{workflow_name}.yml" |
| 37 | + template_name = f"{workflow_name}-workflow-template.yml" |
| 38 | + |
| 39 | + _copy_github_template(template_name, workflow_path) |
| 40 | + |
| 41 | + |
| 42 | +def create_dependabot(): |
| 43 | + """Create Dependabot configuration for GitHub Actions updates""" |
| 44 | + user_path = ap.paths.user_path |
| 45 | + dependabot_path = user_path / ".github" / "dependabot.yml" |
| 46 | + template_name = "dependabot-template.yml" |
| 47 | + |
| 48 | + _copy_github_template(template_name, dependabot_path) |
0 commit comments