Automating Review Requests with ReviewBoard and Mercurial using Python hooks

∥☆過路亽.° 提交于 2020-01-22 10:07:06

问题


Here is my problem:

I got a remote mercurial repository where the hook is gonna be setup either incoming or changegroup, and I got a ReviewBoard setup on a different server. The idea is to automate review request tickets generation upon push from devs into the remote repository. Of course, I would need a hook that invoke post-review that also uses submit-as user which extracted using the mercurial api (ctx.user()), or else all the review requests tickets would be in the name of the user that connects the remote repository to the reviewboard server.

My main dilemma is actually getting the start revision and the stop revision , if I use incoming I'll be getting all changesets nodes but of course the hook is getting invoked everytime so there is no status kept between each invocation. On the other hand if I use changegroup I only get the first changeset and I cannot compare.As well for comparaison I need a way to keep the previous tip to send it to post-review basically :

post-review --revision-range=previoustip:newtip --submit-as=ctx.user() 

If you got any ideas on how to solve the problem, I would be happy. I am writing the hook in python obviously.


回答1:


Not sure if this is quite what you need, but this is something I use for executing a commit message check in pretty much the same circumstances, it has to check each change and verify information based on the user. In the same way I need to check the user the changelist is for, not the 'pushing' user. It should be fairly easy to do something like build up the sets of changes for a particular user and the start and end revisions in 'chunks' whilst looping through the changes in the changegroup.

The return is because it is used as a pretxnchangegroup hook

def checkAllCommitMessage(ui, repo, node, **kwargs):
    """    
    Checks all inbound changeset messages from a push for adherence to the commit message rules.
    """

    # for each change being submitted
    # get all the details, and call the trigger
    fail = False

    for rev in xrange(repo[node].rev(), len(repo)):
        # get context (change)
        ctx = repo[rev]

        # user who commited the change (NOT necessarily the one who is doing push)
        user = ctx.user()

        # do the hook stuff here...
        # set fail to True if something goes wrong

    return fail


来源:https://stackoverflow.com/questions/7675917/automating-review-requests-with-reviewboard-and-mercurial-using-python-hooks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!