Commit a49607b5 authored by Thibault Saunier's avatar Thibault Saunier 🌵
Browse files

gitlab: Add a script to build manifest from a gitlab CI context

parent f4b08721
#!/usr/bin/env python3
import os
import requests
import sys
MANIFEST_TEMPLATE = """<?xml version="1.0" encoding="UTF-8"?>
<remote fetch="%s" name="user"/>
<remote fetch="" name="origin"/>
from pprint import pprint
def request(path):
gitlab_header = {'JOB_TOKEN': os.environ["CI_JOB_TOKEN"]}
url = '' + path
# print("requests.get('%s', headers=gitlab_header)-> %s" % (url,
# pprint(vars(requests.get(url, headers=gitlab_header)))))
return requests.get(url, headers=gitlab_header).json()
def find_repository_sha(module, branchname):
projects = request('projects?owned=true&search=' + module) + request('groups/gstreamer/projects?search=' + module)
for project in projects:
if project['name'] != module:
if 'namespace' not in project:
print("No 'namespace' in: %s - ignoring?" % project, file=sys.stderr)
if project['namespace']['name'] in useful_namespaces:
if project['namespace']['name'] == user_namespace:
# If we have a branch with same name, use it.
for branch in request('projects/%s/repository/branches' % project['id']):
if branch['name'] == branchname:
return 'user', branch['commit']['id'], "%s/%s" % (project['namespace']['name'], branchname)
for current_branchname in [branchname, "master"]:
branches = request('projects/%s/repository/branches?search=%s' % (project['id'], current_branchname))
for branch in branches:
if branch['name'] == current_branchname:
return 'origin', branch['commit']['id'], 'origin/master'
assert("No branch found, not even master?! %s" % branches is None)
return 'origin', 'master', 'origin/master'
if __name__ == "__main__":
user_namespace = os.environ['CI_PROJECT_NAMESPACE']
project_name = os.environ['CI_PROJECT_NAME']
branchname = os.environ['CI_COMMIT_REF_NAME']
useful_namespaces = ['gstreamer']
if branchname != 'master':
# Shouldn't be needed.
remote = "git://"
projects = ''
project_template = ' <project name="%(module)s" remote="%(remote)s" revision="%(revision)s" refname="%(refname)s/>\n'
user_remote = os.path.dirname(os.environ['CI_PROJECT_URL'])
for module in GSTREAMER_MODULES:
print("Checking %s:" % module, end=' ')
remote = "origin"
revision = None
if module == project_name:
revision = os.environ['CI_COMMIT_SHA']
remote = "user"
refname = "%s/%s" % (user_namespace, branchname)
remote, revision, refname = find_repository_sha(module, branchname)
if not revision:
revision = 'master'
projects += project_template % {'module': module, 'refname': refname, 'remote': remote, 'revision': revision}
with open('manifest.xml', mode='w') as manifest:
print(MANIFEST_TEMPLATE % (user_remote, projects), file=manifest)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment