2

I would like to write a hook for Mercurial to do the following, an am struggling to get going.:

  • Run on central repo, and execute when changeset(s) are pushed (I think I should use the "input" or "changegroup" hook)
  • Search each commit message for a string with the format "issue:[0-9]*"
  • IF string found, call a webservice, and provide the issue number, commit message, and a list of files that were changed

So, just for starters, how can I get the commit message for each commit from the "input" or "changegroup" hook? Any advice beyond this on how to achieve the other points would also be appeciated.

Thanks for any help.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
James
  • 7,877
  • 7
  • 42
  • 57

2 Answers2

2

changegroup hook is called once per push. If you want to analyse each changeset, then you want incoming hook (there's no input hook AFAIK) — it'll be called for each changeset, with ID in HG_NODE environment variable. You can get the commit message with e.g. hg log -r $HG_NODE --template '{desc}' or via the API.

Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224
2

You will want to use the incoming hook which is called for each changeset that is applied on the repository (either via pull, push or unbundle).

In the calling script, the current changeset id will be accessible through the HG_NODE environment variable, in python you can access it with os.environ['HG_NODE'].

Depending on how you want to do it, have a look at the provided bugzilla hook as a starting point.

krtek
  • 26,334
  • 5
  • 56
  • 84
  • Thanks Cat Plus Plus, and Krtek. Both great input. I marked this as the answer as it has the bugzilla link as well, which is really useful. – James Nov 03 '11 at 20:24