MCPcopy Create free account
hub / github.com/ezyang/ghstack / parse_pull_request

Function parse_pull_request

src/ghstack/github_utils.py:152–178  ·  view source on GitHub ↗
(
    pull_request: str,
    *,
    sh: Optional[ghstack.shell.Shell] = None,
    remote_name: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

150
151
152def parse_pull_request(
153 pull_request: str,
154 *,
155 sh: Optional[ghstack.shell.Shell] = None,
156 remote_name: Optional[str] = None,
157) -> GitHubPullRequestParams:
158 pull_request = pull_request.lstrip("#")
159 m = RE_PR_URL.match(pull_request)
160 if not m:
161 # We can reconstruct the URL if just a PR number is passed
162 if sh is not None and remote_name is not None:
163 remote_url = sh.git("remote", "get-url", "--push", remote_name)
164 # Do not pass the shell to avoid infinite loop
165 try:
166 return parse_pull_request(
167 _normalize_remote_url(remote_url) + "/pull/" + pull_request
168 )
169 except RuntimeError:
170 # Fall back on original error message
171 pass
172 raise RuntimeError("Did not understand PR argument. PR must be URL")
173
174 github_url = m.group("github_url")
175 owner = m.group("owner")
176 name = m.group("name")
177 number = int(m.group("number"))
178 return {"github_url": github_url, "owner": owner, "name": name, "number": number}

Callers

nothing calls this directly

Calls 2

_normalize_remote_urlFunction · 0.85
gitMethod · 0.80

Tested by

no test coverage detected