4040
4141# Global variables
4242TOKEN = os .getenv ("TOKEN" )
43- DEFAULT_REPO = os .getenv ("DEFAULT_REPO" , "golclinics /discussions" )
43+ DEFAULT_REPO = os .getenv ("DEFAULT_REPO" , "azure-ai-foundry /discussions" )
4444REQUEST_TIMEOUT = int (os .getenv ("REQUEST_TIMEOUT" , "30" )) # Default 30 second timeout
4545
4646# App settings
@@ -604,7 +604,7 @@ def get_label_node_ids(owner: str, repo: str, label_names: list, headers: Dict[s
604604 query = '''
605605 query($owner: String!, $repo: String!) {
606606 repository(owner: $owner, name: $repo) {
607- labels(first: 50 ) {
607+ labels(first: 5 ) {
608608 nodes {
609609 id
610610 name
@@ -619,7 +619,19 @@ def get_label_node_ids(owner: str, repo: str, label_names: list, headers: Dict[s
619619 response .raise_for_status ()
620620 data = response .json ()
621621 all_labels = data ["data" ]["repository" ]["labels" ]["nodes" ]
622+
623+ # Enhanced debugging for labels
624+ logger .info (f"Found { len (all_labels )} labels in repository: { [label ['name' ] for label in all_labels ]} " )
625+
622626 label_ids = [label ["id" ] for label in all_labels if label ["name" ] in label_names ]
627+
628+ # Log the label IDs found
629+ found_labels = [label ["name" ] for label in all_labels if label ["name" ] in label_names ]
630+ missing_labels = [name for name in label_names if name not in found_labels ]
631+ logger .info (f"Found label IDs for: { found_labels } " )
632+ if missing_labels :
633+ logger .warning (f"Could not find IDs for these labels: { missing_labels } " )
634+
623635 return label_ids
624636
625637def assign_labels_to_discussion (repo_url : str , discussion_number : int , label_names : list ) -> bool :
@@ -628,22 +640,55 @@ def assign_labels_to_discussion(repo_url: str, discussion_number: int, label_nam
628640 headers = get_auth_headers ()
629641 headers ["Content-Type" ] = "application/json"
630642 try :
643+ # Get discussion ID
644+ logger .info (f"Fetching discussion ID for #{ discussion_number } " )
631645 discussion_id = get_discussion_node_id (owner , repo , discussion_number , headers )
646+ logger .info (f"Found discussion ID: { discussion_id } " )
647+
648+ # Get label IDs
649+ logger .info (f"Fetching label IDs for: { label_names } " )
632650 label_ids = get_label_node_ids (owner , repo , label_names , headers )
633651 if not label_ids :
634652 logger .error (f"No matching label IDs found for: { label_names } " )
635653 return False
654+
655+ logger .info (f"Found { len (label_ids )} label IDs: { label_ids } " )
656+
657+ # Add labels to discussion
636658 mutation = '''
637659 mutation($labelableId: ID!, $labelIds: [ID!]!) {
638660 addLabelsToLabelable(input: {labelableId: $labelableId, labelIds: $labelIds}) {
639661 clientMutationId
662+ labelable {
663+ ... on Discussion {
664+ labels(first: 10) {
665+ nodes {
666+ name
667+ }
668+ }
669+ }
670+ }
640671 }
641672 }
642673 '''
643674 variables = {"labelableId" : discussion_id , "labelIds" : label_ids }
644675 payload = {"query" : mutation , "variables" : variables }
645676 response = requests .post ("https://api.github.com/graphql" , headers = headers , json = payload )
677+
678+ # Check for errors in the GraphQL response
679+ data = response .json ()
680+ if "errors" in data :
681+ logger .error (f"GraphQL error adding labels: { data ['errors' ]} " )
682+ return False
683+
646684 response .raise_for_status ()
685+
686+ # Check if we got back label information
687+ result = data .get ("data" , {}).get ("addLabelsToLabelable" , {})
688+ if "labelable" in result :
689+ applied_labels = [label ["name" ] for label in result ["labelable" ]["labels" ]["nodes" ]]
690+ logger .info (f"Confirmed labels on discussion #{ discussion_number } : { applied_labels } " )
691+
647692 logger .info (f"Successfully labeled discussion #{ discussion_number } with { label_names } " )
648693 return True
649694 except Exception as e :
0 commit comments