2018-08-07 23:29:17 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import requests
|
|
|
|
import sys
|
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
from typing import Dict, Tuple, List
|
2018-10-23 17:04:43 +00:00
|
|
|
from urllib.parse import urlparse
|
2018-08-07 23:29:17 +00:00
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
GSTREAMER_MODULES: List[str] = [
|
|
|
|
# 'orc',
|
2018-08-07 23:29:17 +00:00
|
|
|
'gst-build',
|
|
|
|
'gstreamer',
|
|
|
|
'gst-plugins-base',
|
|
|
|
'gst-plugins-good',
|
|
|
|
'gst-plugins-bad',
|
|
|
|
'gst-plugins-ugly',
|
|
|
|
'gst-libav',
|
|
|
|
'gst-devtools',
|
|
|
|
'gst-docs',
|
|
|
|
'gst-editing-services',
|
|
|
|
'gst-omx',
|
|
|
|
'gst-python',
|
|
|
|
'gst-rtsp-server'
|
|
|
|
]
|
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
MANIFEST_TEMPLATE: str = """<?xml version="1.0" encoding="UTF-8"?>
|
2018-08-07 23:29:17 +00:00
|
|
|
<manifest>
|
2018-10-23 14:02:37 +00:00
|
|
|
<remote fetch="{}" name="user"/>
|
2018-08-07 23:29:17 +00:00
|
|
|
<remote fetch="https://gitlab.freedesktop.org/gstreamer/" name="gstreamer"/>
|
|
|
|
<remote fetch="git://anongit.freedesktop.org/gstreamer/" name="origin"/>
|
2018-10-23 14:02:37 +00:00
|
|
|
{}
|
2018-08-07 23:29:17 +00:00
|
|
|
</manifest>"""
|
|
|
|
|
|
|
|
|
2018-10-23 19:10:16 +00:00
|
|
|
def request_raw(path: str, token: str, project_url: str) -> Dict[str, str]:
|
|
|
|
gitlab_header: Dict[str, str] = {'JOB_TOKEN': token }
|
|
|
|
base_url: str = get_hostname(project_url)
|
2018-08-07 23:29:17 +00:00
|
|
|
|
2018-10-23 17:04:43 +00:00
|
|
|
return requests.get(f"https://{base_url}/api/v4/" + path, headers=gitlab_header).json()
|
2018-08-07 23:29:17 +00:00
|
|
|
|
2018-10-23 14:02:37 +00:00
|
|
|
|
2018-10-23 19:10:16 +00:00
|
|
|
def request(path: str) -> Dict[str, str]:
|
|
|
|
token = os.environ["CI_JOB_TOKEN"]
|
|
|
|
project_url = os.environ['CI_PROJECT_URL']
|
|
|
|
return request_raw(path, token, project_url)
|
|
|
|
|
|
|
|
|
2018-10-23 19:04:20 +00:00
|
|
|
def get_hostname(url: str) -> str:
|
|
|
|
return urlparse(url).hostname
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_hostname():
|
|
|
|
gitlab = 'https://gitlab.com/example/a_project'
|
|
|
|
assert get_hostname(gitlab) == 'gitlab.com'
|
|
|
|
|
|
|
|
fdo = 'https://gitlab.freedesktop.org/example/a_project'
|
|
|
|
assert get_hostname(fdo) == 'gitlab.freedesktop.org'
|
|
|
|
|
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
def find_repository_sha(module: str, branchname: str) -> Tuple[str, str]:
|
2018-08-07 23:29:17 +00:00
|
|
|
for project in request('projects?search=' + module):
|
|
|
|
if project['name'] != module:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if 'namespace' not in project:
|
|
|
|
# print("No 'namespace' in: %s - ignoring?" % project, file=sys.stderr)
|
|
|
|
continue
|
|
|
|
|
2018-10-23 13:34:19 +00:00
|
|
|
id = project['id']
|
2018-08-07 23:29:17 +00:00
|
|
|
if project['namespace']['name'] in useful_namespaces:
|
|
|
|
if project['namespace']['name'] == user_namespace:
|
|
|
|
# If we have a branch with same name, use it.
|
2018-10-23 13:34:19 +00:00
|
|
|
for branch in request(f"{id}/repository/branches"):
|
2018-08-07 23:29:17 +00:00
|
|
|
if branch['name'] == branchname:
|
2018-10-23 13:34:19 +00:00
|
|
|
name = project['namespace']['name']
|
|
|
|
print(f"{name}/{branchname}")
|
2018-08-07 23:29:17 +00:00
|
|
|
|
|
|
|
return 'user', branch['commit']['id']
|
|
|
|
else:
|
2018-10-23 13:34:19 +00:00
|
|
|
for branch in request(f"{id}/repository/branches"):
|
2018-08-07 23:29:17 +00:00
|
|
|
if branch['name'] == branchname:
|
2018-10-23 13:34:19 +00:00
|
|
|
print(f"gstreamer/{branchname}")
|
2018-08-07 23:29:17 +00:00
|
|
|
return 'gstreamer', branch['commit']['id']
|
|
|
|
|
2018-10-23 13:34:19 +00:00
|
|
|
branch, = request(f"{id}/repository/branches?search=master")
|
2018-08-07 23:29:17 +00:00
|
|
|
print('gstreamer/master')
|
|
|
|
return 'gstreamer', branch.attributes['commit']['id']
|
|
|
|
|
|
|
|
print('origin/master')
|
|
|
|
return 'origin', 'master'
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-10-23 12:41:58 +00:00
|
|
|
user_namespace: str = os.environ['CI_PROJECT_NAMESPACE']
|
|
|
|
project_name: str = os.environ['CI_PROJECT_NAME']
|
|
|
|
branchname: str = os.environ['CI_COMMIT_REF_NAME']
|
2018-08-07 23:29:17 +00:00
|
|
|
|
2018-10-23 12:41:58 +00:00
|
|
|
useful_namespaces: List[str] = ['gstreamer']
|
2018-08-07 23:29:17 +00:00
|
|
|
if branchname != 'master':
|
|
|
|
useful_namespaces.append(user_namespace)
|
|
|
|
|
|
|
|
# Shouldn't be needed.
|
2018-10-23 12:41:58 +00:00
|
|
|
remote: str = "git://anongit.freedesktop.org/gstreamer/"
|
|
|
|
projects: str = ''
|
2018-10-23 14:02:37 +00:00
|
|
|
project_template: str = " <project name=\"{}\" remote=\"{}\" revision=\"{}\" />\n"
|
2018-10-23 12:41:58 +00:00
|
|
|
user_remote: str = os.path.dirname(os.environ['CI_PROJECT_URL'])
|
2018-08-07 23:29:17 +00:00
|
|
|
for module in GSTREAMER_MODULES:
|
2018-10-23 13:34:19 +00:00
|
|
|
print(f"Checking {module}:", end=' ')
|
2018-08-07 23:29:17 +00:00
|
|
|
|
2018-10-23 13:34:19 +00:00
|
|
|
remote = 'origin'
|
2018-08-07 23:29:17 +00:00
|
|
|
revision = None
|
|
|
|
if module == project_name:
|
|
|
|
revision = os.environ['CI_COMMIT_SHA']
|
2018-10-23 13:34:19 +00:00
|
|
|
remote = 'user'
|
|
|
|
print(f"{user_namespace}/{branchname}")
|
2018-08-07 23:29:17 +00:00
|
|
|
else:
|
|
|
|
remote, revision = find_repository_sha(module, branchname)
|
|
|
|
|
|
|
|
if not revision:
|
|
|
|
revision = 'master'
|
2018-10-23 14:02:37 +00:00
|
|
|
projects += project_template.format(module, remote, revision)
|
2018-08-07 23:29:17 +00:00
|
|
|
|
|
|
|
with open('manifest.xml', mode='w') as manifest:
|
2018-10-23 14:02:37 +00:00
|
|
|
print(MANIFEST_TEMPLATE.format(user_remote, projects), file=manifest)
|