|
7 | 7 | import shutil
|
8 | 8 | import json
|
9 | 9 | import pathlib
|
| 10 | +import importlib |
10 | 11 |
|
11 | 12 | import click
|
12 | 13 | from spin import util
|
|
23 | 24 | )
|
24 | 25 |
|
25 | 26 |
|
| 27 | +def _get_numpy_tools(filename): |
| 28 | + filepath = pathlib.Path('tools', filename) |
| 29 | + spec = importlib.util.spec_from_file_location(filename.stem, filepath) |
| 30 | + module = importlib.util.module_from_spec(spec) |
| 31 | + spec.loader.exec_module(module) |
| 32 | + return module |
| 33 | + |
| 34 | + |
| 35 | +@click.command() |
| 36 | +@click.option( |
| 37 | + "-t", "--token", |
| 38 | + help="GitHub access token", |
| 39 | + required=True |
| 40 | +) |
| 41 | +@click.option( |
| 42 | + "--revision-range", |
| 43 | + help="<revision>..<revision>", |
| 44 | + required=True |
| 45 | +) |
| 46 | +@click.pass_context |
| 47 | +def changelog(ctx, token, revision_range): |
| 48 | + """👩 Get change log for provided revision range |
| 49 | +
|
| 50 | + \b |
| 51 | + Example: |
| 52 | +
|
| 53 | + \b |
| 54 | + $ spin authors -t $GH_TOKEN --revision-range v1.25.0..v1.26.0 |
| 55 | + """ |
| 56 | + try: |
| 57 | + from github.GithubException import GithubException |
| 58 | + from git.exc import GitError |
| 59 | + changelog = _get_numpy_tools(pathlib.Path('changelog.py')) |
| 60 | + except ModuleNotFoundError as e: |
| 61 | + raise click.ClickException( |
| 62 | + f"{e.msg}. Install the missing packages to use this command." |
| 63 | + ) |
| 64 | + click.secho( |
| 65 | + f"Generating change log for range {revision_range}", |
| 66 | + bold=True, fg="bright_green", |
| 67 | + ) |
| 68 | + try: |
| 69 | + changelog.main(token, revision_range) |
| 70 | + except GithubException as e: |
| 71 | + raise click.ClickException( |
| 72 | + f"GithubException raised with status: {e.status} " |
| 73 | + f"and message: {e.data['message']}" |
| 74 | + ) |
| 75 | + except GitError as e: |
| 76 | + raise click.ClickException( |
| 77 | + f"Git error in command `{' '.join(e.command)}` " |
| 78 | + f"with error message: {e.stderr}" |
| 79 | + ) |
| 80 | + |
| 81 | + |
26 | 82 | @click.command()
|
27 | 83 | @click.option(
|
28 | 84 | "-j", "--jobs",
|
|
0 commit comments