def create(self, opts): """[--private|--internal] [--group=<group>] [--description=<description>] Create a repository on gitlab to push to""" root = self.gitm('rev-parse', '--show-toplevel').stdout.strip() name = os.path.basename(root) if (opts['--group'] or self.my_login, name) in [(x.namespace.path, x.path) for x in self.gl.Project()]: err("Repository already exists") visibility_level = 20 # public if opts['--internal']: visibility_level = 10 elif opts['--private']: visibility_level = 0 kwargs = { 'name': name, 'description': opts['--description'] or "", 'visibility_level': visibility_level } if opts['--group']: group = self.find_group(opts['--group']) if not group: err("Group %s could not be found" % opts['--group']) kwargs['namespace_id'] = group.id repo = glapi.Project(self.gl, kwargs) repo.save() if 'origin' in self.remotes(): print( "Remote 'origin' already exists, adding the GitLab repository as 'gitlab'" ) self.set_origin(opts, repo=repo, remote='gitlab') else: self.set_origin(opts, repo=repo)
def apply_merge(self, opts): """[--ssh|--http] <merge-request-number> Applies a merge request as a series of cherry-picks""" repo = self.repository(opts) mn = int(opts['<merge-request-number>']) for req in repo.MergeRequest(): if req.iid == mn: mr = req break else: err("Merge request %s does not exist" % opts['<merge-request-number>']) print("Applying merge request #%d from %s: %s" % (mr.iid, mr.author.name, mr.title)) # Warnings warned = False cbr = self.gitm('rev-parse', '--symbolic-full-name', 'HEAD').stdout.strip().replace('refs/heads/', '') if cbr != mr.target_branch: print( wrap( "Merge request was filed against %s, but you're on the %s branch" % (mr.base.ref, cbr), fgcolor.red)) warned = True if mr.state == 'merged': print(wrap("Merge request was already merged", fgcolor.red)) if mr.state == 'closed': print(wrap("Merge request has already been closed", fgcolor.red)) warned = True if warned: if not self.question("Continue?", default=False): sys.exit(1) # Fetch mr if needed sha = self.git('rev-parse', '--verify', 'refs/merge/%d/head' % mr.iid).stdout.strip() if not sha: print("Fetching merge request") url = self.clone_url(glapi.Project(self.gl, mr.source_project_id), opts) self.gitm('fetch', url, 'refs/heads/%s:refs/merge/%d/head' % (mr.source_branch, mr.iid), redirect=False) head_sha = self.gitm('rev-parse', 'HEAD').stdout.strip() if self.git('merge-base', 'refs/merge/%d/head' % mr.iid, head_sha).stdout.strip() == head_sha: print("Fast-forward merging %s..refs/merge/%d/head" % (mr.target_branch, mr.iid)) self.gitm('merge', '--ff-only', 'refs/merge/%d/head' % mr.iid, redirect=False) else: print("Cherry-picking %s..refs/merge/%d/head" % (mr.target_branch, mr.iid)) self.gitm('cherry-pick', '%s..refs/merge/%d/head' % (mr.target_branch, mr.iid), redirect=False)
def create(self, opts): """[--private|--internal] [--group=<group>] [--description=<description>] Create a repository on gitlab to push to""" root = self.gitm('rev-parse', '--show-toplevel').stdout.strip() name = os.path.basename(root) if (opts['--group'] or self.my_login, name) in [(x.namespace.path, x.path) for x in self.gl.Project()]: err("Repository already exists") visibility_level = 20 # public if opts['--internal']: visibility_level = 10 elif opts['--private']: visibility_level = 0 kwargs = { 'name': name, 'description': opts['--description'] or "", 'visibility_level': visibility_level } if opts['--group']: group = self.find_group(opts['--group']) if not group: err("Group %s could not be found" % opts['--group']) kwargs['namespace_id'] = group.id repo = glapi.Project(self.gl, kwargs) i = 0 success = False while not success: try: repo.save() success = True except glapi.GitlabCreateError as gce: i += 1 time.sleep(1) if (gce.response_code != 400) \ or (not isinstance(gce.error_message, dict)) \ or (not 'base' in gce.error_message) \ or (not isinstance(gce.error_message['base'], list)) \ or (not 'The project is still being deleted. Please try again later.' in gce.error_message['base']) \ or (i >= 120): raise if 'origin' in self.remotes(): print( "Remote 'origin' already exists, adding the GitLab repository as 'gitlab'" ) self.set_origin(opts, repo=repo, remote='gitlab') else: self.set_origin(opts, repo=repo)
def create(self, opts): """[--private|--internal] [--description=<description>] Create a repository on gitlab to push to""" root = self.gitm('rev-parse', '--show-toplevel').stdout.strip() name = os.path.basename(root) if name in [x.name for x in self.gl.Project()]: err("Repository already exists") visibility_level = 20 # public if opts['--internal']: visibility_level = 10 elif opts['--private']: visibility_level = 0 glapi.Project(self.gl, {'name': name, 'description': opts['--description'] or "", 'visibility_level': visibility_level}).save() if 'origin' in self.remotes(): print("Remote 'origin' already exists, adding the GitLab repository as 'gitlab'") self.set_origin(opts, 'gitlab') else: self.set_origin(opts)
def create(self, opts): """[--private|--internal] [-d <description>] Create a repository on gitlab to push to""" root = self.gitm('rev-parse', '--show-toplevel').stdout.strip() name = os.path.basename(root) if name in [x.name for x in self.gl.Project()]: err("Repository already exists") visibility_level = 20 # public if opts['--internal']: visibility_level = 10 elif opts['--private']: visibility_level = 10 glapi.Project( self.gl, { 'name': name, 'description': opts['<description>'] or "", 'visibility_level': visibility_level }).save() opts['remotes'] = self.get_remotes(opts) self.set_origin(opts)