Skip to content

Instantly share code, notes, and snippets.

@markuskreitzer
Created January 18, 2024 19:33
Show Gist options
  • Save markuskreitzer/aa882c7a3bebc11ce0d5e5f07ca174b9 to your computer and use it in GitHub Desktop.
Save markuskreitzer/aa882c7a3bebc11ce0d5e5f07ca174b9 to your computer and use it in GitHub Desktop.
how to mass create branch and MRs
import gitlab
import argparse
from typing import Iterable
def fix_cicd(project: Project, replacements:Iterable, branch='gitlab-ultimate-migration'):
f = project.files.get('.gitlab-ci.yml', ref=branch)
f_new = f.content
for replacement in replacements:
f_new.replace(replacement[0], repalcement[1])
f_new.save(branch=branch, commit_message='Updated CICD file.')
def check_for_cicd_config(project: Project) -> bool:
f = project.files.get('.gitlab-ci.yml', ref='master')
if f:
return True
else:
return False
def create_branch(project: Project, branch_name:str = 'cicd-update', branch_ref: str = 'master', mr_name:str = 'CICD Update'):
br = project.branches.create({ 'branch': branch_name,'ref': branch_ref})
mr = project.mergerequests.create({'source_branch': branch_name,
'target_branch': branch_ref,
'title': mr_name,
'labels': ['DevSecOps', 'GitlabMigration']})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment