@@ -31,6 +31,8 @@ from collections.abc import Sequence
3131
3232import pika
3333
34+ from lib .aio .jsonutil import JsonObject , get_int , get_str
35+ from lib .bots_automerge import auto_merge_bots_pr
3436from lib .directories import get_images_data_dir
3537from lib .network import redhat_network
3638from lib .stores import LOG_STORE
@@ -43,7 +45,9 @@ statistics_queue = os.environ.get("RUN_STATISTICS_QUEUE")
4345# as per pika docs
4446DeliveryTag = int
4547
46- ConsumeResult = tuple [Sequence [str ] | str | None , DeliveryTag | None ]
48+ JobSubject = JsonObject
49+
50+ ConsumeResult = tuple [Sequence [str ] | str | None , DeliveryTag | None , JobSubject | None ]
4751
4852
4953# Returns a command argv to execute and the delivery tag needed to ack the message
@@ -52,7 +56,7 @@ def consume_webhook_queue(dq: distributed_queue.DistributedQueue) -> ConsumeResu
5256 # call tests-scan or issue-scan appropriately
5357 method_frame , _header_frame , message = dq .channel .basic_get (queue = 'webhook' )
5458 if not method_frame or not message :
55- return None , None
59+ return None , None , None
5660
5761 body = json .loads (message )
5862 event = body ['event' ]
@@ -97,9 +101,9 @@ def consume_webhook_queue(dq: distributed_queue.DistributedQueue) -> ConsumeResu
97101 cmd = ['./issue-scan' , '--issues-data' , json .dumps (request ), '--amqp' , dq .address ]
98102 else :
99103 logging .error ('Unkown event type in the webhook queue' )
100- return None , None
104+ return None , None , None
101105
102- return cmd , method_frame .delivery_tag
106+ return cmd , method_frame .delivery_tag , None
103107
104108
105109# Returns a command to execute and the delivery tag needed to ack the message
@@ -119,18 +123,20 @@ def consume_task_queue(dq: distributed_queue.DistributedQueue) -> ConsumeResult:
119123 queue = ['public' , 'rhel' ][random .randrange (2 )]
120124 else :
121125 # nothing to do
122- return None , None
126+ return None , None , None
123127
124128 method_frame , _header_frame , message = dq .channel .basic_get (queue = queue )
125129 if not method_frame or not message :
126- return None , None
130+ return None , None , None
127131
128132 body = json .loads (message )
129133 if job := body .get ('job' ):
130134 command = ['./job-runner' , 'json' , json .dumps (job )]
135+ job_subject = job .get ('subject' )
131136 else :
132137 command = body ['command' ]
133- return command , method_frame .delivery_tag
138+ job_subject = None
139+ return command , method_frame .delivery_tag , job_subject
134140
135141
136142def mail_notification (body : str ) -> None :
@@ -159,14 +165,14 @@ def main() -> int:
159165 opts = parser .parse_args ()
160166
161167 with distributed_queue .DistributedQueue (opts .amqp , ['webhook' , 'rhel' , 'public' , 'statistics' ]) as dq :
162- cmd , delivery_tag = consume_webhook_queue (dq )
168+ cmd , delivery_tag , job_subj = consume_webhook_queue (dq )
163169 if not cmd and delivery_tag :
164170 logging .info ("Webhook message interpretation generated no command" )
165171 dq .channel .basic_ack (delivery_tag )
166172 return 0
167173
168174 if not cmd :
169- cmd , delivery_tag = consume_task_queue (dq )
175+ cmd , delivery_tag , job_subj = consume_task_queue (dq )
170176 if not cmd :
171177 logging .info ("All queues are empty" )
172178 return 1
@@ -191,6 +197,16 @@ failed with exit code %i. Please check the container logs for details.""" % (cmd
191197 if delivery_tag is not None :
192198 dq .channel .basic_ack (delivery_tag )
193199
200+ if job_subj is not None :
201+ repo = get_str (job_subj , 'repo' )
202+ pull = get_int (job_subj , 'pull' )
203+ sha = get_str (job_subj , 'sha' )
204+ # skip automerge if jobs don't run against a PR
205+ if repo is not None and pull is not None and sha is not None :
206+ auto_merge_bots_pr (repo , pull , sha )
207+ else :
208+ logging .info ("Skipping automerge for job: %s" , job_subj )
209+
194210 return 0
195211
196212
0 commit comments