Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import gitlab
- REPOS = [
- {'url': 'git@salsa.debian.org:ina-guest/logbook', 'branch': 'master', 'id': 26753},
- #{'url': 'https://salsa.debian.org/debian/python-icecream', 'branch': 'master'},
- ]
- #DOCKER_IMAGE = 'debian:unstable'
- DOCKER_IMAGE = 'upstramer'
- UPSTREAM_BRANCH = 'upstream-update'
- GITLAB_URL = 'https://salsa.debian.org'
- GITLAB_PRIVATE_TOKEN = ''
- BOT_REPO_ID = 26754
- SALSA = gitlab.Gitlab(GITLAB_URL, private_token=GITLAB_PRIVATE_TOKEN)
- class Container():
- def __init__(self):
- pass
- def start(self):
- self.container_id = subprocess.check_output([
- 'docker', 'run', '--detach=true', '-w=/root/workspace',
- DOCKER_IMAGE, 'sleep', 'infinity'
- ]).decode('UTF-8').strip()
- def run(self, command, path='/root/workspace/repo'):
- proc = subprocess.Popen(
- self._(command, path),
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- stdout, stderr = proc.communicate()
- exit_code = proc.poll()
- return exit_code, stdout, stderr
- def keys(self):
- # Polemic.
- # Como pushea sino?
- subprocess.check_call(['docker', 'cp', '/home/ina/.ssh', '{}:/root/.ssh'.format(self.container_id)])
- subprocess.check_call(['docker', 'exec', self.container_id, 'sh', '-c', 'chown -R root. /root/.ssh'])
- def stop(self):
- subprocess.check_call(['docker', 'stop', self.container_id])
- subprocess.check_call(['docker', 'rm', '-f', self.container_id])
- def _(self, command, path):
- docker_exec = ['docker', 'exec', '-w', path, self.container_id, 'sh', '-c']
- return docker_exec + [command]
- def create_mr(repo):
- project = SALSA.projects.get(repo['id'])
- project.mergerequests.create(
- source_branch=UPSTREAM_BRANCH,
- target_branch='master',
- remove_source_branch=True,
- title='New upstream release',
- description='Please find tests output here',
- )
- def notify_downstream(virt, repo):
- virt.run('gbp dch'.format(**globals()))
- _, stdout, stderr = virt.run('dpkg-parsechangelog -S Version')
- branch_name = '{}_{}'.format(UPSTREAM_BRANCH, stdout.strip().decode('utf-8'))
- virt.run('git checkout -b {branch_name}'.format(**locals()))
- virt.run('git commit -m "New upstream release" debian/changelog')
- virt.run('gbp push --debian-branch={branch_name}'.format(**locals()))
- create_mr(repo)
- def check_repo(repo):
- try:
- virt = Container()
- virt.start()
- virt.keys()
- virt.run('gbp clone {} repo'.format(repo['url']), path='/root/workspace')
- exit_code, _, __ = virt.run('gbp import-orig --uscan --no-interactive')
- if exit_code == 0:
- notify_downstream(virt, repo)
- except Exception as e:
- raise e
- finally:
- virt.stop()
- def main():
- for repo in REPOS:
- check_repo(repo)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement