Skip to content

Auto generate config from an internal GitLab instance

Gavin M. Roy edited this page Dec 26, 2018 · 1 revision

The following example will build a config for an internal GitLab CE/EE install.

import json

import requests

config = {
  'max-concurrent-indexers': 2,
  'dbpath': 'data',
  'health-check-uri': '/status',
  'repos': {}
}

url = 'https://gitlab.example.com/api/v4/projects'
while True:
    result = requests.get(url)
    data = result.json()
    for row in data:
        config['repos'][row['name_with_namespace']] = {
            'url': row['http_url_to_repo'],
            'exclude-dot-files': True,
            'url-pattern': {
                'base-url': '{url}/blob/master/{path}{anchor}',
                'anchor': '#L{line}'
            }
        }
    if 'next' not in result.links:
        break
    url = result.links['next']['url']

with open('config.json', 'w') as handle:
    json.dump(config, handle, sort_keys=True, indent=2)