Skip to content

Instantly share code, notes, and snippets.

@phaer
Created February 7, 2017 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phaer/59b488b5aaea69d5bdd0443f9903342a to your computer and use it in GitHub Desktop.
Save phaer/59b488b5aaea69d5bdd0443f9903342a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
A litte tool to generate a .mrconfig file for https://myrepos.branchable.com/
from a https://gitea.io/ account.
sudo apt install python3 python3-requests
Check possible values for your MR_REPO_TEMPLATE with
$ curl --user ${GITEA_USER}:{$GITEA_PASS} https://${GITEA_HOST}/api/v1/user/repos | jq .
"""
import os
import sys
import requests
MR_REPO_TEMPLATE = """
[{full_name}]
checkout = git clone {ssh_url}
"""
# feel free to use sys.argv[] here.
GITEA_HOST = 'gitea.example.com'
GITEA_USER = 'your-username'
GITEA_PASS = 'your-password'
def fatal(msg):
sys.stderr.write(msg)
sys.stderr.flush()
sys.exit(1)
def fetch_repos():
try:
url = 'https://{}/api/v1/user/repos'.format(GITEA_HOST)
response = requests.get(url, auth=(GITEA_USER, GITEA_PASS))
except requests.exceptions.RequestException as e:
fatal(str(e))
try:
return response.json()
except ValueError as e:
fatal('Malformed JSON: {}'.format(e))
def mr_config(repo):
try:
return MR_REPO_TEMPLATE.format(**repo)
except KeyError as e:
fatal('Unexpected JSON: {}'.format(e))
if __name__ == '__main__':
for repo in fetch_repos():
sys.stdout.write(mr_config(repo))
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment