Skip to content
Open
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
7 changes: 7 additions & 0 deletions src/ghstack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def land(force: bool, pull_request: str) -> None:
github_url=config.github_url,
remote_name=config.remote_name,
force=force,
repo_default_branch_opt=config.repo_default_branch,
)


Expand Down Expand Up @@ -271,6 +272,11 @@ def submit(
revs=revs,
stack=stack,
direct_opt=direct_opt,
repo_name_opt=config.repo_name,
repo_owner_opt=config.repo_owner,
repo_is_fork_opt=config.repo_is_fork,
repo_id_opt=config.repo_id,
repo_default_branch_opt=config.repo_default_branch,
)


Expand All @@ -287,4 +293,5 @@ def unlink(commits: List[str]) -> None:
sh=shell,
github_url=config.github_url,
remote_name=config.remote_name,
repo_default_branch_opt=config.repo_default_branch,
)
35 changes: 35 additions & 0 deletions src/ghstack/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env python3

import configparser
Expand Down Expand Up @@ -40,6 +40,16 @@
("github_url", str),
# Name of the upstream remote
("remote_name", str),
# Repository name

Check warning on line 43 in src/ghstack/config.py

View workflow job for this annotation

GitHub Actions / lint (3.11, ubuntu-latest)

FLAKE8 W291

trailing whitespace See https://www.flake8rules.com/rules/W291.html
("repo_name", Optional[str]),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, while I want to accept this PR on principle, this is not so good, it means you can only set one repo name for all ghstack uses everwhere on your machine. Any chance I can convince you to introduce a per repo configuration? :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense - will give that a stab!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking that with use of github_path in the ~/.ghstack config, I can add a check where, if $github_path/.ghstack exists, use that for per-repo config, otherwise assume no per-repo config exists. is that what you were thinking?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some precedent for just chucking stuff in .git/config (using the standard git cli for modifying it.) How do you like that?

# Repository owner / organisation
("repo_owner", Optional[str]),
# Whether the repo is a fork
("repo_is_fork", Optional[str]),
# Numeric GitHub repository ID
("repo_id", Optional[str]),
# Default branch name (e.g. "main")
("repo_default_branch", Optional[str]),
],
)

Expand Down Expand Up @@ -208,6 +218,26 @@
config.write(f)
logging.info("NB: configuration saved to {}".format(config_path))

repo_name = None
if config.has_option("repo", "name"):
repo_name = config.get("repo", "name")

repo_owner = None
if config.has_option("repo", "owner"):
repo_owner = config.get("repo", "owner")

repo_is_fork = None
if config.has_option("repo", "is_fork"):
repo_is_fork = config.getboolean("repo", "is_fork")

repo_id = None
if config.has_option("repo", "id"):
repo_id = config.get("repo", "id")

Check warning on line 235 in src/ghstack/config.py

View workflow job for this annotation

GitHub Actions / lint (3.11, ubuntu-latest)

FLAKE8 E117

over-indented See https://www.flake8rules.com/rules/E117.html

Check warning on line 235 in src/ghstack/config.py

View workflow job for this annotation

GitHub Actions / lint (3.11, ubuntu-latest)

FLAKE8 E111

indentation is not a multiple of 4 See https://www.flake8rules.com/rules/E111.html

repo_default_branch = None
if config.has_option("repo", "default_branch"):
repo_default_branch = config.get("repo", "default_branch")

Check warning on line 239 in src/ghstack/config.py

View workflow job for this annotation

GitHub Actions / lint (3.11, ubuntu-latest)

FLAKE8 E117

over-indented See https://www.flake8rules.com/rules/E117.html

Check warning on line 239 in src/ghstack/config.py

View workflow job for this annotation

GitHub Actions / lint (3.11, ubuntu-latest)

FLAKE8 E111

indentation is not a multiple of 4 See https://www.flake8rules.com/rules/E111.html

conf = Config(
github_oauth=github_oauth,
circle_token=circle_token,
Expand All @@ -218,6 +248,11 @@
default_project_dir=default_project_dir,
github_url=github_url,
remote_name=remote_name,
repo_name=repo_name,
repo_owner=repo_owner,
repo_is_fork=repo_is_fork,
repo_id=repo_id,
repo_default_branch=repo_default_branch,
)
logging.debug(f"conf = {conf}")
return conf
21 changes: 12 additions & 9 deletions src/ghstack/land.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging
import re
from typing import List, Tuple
from typing import List, Optional, Tuple

import ghstack.git
import ghstack.github
Expand Down Expand Up @@ -50,6 +50,7 @@ def main(
github_url: str,
*,
force: bool = False,
repo_default_branch_opt: Optional[str] = None,
) -> None:

# We land the entire stack pointed to by a URL.
Expand All @@ -60,14 +61,16 @@ def main(
params = ghstack.github_utils.parse_pull_request(
pull_request, sh=sh, remote_name=remote_name
)
default_branch = ghstack.github_utils.get_github_repo_info(
github=github,
sh=sh,
repo_owner=params["owner"],
repo_name=params["name"],
github_url=github_url,
remote_name=remote_name,
)["default_branch"]
default_branch = repo_default_branch_opt
if default_branch is None:
default_branch = ghstack.github_utils.get_github_repo_info(
github=github,
sh=sh,
repo_owner=params["owner"],
repo_name=params["name"],
github_url=github_url,
remote_name=remote_name,
)["default_branch"]

needs_force = False
try:
Expand Down
42 changes: 31 additions & 11 deletions src/ghstack/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ class Submitter:
# Presents as repo_name kwarg in main
repo_name_opt: Optional[str] = None

# allow configuration to optionally define repo details
repo_is_fork_opt: Optional[str] = None
repo_id_opt: Optional[str] = None
repo_default_branch_opt: Optional[str] = None

# Print only PR URL to stdout
short: bool = False

Expand Down Expand Up @@ -375,17 +380,32 @@ class Submitter:
# Post initialization

def __post_init__(self) -> None:
# Network call in the constructor, help me father, for I have sinned
repo = ghstack.github_utils.get_github_repo_info(
github=self.github,
sh=self.sh,
repo_owner=self.repo_owner_opt,
repo_name=self.repo_name_opt,
github_url=self.github_url,
remote_name=self.remote_name,
)
object.__setattr__(self, "repo_owner", repo["name_with_owner"]["owner"])
object.__setattr__(self, "repo_name", repo["name_with_owner"]["name"])
repo = {}
if (
self.repo_id_opt is not None
and self.repo_owner_opt is not None
and self.repo_name_opt is not None
and self.repo_is_fork_opt is not None
and self.repo_default_branch_opt is not None
):
repo["is_fork"] = self.repo_is_fork_opt
repo["id"] = self.repo_id_opt
repo["default_branch"] = self.repo_default_branch_opt
repo["name_with_owner"] = {}
repo["name_with_owner"]["owner"] = self.repo_owner_opt
repo["name_with_owner"]["name"] = self.repo_name_opt
else:
# Network call in the constructor, help me father, for I have sinned
repo = ghstack.github_utils.get_github_repo_info(
github=self.github,
sh=self.sh,
repo_owner=self.repo_owner_opt,
repo_name=self.repo_name_opt,
github_url=self.github_url,
remote_name=self.remote_name,
)
object.__setattr__(self, "repo_owner", repo["name_with_owner"]["owner"])
object.__setattr__(self, "repo_name", repo["name_with_owner"]["name"])

if repo["is_fork"]:
raise RuntimeError(
Expand Down
19 changes: 11 additions & 8 deletions src/ghstack/unlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def main(
repo_name: Optional[str] = None,
github_url: str,
remote_name: str,
repo_default_branch_opt: Optional[str] = None,
) -> GitCommitHash:
# If commits is empty, we unlink the entire stack
#
Expand All @@ -36,14 +37,16 @@ def main(
# Use CWD
sh = ghstack.shell.Shell()

default_branch = ghstack.github_utils.get_github_repo_info(
github=github,
sh=sh,
repo_owner=repo_owner,
repo_name=repo_name,
github_url=github_url,
remote_name=remote_name,
)["default_branch"]
default_branch = repo_default_branch_opt
if default_branch is None:
default_branch = ghstack.github_utils.get_github_repo_info(
github=github,
sh=sh,
repo_owner=repo_owner,
repo_name=repo_name,
github_url=github_url,
remote_name=remote_name,
)["default_branch"]

# Parse the commits
parsed_commits: Optional[Set[GitCommitHash]] = None
Expand Down
Loading