Skip to content

Commit b09abe4

Browse files
authored
Add some extra docs for repo not found case (#297)
1 parent 8be1391 commit b09abe4

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

src/ghstack/github_utils.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,43 @@ def get_github_repo_info(
7777
name_with_owner = {"owner": repo_owner, "name": repo_name}
7878

7979
# TODO: Cache this guy
80-
repo = github.graphql(
81-
"""
82-
query ($owner: String!, $name: String!) {
83-
repository(name: $name, owner: $owner) {
84-
id
85-
isFork
86-
defaultBranchRef {
87-
name
80+
try:
81+
repo = github.graphql(
82+
"""
83+
query ($owner: String!, $name: String!) {
84+
repository(name: $name, owner: $owner) {
85+
id
86+
isFork
87+
defaultBranchRef {
88+
name
89+
}
8890
}
89-
}
90-
}""",
91-
owner=name_with_owner["owner"],
92-
name=name_with_owner["name"],
93-
)["data"]["repository"]
91+
}""",
92+
owner=name_with_owner["owner"],
93+
name=name_with_owner["name"],
94+
)["data"]["repository"]
95+
except RuntimeError as e:
96+
# Check if this is a repository access error (NOT_FOUND)
97+
error_msg = str(e)
98+
if (
99+
"Could not resolve to a Repository" in error_msg
100+
and "NOT_FOUND" in error_msg
101+
):
102+
raise RuntimeError(
103+
f"Original error: {error_msg}\n\n"
104+
f"Could not access repository '{name_with_owner['owner']}/{name_with_owner['name']}'. "
105+
f"This usually means:\n"
106+
f"1. The repository is private and your OAuth token doesn't have access\n"
107+
f"2. The repository is in a different organization that hasn't granted access\n"
108+
f"3. The repository doesn't exist or has been moved\n\n"
109+
f"If this is a private repository or in a separate organization, you can grant access by:\n"
110+
f"1. Delete the 'github_oauth' entry from your .ghstackrc file\n"
111+
f"2. Run ghstack again to redo the OAuth flow\n"
112+
f"3. Make sure to grant access to the appropriate organizations when prompted"
113+
)
114+
else:
115+
# Re-raise the original error if it's not the repository access issue
116+
raise
94117

95118
return {
96119
"name_with_owner": name_with_owner,

0 commit comments

Comments
 (0)