@@ -302,6 +302,89 @@ def get_colocation_centers(self, branch: str = "main") -> List[Dict[str, Any]]:
302302
303303 return colocations
304304
305+ def get_proposed_changes (self , branch : str = "main" ) -> List [Dict [str , Any ]]:
306+ """Fetch proposed changes for a branch.
307+
308+ Args:
309+ branch: Branch name to query (default: "main")
310+
311+ Returns:
312+ List of proposed change dictionaries
313+
314+ Raises:
315+ InfrahubConnectionError: If connection fails
316+ InfrahubHTTPError: If HTTP error occurs
317+ InfrahubGraphQLError: If GraphQL error occurs
318+ """
319+ query = """
320+ query GetProposedChanges {
321+ CoreProposedChange {
322+ edges {
323+ node {
324+ id
325+ name {
326+ value
327+ }
328+ state {
329+ value
330+ }
331+ source_branch {
332+ value
333+ }
334+ }
335+ }
336+ }
337+ }
338+ """
339+
340+ result = self .execute_graphql (query , branch = branch )
341+
342+ # Extract proposed changes from GraphQL response
343+ edges = result .get ("data" , {}).get ("CoreProposedChange" , {}).get ("edges" , [])
344+ proposed_changes = [edge ["node" ] for edge in edges ]
345+
346+ return proposed_changes
347+
348+ def get_datacenters_from_proposed_changes (
349+ self , branch : str = "main"
350+ ) -> List [Dict [str , Any ]]:
351+ """Fetch TopologyDataCenter objects from proposed changes on a branch.
352+
353+ This method queries for data centers that may be part of open proposed changes
354+ and haven't been merged yet. It adds a "_proposed" flag to distinguish them.
355+
356+ Args:
357+ branch: Branch name to query (default: "main")
358+
359+ Returns:
360+ List of datacenter dictionaries from proposed changes
361+
362+ Raises:
363+ InfrahubConnectionError: If connection fails
364+ InfrahubHTTPError: If HTTP error occurs
365+ InfrahubGraphQLError: If GraphQL error occurs
366+ """
367+ # First, get proposed changes for this branch
368+ proposed_changes = self .get_proposed_changes (branch )
369+
370+ # Filter for open proposed changes on this branch
371+ open_pcs = [
372+ pc
373+ for pc in proposed_changes
374+ if pc .get ("state" , {}).get ("value" ) == "open"
375+ and pc .get ("source_branch" , {}).get ("value" ) == branch
376+ ]
377+
378+ if not open_pcs :
379+ return []
380+
381+ # For now, we'll query the branch directly with a flag to get uncommitted objects
382+ # In Infrahub, objects created on a branch are visible via GraphQL queries on that branch
383+ # even if they're part of an open proposed change
384+ # So we actually don't need special handling - the issue is likely elsewhere
385+
386+ return []
387+
305388 def execute_graphql (
306389 self ,
307390 query : str ,
0 commit comments