|
1 | 1 | import os |
2 | | -from typing import Optional |
| 2 | +from typing import Optional, Tuple |
3 | 3 | from pathlib import Path |
4 | 4 | import logging |
5 | 5 | from subprocess import check_call, CalledProcessError, getoutput |
@@ -41,42 +41,47 @@ def change_log_new(package_folder: str, lastest_pypi_version: bool) -> str: |
41 | 41 | return "\n".join(result[begin + 1 : end]).strip() |
42 | 42 |
|
43 | 43 |
|
44 | | -def change_log_generate( |
45 | | - package_name, |
46 | | - last_version, |
47 | | - tag_is_stable: bool = False, |
48 | | - *, |
49 | | - prefolder: Optional[str] = None, |
50 | | - is_multiapi: bool = False, |
51 | | -): |
| 44 | +def get_version_info(package_name: str, tag_is_stable: bool = False) -> Tuple[str, str]: |
52 | 45 | from pypi_tools.pypi import PyPIClient |
53 | 46 |
|
54 | | - client = PyPIClient() |
55 | 47 | try: |
| 48 | + client = PyPIClient() |
56 | 49 | ordered_versions = client.get_ordered_versions(package_name) |
57 | 50 | last_release = ordered_versions[-1] |
58 | 51 | stable_releases = [x for x in ordered_versions if not x.is_prerelease] |
59 | | - last_stable_release = stable_releases[-1] if stable_releases else None |
| 52 | + last_stable_release = stable_releases[-1] if stable_releases else "" |
60 | 53 | if tag_is_stable: |
61 | | - last_version[-1] = str(last_stable_release) if last_stable_release else str(last_release) |
| 54 | + last_version = str(last_stable_release) if last_stable_release else str(last_release) |
62 | 55 | else: |
63 | | - last_version[-1] = str(last_release) |
| 56 | + last_version = str(last_release) |
64 | 57 | except: |
65 | | - return ("### Other Changes\n\n - Initial version", last_version) |
| 58 | + last_version = "" |
| 59 | + last_stable_release = "" |
| 60 | + return last_version, str(last_stable_release) |
| 61 | + |
| 62 | + |
| 63 | +def change_log_generate( |
| 64 | + package_name, |
| 65 | + last_version, |
| 66 | + tag_is_stable: bool = False, |
| 67 | + *, |
| 68 | + last_stable_release: Optional[str] = None, |
| 69 | + prefolder: Optional[str] = None, |
| 70 | + is_multiapi: bool = False, |
| 71 | +): |
| 72 | + if not last_version: |
| 73 | + return "### Other Changes\n\n - Initial version" |
66 | 74 |
|
67 | 75 | # try new changelog tool |
68 | 76 | if prefolder and not is_multiapi: |
69 | 77 | try: |
70 | | - return ( |
71 | | - change_log_new(str(Path(prefolder) / package_name), not (last_stable_release and tag_is_stable)), |
72 | | - last_version, |
73 | | - ) |
| 78 | + return change_log_new(str(Path(prefolder) / package_name), not (last_stable_release and tag_is_stable)) |
74 | 79 | except Exception as e: |
75 | 80 | _LOGGER.warning(f"Failed to generate changelog with breaking_change_detector: {e}") |
76 | 81 |
|
77 | 82 | # fallback to old changelog tool |
78 | 83 | _LOGGER.info("Fallback to old changelog tool") |
79 | | - return (change_log_main(f"{package_name}:pypi", f"{package_name}:latest", tag_is_stable), last_version) |
| 84 | + return change_log_main(f"{package_name}:pypi", f"{package_name}:latest", tag_is_stable) |
80 | 85 |
|
81 | 86 |
|
82 | 87 | def extract_breaking_change(changelog): |
|
0 commit comments