4040from operator import attrgetter
4141import random
4242import time
43+ import datetime
4344import textwrap
4445# Since pylint can not found rpm.error, disable this check
4546from rpm import error as RpmError # pylint: disable=no-name-in-module
4849from rift import RiftError , __version__
4950from rift .Annex import Annex , is_binary
5051from rift .Config import Config , Staff , Modules
51- from rift .Gerrit import Review
52+ from rift .auth import auth
5253from rift .Mock import Mock
5354from rift .Package import Package , Test
5455from rift .Repository import LocalRepository , ProjectArchRepositories
@@ -221,6 +222,9 @@ def make_parser():
221222 subsubprs .add_argument ('--dest' , metavar = 'PATH' , required = True ,
222223 help = 'destination path' )
223224
225+ # Auth options
226+ subprs = subparsers .add_parser ('auth' , help = 'Authenticate for access to Annex write access' )
227+
224228 # VM options
225229 subprs = subparsers .add_parser ('vm' , help = 'Manipulate VM process' )
226230 subprs .add_argument ('-a' , '--arch' , help = 'CPU architecture of the VM' )
@@ -270,11 +274,9 @@ def make_parser():
270274 subprs .add_argument ('--bump' , dest = 'bump' , action = 'store_true' ,
271275 help = 'also bump the release number' )
272276
273- # Gerrit review
274- subprs = subparsers .add_parser ('gerrit' , add_help = False ,
275- help = 'Make Gerrit automatic review' )
276- subprs .add_argument ('--change' , help = "Gerrit Change-Id" , required = True )
277- subprs .add_argument ('--patchset' , help = "Gerrit patchset ID" , required = True )
277+ # GitLab review
278+ subprs = subparsers .add_parser ('gitlab' , add_help = False ,
279+ help = 'Check specfiles for GitLab' )
278280 subprs .add_argument ('patch' , metavar = 'PATCH' , type = argparse .FileType ('r' ))
279281
280282 # Parse options
@@ -357,8 +359,8 @@ def action_annex(args, config, staff, modules):
357359 message ('%s: not an annex pointer, ignoring' % srcfile )
358360
359361 elif args .annex_cmd == 'delete' :
360- annex .delete (args .id )
361- message ('%s has been deleted' % args .id )
362+ if annex .delete (args .id ):
363+ message ('%s has been deleted' % args .id )
362364
363365 elif args .annex_cmd == 'get' :
364366 annex .get (args .id , args .dest )
@@ -369,8 +371,26 @@ def action_annex(args, config, staff, modules):
369371 output_file = annex .backup (
370372 Package .list (config , staff , modules ), args .output_file
371373 )
374+
372375 message (f"Annex backup is available here: { output_file } " )
373376
377+ def action_auth (args , config ):
378+ """Action for 'auth' sub-commands."""
379+ auth_obj = auth (config )
380+
381+ if auth_obj .authenticate ():
382+ msg = "succesfully authenticated"
383+
384+ t = auth_obj .get_expiration_timestr ()
385+ if t != "" :
386+ msg += "; token expires in {}" .format (t )
387+ else :
388+ msg += "; token expiration time is unknown"
389+
390+ message (msg )
391+ else :
392+ message ("error: authentication failed" )
393+
374394def _vm_start (vm ):
375395 if vm .running ():
376396 message ('VM is already running' )
@@ -874,23 +894,18 @@ def action_validdiff(args, config):
874894
875895 return rc
876896
877- def action_gerrit (args , config , staff , modules ):
878- """Review a patchset for Gerrit (specfiles)"""
879-
880- review = Review ()
897+ def action_gitlab (args , config , staff , modules ):
898+ """Review a patchset for GitLab (specfiles)"""
881899
882900 # Parse matching diff and specfiles in it
883- for patchedfile in parse_unidiff (args .patch ):
884- filepath = patchedfile .path
885- names = filepath .split (os .path .sep )
901+ for f in parse_unidiff (args .patch ):
902+ path = f .path
903+ names = path .split (os .path .sep )
886904 if names [0 ] == config .get ('packages_dir' ):
887905 pkg = Package (names [1 ], config , staff , modules )
888- if filepath == pkg .specfile and not patchedfile .is_deleted_file :
889- Spec (pkg .specfile , config = config ).analyze (review , pkg .dir )
890-
891- # Push review
892- review .msg_header = 'rpmlint analysis'
893- review .push (config , args .change , args .patchset )
906+ if os .path .abspath (path ) == pkg .specfile and not f .is_deleted_file :
907+ spec = Spec (pkg .specfile , config = config )
908+ spec .check ()
894909
895910def get_packages_from_patch (patch , config , modules , staff ):
896911 """
@@ -981,6 +996,11 @@ def action(config, args):
981996 action_annex (args , config , * staff_modules (config ))
982997 return
983998
999+ # AUTH
1000+ if args .command == 'auth' :
1001+ action_auth (args , config )
1002+ return
1003+
9841004 # VM
9851005 if args .command == 'vm' :
9861006 return action_vm (args , config )
@@ -1124,9 +1144,9 @@ def action(config, args):
11241144 config = config ).add_changelog_entry (author , args .comment ,
11251145 bump = getattr (args , 'bump' , False ))
11261146
1127- # GERRIT
1128- elif args .command == 'gerrit ' :
1129- return action_gerrit (args , config , * staff_modules (config ))
1147+ # GITLAB
1148+ elif args .command == 'gitlab ' :
1149+ return action_gitlab (args , config , * staff_modules (config ))
11301150
11311151 return 0
11321152
@@ -1167,6 +1187,18 @@ def _validate_patched_file(patched_file, config, modules, staff):
11671187 if patched_file .binary :
11681188 raise RiftError ("Binary file detected: %s" % filepath )
11691189
1190+ if filepath == '.gitlab-ci.yml' :
1191+ logging .debug ('Ignoring gitlab ci file: %s' , filepath )
1192+ return False
1193+
1194+ if filepath == 'CODEOWNERS' :
1195+ logging .debug ('Ignoring gitlab ci file: %s' , filepath )
1196+ return False
1197+
1198+ if names [0 ] == "gitlab-ci" :
1199+ logging .debug ("Ignoring gitlab ci file: %s" % filepath )
1200+ return False
1201+
11701202 if names [0 ] != config .get ('packages_dir' ):
11711203 raise RiftError ("Unknown file pattern: %s" % filepath )
11721204
0 commit comments