55
66import spackbot .comments as comments
77import spackbot .helpers as helpers
8- from sh .contrib import git
98import logging
10- import os
11- import sh
9+
10+ from spackbot .workers import fix_style_task , work_queue
11+
12+ # If we don't provide a timeout, the default in RQ is 180 seconds
13+ WORKER_JOB_TIMEOUT = 6 * 60 * 60
1214
1315logger = logging .getLogger (__name__ )
1416
@@ -31,13 +33,6 @@ async def style_comment(event, gh):
3133 await gh .post (comments_url , {}, data = {"body" : comments .style_message })
3234
3335
34- def is_up_to_date (output ):
35- """
36- A commit can fail if there are no changes!
37- """
38- return "branch is up to date" in output
39-
40-
4136async def fix_style (event , gh ):
4237 """
4338 Respond to a request to fix style.
@@ -58,7 +53,7 @@ async def fix_style(event, gh):
5853 return f"Sorry { sender } , I cannot do that for you. Only users with write can make this request!"
5954
6055 # Tell the user the style fix is going to take a minute or two
61- message = "Let me see if I can fix that for you! This might take a moment... "
56+ message = "Let me see if I can fix that for you!"
6257 await gh .post (event .data ["issue" ]["comments_url" ], {}, data = {"body" : message })
6358
6459 # Get the username of the original committer
@@ -72,49 +67,15 @@ async def fix_style(event, gh):
7267 full_name = pr ["head" ]["repo" ]["full_name" ]
7368 fork_url = f"git@github.com:{ full_name } .git"
7469
75- # At this point, we can clone the repository and make the change
76- with helpers .temp_dir () as cwd :
77-
78- # Clone a fresh spack develop to use for spack style
79- git ("clone" , helpers .spack_upstream , "spack-develop" )
80-
81- spack = sh .Command (f"{ cwd } /spack-develop/bin/spack" )
82-
83- # clone the develop repository to another folder for our PR
84- git ("clone" , "spack-develop" , "spack" )
85-
86- os .chdir ("spack" )
87- git ("config" , "user.name" , user )
88- git ("config" , "user.email" , email )
89-
90- # This will authenticate the push with the added ssh credentials
91- git ("remote" , "add" , "upstream" , helpers .spack_upstream )
92- git ("remote" , "set-url" , "origin" , fork_url )
93-
94- # we're on upstream/develop. Fetch and check out just the PR branch
95- git ("fetch" , "origin" , f"{ branch } :{ branch } " )
96- git ("checkout" , branch )
97-
98- # Save the message for the user
99- res , err = helpers .run_command (spack , ["--color" , "never" , "style" , "--fix" ])
100- message = comments .get_style_message (res )
101-
102- # Commit (allow for no changes)
103- res , err = helpers .run_command (
104- git ,
105- ["commit" , "-a" , "-m" , f"[spackbot] updating style on behalf of { user } " ],
106- )
107-
108- # Continue differently if the branch is up to date or not
109- if is_up_to_date (res ):
110- message += "\n I wasn't able to make any further changes, but please see the message above for remaining issues you can fix locally!"
111- return message
112- message += "\n I've updated the branch with isort fixes."
113-
114- # Finally, try to push, update the message if permission not allowed
115- try :
116- git ("push" , "origin" , branch )
117- except Exception :
118- message += "\n \n But it looks like I'm not able to push to your branch. 😭️ Did you check maintainer can edit when you opened the PR?"
70+ task_q = work_queue .get_queue ()
71+ fix_style_job = task_q .enqueue (
72+ fix_style_task ,
73+ user ,
74+ email ,
75+ fork_url ,
76+ branch ,
77+ job_timeout = WORKER_JOB_TIMEOUT ,
78+ )
79+ logger .info (f"Fix style job queued: { fix_style_job .id } " )
11980
12081 return message
0 commit comments