Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ def list_commands(self, ctx):
return self.commands.keys()


@click.group(cls=ReleaseHelperGroup)
@click.group(cls=ReleaseHelperGroup) # type:ignore[arg-type]
@click.option("--force", default=False, help="Force a command to run even when skipped by config")
def main(force):
"""Jupyter Releaser scripts"""
pass


# Extracted common options
version_spec_options = [
version_spec_options: t.Any = [
click.option(
"--version-spec",
envvar="RH_VERSION_SPEC",
Expand All @@ -164,7 +164,7 @@ def main(force):
]


post_version_spec_options = [
post_version_spec_options: t.Any = [
click.option(
"--post-version-spec",
envvar="RH_POST_VERSION_SPEC",
Expand All @@ -179,24 +179,26 @@ def main(force):
),
]

version_cmd_options = [
version_cmd_options: t.Any = [
click.option("--version-cmd", envvar="RH_VERSION_COMMAND", help="The version command")
]


branch_options = [
branch_options: t.Any = [
click.option("--ref", envvar="RH_REF", help="The source reference"),
click.option("--branch", envvar="RH_BRANCH", help="The target branch"),
click.option("--repo", envvar="RH_REPOSITORY", help="The git repo"),
]

auth_options = [
auth_options: t.Any = [
click.option("--auth", envvar="GITHUB_ACCESS_TOKEN", help="The GitHub auth token"),
]

username_options = [click.option("--username", envvar="GITHUB_ACTOR", help="The git username")]
username_options: t.Any = [
click.option("--username", envvar="GITHUB_ACTOR", help="The git username")
]

dist_dir_options = [
dist_dir_options: t.Any = [
click.option(
"--dist-dir",
envvar="RH_DIST_DIR",
Expand All @@ -205,7 +207,7 @@ def main(force):
)
]

python_packages_options = [
python_packages_options: t.Any = [
click.option(
"--python-packages",
envvar="RH_PYTHON_PACKAGES",
Expand All @@ -215,7 +217,7 @@ def main(force):
)
]

check_imports_options = [
check_imports_options: t.Any = [
click.option(
"--check-imports",
envvar="RH_CHECK_IMPORTS",
Expand All @@ -225,20 +227,20 @@ def main(force):
)
]

dry_run_options = [
dry_run_options: t.Any = [
click.option("--dry-run", is_flag=True, envvar="RH_DRY_RUN", help="Run as a dry run")
]


git_url_options = [click.option("--git-url", help="A custom url for the git repository")]
git_url_options: t.Any = [click.option("--git-url", help="A custom url for the git repository")]


release_url_options = [
release_url_options: t.Any = [
click.option("--release-url", envvar="RH_RELEASE_URL", help="A draft GitHub release url")
]


changelog_path_options = [
changelog_path_options: t.Any = [
click.option(
"--changelog-path",
envvar="RH_CHANGELOG",
Expand All @@ -247,7 +249,7 @@ def main(force):
),
]

since_options = [
since_options: t.Any = [
click.option(
"--since",
envvar="RH_SINCE",
Expand All @@ -262,7 +264,7 @@ def main(force):
),
]

changelog_options = (
changelog_options: t.Any = (
branch_options
+ auth_options
+ changelog_path_options
Expand All @@ -277,7 +279,7 @@ def main(force):
]
)

npm_install_options = [
npm_install_options: t.Any = [
click.option(
"--npm-install-options",
envvar="RH_NPM_INSTALL_OPTIONS",
Expand All @@ -286,7 +288,7 @@ def main(force):
)
]

pydist_check_options = [
pydist_check_options: t.Any = [
click.option(
"--pydist-check-cmd",
envvar="RH_PYDIST_CHECK_CMD",
Expand Down
15 changes: 11 additions & 4 deletions jupyter_releaser/mock_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def write_to_file(name, data):
for key in data:
value = data[key]
if isinstance(value, BaseModel):
value = json.loads(value.json())
if hasattr(value, 'model_dump_json'):
value = json.loads(value.model_dump_json())
else:
value = json.loads(value.json())
result[key] = value
with open(source_file, "w") as fid:
json.dump(result, fid)
Expand Down Expand Up @@ -145,7 +148,7 @@ def list_releases(owner: str, repo: str) -> List[Release]:
@app.post("/repos/{owner}/{repo}/releases")
async def create_a_release(owner: str, repo: str, request: Request) -> Release:
"""https://docs.github.com/en/rest/releases/releases#create-a-release"""
release_id = uuid.uuid4().int
release_id = uuid.uuid4().int % (2**32 - 1)
data = await request.json()
base_url = get_mock_github_url()
url = f"{base_url}/repos/{owner}/{repo}/releases/{release_id}"
Expand Down Expand Up @@ -183,7 +186,7 @@ async def upload_a_release_asset(owner: str, repo: str, release_id: int, request
"""https://docs.github.com/en/rest/releases/assets#upload-a-release-asset"""
base_url = get_mock_github_url()
model = releases[str(release_id)]
asset_id = uuid.uuid4().int
asset_id = uuid.uuid4().int % (2**32 - 1)
name = request.query_params["name"]
with open(f"{static_dir}/{asset_id}", "wb") as fid:
async for chunk in request.stream():
Expand Down Expand Up @@ -242,7 +245,11 @@ def create_a_pull_request(owner: str, repo: str) -> PullRequest:
@app.post("/repos/{owner}/{repo}/issues/{issue_number}/labels")
def add_labels_to_an_issue(owner: str, repo: str, issue_number: int) -> BaseModel:
"""https://docs.github.com/en/rest/issues/labels#add-labels-to-an-issue"""
return BaseModel()

class _Inner(BaseModel):
pass

return _Inner()


@app.post("/repos/{owner}/{repo}/git/refs")
Expand Down