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
26 changes: 13 additions & 13 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@ def make_changelog_pr(auth, branch, repo, title, commit_message, body, dry_run=F
# Make a new branch with a uuid suffix
pr_branch = f"changelog-{uuid.uuid1().hex}"

if not dry_run:
dirty = util.run("git --no-pager diff --stat") != ""
if dirty:
util.run("git stash")
util.run(f"{util.GIT_FETCH_CMD} {branch}")
util.run(f"git checkout -b {pr_branch} origin/{branch}")
if dirty:
util.run("git stash apply")
dirty = util.run("git --no-pager diff --stat") != ""
if dirty:
util.run("git stash")
util.run(f"{util.GIT_FETCH_CMD} {branch}")
util.run(f"git checkout -b {pr_branch} origin/{branch}")
if dirty:
util.run("git stash apply")

# Add a commit with the message
try:
Expand All @@ -188,8 +187,8 @@ def make_changelog_pr(auth, branch, repo, title, commit_message, body, dry_run=F
head = pr_branch
maintainer_can_modify = True

if not dry_run:
util.run(f"git push origin {pr_branch}")
remote_name = util.get_remote_name(dry_run)
util.run(f"git push {remote_name} {pr_branch}")

# title, head, base, body, maintainer_can_modify, draft, issue
pull = gh.pulls.create(title, head, base, body, maintainer_can_modify, False, None)
Expand Down Expand Up @@ -265,9 +264,10 @@ def draft_release(
if delta.days > 0:
gh.repos.delete_release(release.id)

remote_url = util.run("git config --get remote.origin.url")
if not dry_run and not os.path.exists(remote_url):
util.run(f"git push origin HEAD:{branch} --follow-tags --tags")
remote_name = util.get_remote_name(dry_run)
remote_url = util.run(f"git config --get remote.{remote_name}.url")
if not os.path.exists(remote_url):
util.run(f"git push {remote_name} HEAD:{branch} --follow-tags --tags")

util.log(f"Creating release for {version}")
util.log(f"With assets: {assets}")
Expand Down
24 changes: 24 additions & 0 deletions jupyter_releaser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,30 @@ def get_gh_object(dry_run=False, **kwargs):
return core.GhApi(**kwargs)


_local_remote = None


def get_remote_name(dry_run):
"""Get the appropriate remote git name."""
global _local_remote
if not dry_run:
return "origin"

if _local_remote:
try:
run(f"git remote add test {_local_remote}")
except Exception:
pass
return "test"

tfile = tempfile.NamedTemporaryFile(suffix=".git")
tfile.close()
_local_remote = tfile.name.replace(os.sep, "/")
run(f"git init --bare {_local_remote}")
run(f"git remote add test {_local_remote}")
return "test"


def ensure_mock_github():
"""Check for or start a mock github server."""
core.GH_HOST = MOCK_GITHUB_URL
Expand Down