99
1010# pypi
1111import sh
12- from retask .task import Task
1312from retask .queue import Queue
1413
14+ import pep8
15+
1516# local
1617import githubutils as gh
1718
@@ -58,6 +59,9 @@ def run(self):
5859
5960 repo = data ['repository' ]['name' ]
6061 owner = data ['repository' ]['owner' ]['name' ]
62+ commits = data ['commits' ]
63+ import pprint
64+ pprint .pprint (commits )
6165
6266 fork = gh .my_fork (owner , repo )
6367 if not fork :
@@ -78,44 +82,31 @@ def run(self):
7882 print "** Adding remote upstream"
7983 with directory (self .working_dir ):
8084 print sh .git .remote .add ("upstream" , data ['repository' ]['url' ])
81- print sh .git .pull ("upstream" , data ['repository' ]['master_branch' ])
82-
83- print "** Processing files."
84- for root , dirs , files in os .walk (self .working_dir ):
85-
86- if '.git' in root :
87- continue
88-
89- for filename in files :
90- if filename .endswith (".py" ):
91- infile = root + "/" + filename
92- print "**** Tidying" , infile
93- tmpfile = infile + ".bak"
94- script = os .path .expanduser (
95- "~/devel/PythonTidy/PythonTidy.py"
96- )
97- # Run it twice for now.. since its a little unstable.
98- sh .python (script , infile , tmpfile )
99- sh .python (script , infile , tmpfile )
100- shutil .move (tmpfile , infile )
101-
102- patch_name = "pep8-" + str (uuid .uuid4 ())
103- with directory (self .working_dir ):
104- print sh .pwd ()
105- print sh .git .status ()
106- print sh .git .commit (
107- a = True ,
108- message = "(Auto commit from PEP8 Bot)" ,
109- author = "PEP8 Bot <bot@pep8.me>" ,
110- )
111- print sh .git .push (
112- "origin" ,
113- data ['repository' ]['master_branch' ] + ":" + patch_name ,
114- )
115-
116- print "Sleeping for 4 seconds"
117- time .sleep (4 )
118- gh .create_pull_request (owner , repo , patch_name )
85+ print sh .git .pull ("upstream" ,
86+ data ['repository' ]['master_branch' ])
87+
88+ print "** Processing commits."
89+ for commit in commits :
90+ print "** Processing files on commit" , commit
91+ print sh .git .checkout (commit )
92+ infiles = []
93+ for root , dirs , files in os .walk (self .working_dir ):
94+
95+ if '.git' in root :
96+ continue
97+
98+ infiles .extend ([
99+ root + "/" + fname
100+ for fname in files
101+ if fname .endswith (".py" )
102+ ])
103+
104+ pep8style = pep8 .StyleGuide (quiet = True )
105+ result = pep8style .check_files (infiles )
106+ print result .total_errors
107+ # TODO - mark gh commit with errors
108+ # TODO - add a note in our DB about the status
109+ # TODO - try/except/finally mark as 'failed' if necessary.
119110
120111
121112def worker ():
0 commit comments