Skip to content

Commit e002387

Browse files
authored
feat: allow GitHub source property to be split into two (#14)
GitHub custom properies have a limit of 75 characters, so we can split the host and path parts to make it a bit more manageable
1 parent fd9049f commit e002387

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/kalandra/cli.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,27 @@ async def main(cmdline_args: list[str]) -> int:
115115

116116
logger.info("Looking up source URL from target repository")
117117

118-
source_url = await github_api.get_repo_property(
119-
repo_url=args.target,
120-
property_name=args.source[len("target-prop:") :],
121-
)
122-
if source_url is None:
118+
props = await github_api.get_repo_properties(args.target)
119+
source_prop_name = args.source[len("target-prop:") :]
120+
121+
if source_prop_name not in props:
123122
logger.error("Property %s not found in target repository", args.source)
124123
return 1
125124

125+
source_prop_value = props[source_prop_name]
126+
if source_prop_value.startswith("/"):
127+
# Assume it's a relative path and lookup host from another prop
128+
if f"{source_prop_name}-host" not in props:
129+
logger.error(
130+
"Source property is relative, but no %s-host not found in target repository: %s",
131+
args.source,
132+
source_prop_value,
133+
)
134+
return 1
135+
source_url = props[f"{source_prop_name}-host"] + source_prop_value
136+
else:
137+
source_url = source_prop_value
138+
126139
source = Transport.from_url(source_url, credentials_provider=credentials_provider)
127140
target = Transport.from_url(args.target, credentials_provider=credentials_provider)
128141

src/kalandra/github_utils.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ def get_org_api(self, org: str) -> github.Github:
4949

5050
return github.Github(auth=self._auth.get_installation_auth(installation_id))
5151

52-
async def get_repo_property(
52+
async def get_repo_properties(
5353
self,
5454
repo_url: str,
55-
property_name: str,
56-
) -> None | str:
55+
) -> dict[str, str]:
5756
url = urlparse(repo_url)
5857

5958
path_parts = url.path.strip("/").split("/")
@@ -62,13 +61,15 @@ async def get_repo_property(
6261
if repo_name.endswith(".git"):
6362
repo_name = repo_name[:-4]
6463

65-
logging.info("Looking up property %s for org '%s' and repo '%s'", property_name, org, repo_name)
6664
api = self.get_org_api(org)
6765
repo = api.get_repo(f"{org}/{repo_name}")
68-
value = repo.get_custom_properties().get(property_name, None) # type: ignore
69-
if value is not None and not isinstance(value, str):
70-
raise ValueError(f"Property {property_name} is not a string: {value}")
71-
return value
66+
67+
values: dict[str, str] = {}
68+
for key, value in repo.custom_properties.items(): # type: ignore
69+
if isinstance(value, str):
70+
values[key] = value
71+
72+
return values
7273

7374
def crendentials_provider_for_org(self, org: str) -> GitHubAppCredentialProvider:
7475
installation_id = self.get_installation_id(org)

0 commit comments

Comments
 (0)