Make a temp commit if necessary & return GitHub permalink. Args: org: The GitHub organization name repo: The GitHub repository name ignore_workdir: If true, start task from current commit and ignore any uncommitted changes. Returns: GitHub orga
(
org: str, repo: str, ignore_workdir: bool = False
)
| 96 | |
| 97 | |
| 98 | def create_working_tree_permalink( |
| 99 | org: str, repo: str, ignore_workdir: bool = False |
| 100 | ) -> tuple[str, str, str]: |
| 101 | """Make a temp commit if necessary & return GitHub permalink. |
| 102 | |
| 103 | Args: |
| 104 | org: The GitHub organization name |
| 105 | repo: The GitHub repository name |
| 106 | ignore_workdir: If true, start task from current commit and ignore any |
| 107 | uncommitted changes. |
| 108 | |
| 109 | Returns: |
| 110 | GitHub organization, repository, commit id, permalink to commit. |
| 111 | """ |
| 112 | |
| 113 | def exec_with_err_log(cmd: str | list[str]) -> ExecResult: |
| 114 | """Execute a command and log errors.""" |
| 115 | return execute(cmd, error_out=True, log=True) |
| 116 | |
| 117 | if ignore_workdir: |
| 118 | commit = get_latest_commit_id() |
| 119 | return get_branch() or commit, commit, create_commit_permalink(org, repo, commit) |
| 120 | |
| 121 | branch = get_branch() or err_exit( |
| 122 | "Error: can't start run from detached head (must be on branch)" |
| 123 | ) |
| 124 | |
| 125 | tmp_branch_name = "temp-branch-" + str(randint(0, 1_000_000)) # noqa: S311 |
| 126 | |
| 127 | if not check_repo_is_dirty(): |
| 128 | commit = get_latest_commit_id() |
| 129 | exec_with_err_log(f"git push -u origin {branch}") |
| 130 | return branch, commit, create_commit_permalink(org, repo, commit) |
| 131 | |
| 132 | exec_with_err_log("git stash --include-untracked -m viv-autostash") |
| 133 | exec_with_err_log(f"git checkout -b {tmp_branch_name}") |
| 134 | exec_with_err_log("git stash apply") |
| 135 | exec_with_err_log("git add --all") |
| 136 | exec_with_err_log(["git", "commit", "-m", "viv auto commit"]) |
| 137 | commit = get_latest_commit_id() |
| 138 | exec_with_err_log(f"git checkout {branch}") |
| 139 | exec_with_err_log("git stash pop") |
| 140 | exec_with_err_log(f"git push -u origin {tmp_branch_name}") |
| 141 | exec_with_err_log(f"git branch -D {tmp_branch_name}") |
| 142 | threading.Thread(target=lambda: execute(f"git push origin --delete {tmp_branch_name}")).start() |
| 143 | |
| 144 | return branch, commit, create_commit_permalink(org, repo, commit) |
| 145 | |
| 146 | |
| 147 | def ask_pull_repo_or_exit() -> None: |
nothing calls this directly
no test coverage detected