2450
+ − 1 #!/usr/bin/env python2
+ − 2 # -*- coding: utf-8 -*-
+ − 3
+ − 4 # jp: a SàT command line tool
2483
+ − 5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org)
2450
+ − 6
+ − 7 # This program is free software: you can redistribute it and/or modify
+ − 8 # it under the terms of the GNU Affero General Public License as published by
+ − 9 # the Free Software Foundation, either version 3 of the License, or
+ − 10 # (at your option) any later version.
+ − 11
+ − 12 # This program is distributed in the hope that it will be useful,
+ − 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ − 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ − 15 # GNU Affero General Public License for more details.
+ − 16
+ − 17 # You should have received a copy of the GNU Affero General Public License
+ − 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
+ − 19
+ − 20
+ − 21 import base
+ − 22 from sat.core.i18n import _
+ − 23 from sat_frontends.jp import common
+ − 24 from sat_frontends.jp.constants import Const as C
+ − 25 from functools import partial
+ − 26 import os.path
+ − 27
+ − 28 __commands__ = [ "MergeRequest" ]
+ − 29
+ − 30
+ − 31 class Set ( base . CommandBase ):
+ − 32
+ − 33 def __init__ ( self , host ):
+ − 34 base . CommandBase . __init__ ( self , host , 'set' , use_pubsub = True , help = _ ( u 'publish or update a merge request' ))
+ − 35 self . need_loop = True
+ − 36
+ − 37 def add_parser_options ( self ):
+ − 38 self . parser . add_argument ( "-i" , "--item" , type = base . unicode_decoder , default = u '' , help = _ ( u "id or URL of the request to update, or nothing for a new one" ))
+ − 39 self . parser . add_argument ( "-r" , "--repository" , metavar = "PATH" , type = base . unicode_decoder , default = u '.' , help = _ ( u "path of the repository (DEFAULT: current directory)" ))
+ − 40
+ − 41 def mergeRequestSetCb ( self , published_id ):
+ − 42 if published_id :
+ − 43 self . disp ( u "Merge request published at {pub_id} " . format ( pub_id = published_id ))
+ − 44 else :
+ − 45 self . disp ( u "Merge request published" )
+ − 46 self . host . quit ( C . EXIT_OK )
+ − 47
+ − 48 def start ( self ):
+ − 49 common . checkURI ( self . args )
+ − 50 repository = os . path . expanduser ( os . path . abspath ( self . args . repository ))
+ − 51 extra = { 'update' : 'true' } if self . args . item else {}
+ − 52 self . host . bridge . mergeRequestSet (
+ − 53 self . args . service ,
+ − 54 self . args . node ,
+ − 55 repository ,
+ − 56 u 'auto' ,
+ − 57 {},
+ − 58 u '' ,
+ − 59 self . args . item ,
+ − 60 extra ,
+ − 61 self . profile ,
+ − 62 callback = self . mergeRequestSetCb ,
+ − 63 errback = partial ( self . errback ,
+ − 64 msg = _ ( u "can't create merge request: {} " ),
+ − 65 exit_code = C . EXIT_BRIDGE_ERRBACK ))
+ − 66
+ − 67
+ − 68 class MergeRequest ( base . CommandBase ):
+ − 69 subcommands = ( Set ,)
+ − 70
+ − 71 def __init__ ( self , host ):
+ − 72 super ( MergeRequest , self ) . __init__ ( host , 'merge-request' , use_profile = False , help = _ ( 'merge-request management' ))