Source

pyrest / pyrest / examples / hg / changeset.py

import hgapi.hgapi as hgapi
from pyrest import pyrest

def get(ref=None):
    rev = hgapi.Repo('.')[ref]

    return pyrest.OkResponse({
    'node': rev.node,
    'desc': rev.desc
    })

def post(message=None, user=None):
    
    if message is None:
        return pyrest.MalformedResponse('Need to supply a commit message')

    try:
        repo = hgapi.Repo('.')
        if not user is None:
            repo.hg_commit(message, user)
        else:
            repo.hg_commit(message)
    except Exception as e:
        if 'Out: nothing changed' in str(e):
            return pyrest.ConflictResponse('Nothing changed')
        return pyrest.ErrorResponse(str(e))
    return pyrest.CreatedResponse('Revision committed')