Skip to content

Commit 2c6c3b1

Browse files
committed
Changes to properties defaults + yielding edges instead of returning lists
1 parent 0617fad commit 2c6c3b1

1 file changed

Lines changed: 72 additions & 72 deletions

File tree

src/openhound_github/models/runner.py

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class GHRunnerGroupProperties(GHNodeProperties):
1616
group_id: int | None = field(
1717
default=None, metadata={"description": "The GitHub runner group ID."}
1818
)
19-
group_name: str = field(
20-
default="", metadata={"description": "The runner group display name."}
19+
group_name: str | None = field(
20+
default=None, metadata={"description": "The runner group display name."}
2121
)
2222
visibility: str | None = field(
2323
default=None,
@@ -49,12 +49,12 @@ class GHRunnerGroupProperties(GHNodeProperties):
4949
default=None,
5050
metadata={"description": "API URL for runners in this group."},
5151
)
52-
environment_name: str = field(
53-
default="",
52+
environment_name: str | None = field(
53+
default=None,
5454
metadata={"description": "The name of the environment (GitHub organization)."},
5555
)
56-
query_runners: str = ""
57-
query_repositories: str = ""
56+
query_runners: str | None = None
57+
query_repositories: str | None = None
5858

5959

6060
@app.asset(
@@ -115,22 +115,22 @@ def as_node(self) -> GHNode:
115115
)
116116

117117
@property
118-
def edges(self) -> list[Edge]:
119-
return [
120-
Edge(
121-
kind=ek.CONTAINS,
122-
start=EdgePath(value=self._lookup.org_id(), match_by="id"),
123-
end=EdgePath(value=self.node_id, match_by="id"),
124-
properties=EdgeProperties(traversable=False),
125-
)
126-
]
118+
def edges(self):
119+
yield Edge(
120+
kind=ek.CONTAINS,
121+
start=EdgePath(value=self._lookup.org_id(), match_by="id"),
122+
end=EdgePath(value=self.node_id, match_by="id"),
123+
properties=EdgeProperties(traversable=False),
124+
)
127125

128126

129127
@dataclass
130128
class GHRunnerProperties(GHNodeProperties):
131129
scope: str = field(
132130
default="",
133-
metadata={"description": "Whether the runner is organization or repository scoped."},
131+
metadata={
132+
"description": "Whether the runner is organization or repository scoped."
133+
},
134134
)
135135
runner_id: int | None = field(
136136
default=None, metadata={"description": "The GitHub runner ID."}
@@ -167,18 +167,22 @@ class GHRunnerProperties(GHNodeProperties):
167167
)
168168
repository_id: str | None = field(
169169
default=None,
170-
metadata={"description": "The repository node_id for repository-scoped runners."},
170+
metadata={
171+
"description": "The repository node_id for repository-scoped runners."
172+
},
171173
)
172174
repository_full_name: str | None = field(
173175
default=None,
174-
metadata={"description": "The full repository name for repository-scoped runners."},
176+
metadata={
177+
"description": "The full repository name for repository-scoped runners."
178+
},
175179
)
176180
environment_name: str = field(
177181
default="",
178182
metadata={"description": "The name of the environment (GitHub organization)."},
179183
)
180-
query_group: str = ""
181-
query_repositories: str = ""
184+
query_group: str | None = None
185+
query_repositories: str | None = None
182186

183187

184188
@app.asset(
@@ -187,23 +191,7 @@ class GHRunnerProperties(GHNodeProperties):
187191
description="GitHub organization-scoped self-hosted runner",
188192
icon="microchip",
189193
properties=GHRunnerProperties,
190-
),
191-
edges=[
192-
EdgeDef(
193-
start=nk.RUNNER_GROUP,
194-
end=nk.ORG_RUNNER,
195-
kind=ek.CONTAINS,
196-
description="Runner group contains organization runner",
197-
traversable=False,
198-
),
199-
EdgeDef(
200-
start=nk.REPOSITORY,
201-
end=nk.ORG_RUNNER,
202-
kind=ek.CAN_USE_RUNNER,
203-
description="Repository can dispatch jobs to runner",
204-
traversable=False,
205-
),
206-
],
194+
)
207195
)
208196
class OrgRunner(BaseAsset):
209197
id: int
@@ -242,7 +230,7 @@ def as_node(self) -> GHNode:
242230
)
243231

244232
@property
245-
def edges(self) -> list[Edge]:
233+
def edges(self):
246234
return []
247235

248236

@@ -274,29 +262,35 @@ def as_node(self):
274262
return None
275263

276264
@property
277-
def edges(self) -> list[Edge]:
278-
runner_node_id = f"{self._lookup.org_id()}_org_runner_{self.runner_id}"
279-
edges = [
280-
Edge(
281-
kind=ek.CONTAINS,
282-
start=EdgePath(
283-
value=f"{self._lookup.org_id()}_runner_group_{self.runner_group_id}",
284-
match_by="id",
285-
),
286-
end=EdgePath(value=runner_node_id, match_by="id"),
287-
properties=EdgeProperties(traversable=False),
288-
)
289-
]
290-
edges.extend(
291-
Edge(
265+
def _runner_node_id(self):
266+
return f"{self._lookup.org_id()}_org_runner_{self.runner_id}"
267+
268+
@property
269+
def _contains_edge(self):
270+
yield Edge(
271+
kind=ek.CONTAINS,
272+
start=EdgePath(
273+
value=f"{self._lookup.org_id()}_runner_group_{self.runner_group_id}",
274+
match_by="id",
275+
),
276+
end=EdgePath(value=self._runner_node_id, match_by="id"),
277+
properties=EdgeProperties(traversable=False),
278+
)
279+
280+
@property
281+
def _can_use_runner_edges(self):
282+
for repo_node_id in self.accessible_repo_node_ids:
283+
yield Edge(
292284
kind=ek.CAN_USE_RUNNER,
293285
start=EdgePath(value=repo_node_id, match_by="id"),
294-
end=EdgePath(value=runner_node_id, match_by="id"),
286+
end=EdgePath(value=self._runner_node_id, match_by="id"),
295287
properties=EdgeProperties(traversable=False),
296288
)
297-
for repo_node_id in self.accessible_repo_node_ids
298-
)
299-
return edges
289+
290+
@property
291+
def edges(self):
292+
yield from self._can_use_runner_edges
293+
yield from self._contains_edge
300294

301295

302296
@app.asset(
@@ -365,18 +359,24 @@ def as_node(self) -> GHNode:
365359
)
366360

367361
@property
368-
def edges(self) -> list[Edge]:
369-
return [
370-
Edge(
371-
kind=ek.CONTAINS,
372-
start=EdgePath(value=self.repository_node_id, match_by="id"),
373-
end=EdgePath(value=self.node_id, match_by="id"),
374-
properties=EdgeProperties(traversable=False),
375-
),
376-
Edge(
377-
kind=ek.CAN_USE_RUNNER,
378-
start=EdgePath(value=self.repository_node_id, match_by="id"),
379-
end=EdgePath(value=self.node_id, match_by="id"),
380-
properties=EdgeProperties(traversable=False),
381-
),
382-
]
362+
def _contains_edge(self):
363+
yield Edge(
364+
kind=ek.CONTAINS,
365+
start=EdgePath(value=self.repository_node_id, match_by="id"),
366+
end=EdgePath(value=self.node_id, match_by="id"),
367+
properties=EdgeProperties(traversable=False),
368+
)
369+
370+
@property
371+
def _can_use_runner_edge(self):
372+
yield Edge(
373+
kind=ek.CAN_USE_RUNNER,
374+
start=EdgePath(value=self.repository_node_id, match_by="id"),
375+
end=EdgePath(value=self.node_id, match_by="id"),
376+
properties=EdgeProperties(traversable=False),
377+
)
378+
379+
@property
380+
def edges(self):
381+
yield from self._can_use_runner_edge
382+
yield from self._contains_edge

0 commit comments

Comments
 (0)