-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathgitlab_fix_refs.py
37 lines (34 loc) · 1.38 KB
/
gitlab_fix_refs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gitlab
import random
import string
import re
import os
import subprocess
import shutil
# GitLab connection
gl = gitlab.Gitlab('https://gitlab.example.com', private_token='superSecret')
shutil.rmtree('code',ignore_errors=True)
# adding an empty commit everywhere
all_orgs = gl.groups.list()
skip_orgs = ['someorg']
for org in all_orgs:
print(org.name)
if org.name in skip_orgs:
print("Skip group", org.name)
continue
projects = org.projects.list(all=True)
for project in projects:
print(project.name)
id=project.id
mrs=gl.projects.get(id=id).mergerequests.list(state='opened', sort='desc',page=1, per_page=10000)
os.mkdir('code')
print(subprocess.run(["git", "clone", project.ssh_url_to_repo, "code"], capture_output=True))
for mr in mrs:
print(project.name, id, mr.title, mr.source_branch, '=>', mr.target_branch)
print(subprocess.run(["git", "checkout", mr.source_branch], cwd='code', capture_output=True))
print(subprocess.run(["git", "pull"], cwd='code', capture_output=True))
print(subprocess.run(["git", "commit", "--allow-empty", "-m", "Nothing here"], cwd='code', capture_output=True))
print(subprocess.run(["git", "push"], cwd='code', capture_output=True))
shutil.rmtree('code',ignore_errors=True)