Skip to content

Commit 82b5422

Browse files
Refactor code in download
1 parent 5de78e2 commit 82b5422

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

app/commands/download.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,10 @@ def _download_exercise(
4848
f"Downloading {exercise} to {click.style(exercise + '/', bold=True, italic=True)}"
4949
)
5050

51+
old_config: Optional[ExerciseConfig] = None
5152
if os.path.isdir(exercise):
5253
warn(f"You already have {exercise}, removing it to download again")
5354
old_config = ExerciseConfig.read(Path(exercise), 0)
54-
if old_config.exercise_repo.repo_type == "remote" and old_config.exercise_repo.create_fork:
55-
pr_repo_full_name = old_config.exercise_repo.pr_repo_full_name
56-
if pr_repo_full_name:
57-
info(f"Closing any open PRs in {pr_repo_full_name}...")
58-
close_pr(pr_repo_full_name)
5955
rmtree(exercise)
6056

6157
os.makedirs(exercise)
@@ -101,6 +97,12 @@ def _download_exercise(
10197
warn("Setup Github and Github CLI before downloading this exercise")
10298
sys.exit(1)
10399

100+
if old_config and old_config.exercise_repo.repo_type == "remote" and old_config.exercise_repo.create_fork:
101+
pr_repo_full_name = old_config.exercise_repo.pr_repo_full_name
102+
if pr_repo_full_name:
103+
info(f"Closing any open PRs in {pr_repo_full_name}...")
104+
close_pr(pr_repo_full_name)
105+
104106
if len(config.base_files) > 0:
105107
info("Downloading base files...")
106108

0 commit comments

Comments
 (0)