@@ -17,6 +17,8 @@ class SourceHutIntegration(BaseIntegration):
1717 """A SourceHut integration using GraphQL for issue creation and updates."""
1818
1919 api_url = SOURCEHUT_GRAPHQL_API_URL
20+ open_status = "REPORTED"
21+ closed_status = "RESOLVED"
2022
2123 def get_headers (self ):
2224 token = self .dataspace .get_configuration (field_name = "sourcehut_token" )
@@ -104,6 +106,8 @@ def update_issue(self, repo_id, issue_id, title=None, body=None, state=None, lab
104106 id
105107 subject
106108 body
109+ status
110+ resolution
107111 }
108112 }
109113 """
@@ -116,17 +120,58 @@ def update_issue(self, repo_id, issue_id, title=None, body=None, state=None, lab
116120 if not input_data :
117121 raise ValueError ("At least one of 'title' or 'body' must be provided." )
118122
123+ tracker_id = self .get_tracker_id (repo_id )
124+ ticket_id = int (issue_id )
125+
119126 variables = {
120- "trackerId" : self .get_tracker_id (repo_id ),
121- "ticketId" : int (issue_id ),
127+ "trackerId" : tracker_id ,
128+ "ticketId" : ticket_id ,
129+ "input" : input_data ,
130+ }
131+
132+ response = self .post (
133+ self .api_url ,
134+ json = {"query" : mutation , "variables" : variables },
135+ )
136+
137+ updated_ticket = response .get ("data" , {}).get ("updateTicket" )
138+
139+ if state != updated_ticket .get ("status" ):
140+ self .update_ticket_status (tracker_id , ticket_id , state )
141+
142+ return updated_ticket
143+
144+ def update_ticket_status (self , tracker_id , ticket_id , status ):
145+ """Update the status or resolution of a SourceHut ticket via GraphQL."""
146+ mutation = """
147+ mutation UpdateTicketStatus($trackerId: Int!, $ticketId: Int!, $input: UpdateStatusInput!) {
148+ updateTicketStatus(trackerId: $trackerId, ticketId: $ticketId, input: $input) {
149+ id
150+ ticket {
151+ id
152+ subject
153+ status
154+ resolution
155+ }
156+ }
157+ }
158+ """
159+ input_data = {"status" : status }
160+
161+ if status == self .closed_status :
162+ input_data ["resolution" ] = "CLOSED"
163+
164+ variables = {
165+ "trackerId" : tracker_id ,
166+ "ticketId" : int (ticket_id ),
122167 "input" : input_data ,
123168 }
124169
125170 response = self .post (
126171 self .api_url ,
127172 json = {"query" : mutation , "variables" : variables },
128173 )
129- return response .get ("data" , {}).get ("updateTicket " )
174+ return response .get ("data" , {}).get ("updateTicketStatus " )
130175
131176 def post_comment (self , repo_id , issue_id , comment_body , base_url = None ):
132177 """Post a comment on an existing SourceHut ticket."""
0 commit comments