Commit Graph

38 Commits

Author SHA1 Message Date
Joel Brobecker
07642e1591 Factorize code to call third-party hooks even more
This commit introduces a new class (ThirdPartyHook), which centralizes
the handling of third-party hooks (scripts that project set up via
the configuration file). Most of the code is simply a move of the code
from maybe_call_thirdparty_hook, with a couple of enhancements:
  - Ability to specify the directory from which to call the hook;
  - Handling of the situation when calling the hook itself fails.

We can already see the benefits of this in function style_check_files,
where the code now necessary to call the style_checker is both clearer
and more compact.

In the future, the intent is to push this class one step further to
allow users to specify hooks to be fetched from the repository, rather
than requiring that the hooks be installed (usually by an admin) on
the machine hosting the repository. The current class' API should
allow us to implement this in a way that's transparent to all users.

Change-Id: Ie8bf8accbbfd75a91b914628fad27d780532dac4
TN: T209-005
2020-07-19 19:38:40 -07:00
Joel Brobecker
199add7429 use refs/meta/config:project.config hooks configuration immediately
This commit enhances the hooks to read the repository's configuration
from the most recent version. In particular, if an update is updating
the refs/meta/config reference, then read the configuration from that
update, instead of reading from the existing refs/meta/config reference.
For updates of all other references, the behavior remains unchanged.

A testcase (T227-003__meta_config_is_immediate) is added to verify
that refs/meta/config reference creation works as expected.

Following that change, various testcases also needed to be adapted
as follow:

  - MC27-006__meta_config_branch_create: Creating the refs/meta/config
    reference now works;

  - QC13-022__checker_config_on_its_own: This testcase was pushing
    a local branch called "meta-config" to refs/meta/config. This
    update introduced a style-checker-config-file configuration. Since
    the configuration is now taken into account right away, the update
    is was rejected due to the file not existing.

    The branch "meta-config" is renamed to "meta-config-missing",
    and a new branch "meta-config" was created, containg the missing
    file in addition to the configuration changes above.

    We first try to push the "meta-config-missing" to verify
    that this is rejected. We then try to push the (new) "meta-config"
    branch, verifying that the presence of the config file allows
    the push to be accepted.

  - T209-001__update_hook_not_found: A similar situation to the above,
    but with the update hook. The added comments in the testcase
    should make the changes self-explanatory.

  - T209-001__update_hook_reject: Modify the update-hook, which is
    called during reference updates, to not reject the refs/meta/config
    update the testcase is doing as part of the preliminary setup phase.

Change-Id: I0bd7bc0801ba08cd281a751759bba8c48ba0c454
TN: T227-003
2020-06-15 11:32:45 -07:00
Joel Brobecker
611eb6e110 post_update.py: Make the command-line and stdin handling a little clearer
This commit is only there to simplify the logic behind handing
the data passed when calling the post_receive.py script. In particular,
this script receives information:
  - via the command-line, with the optional --submitter-email option;
  - via stdin, with one line per reference being updated.

I don't know what I was thinking at the time, but somehow, the way
I chose to handle this was by appending to each entry from stdin
the arguments from the command-line, and then use an ArgumentParser
to pass each stdin entry. It works, but in practice, the it makes
the code more difficult to understand. In fact, when I read this code
again recently, I missed the tiny "+ sys.argv[1:]" and so it made me
(wrongly) believe that the command-line arguments were entirely ignored!

So, this commit simplifies this by clearly separating the phase
of parsing the command-line, and the phase of processing each
entry passed via stdin by git.

Change-Id: I2e01a99e7c1931a56e9b95f196a2f73f9be70a2e
TN: T223-004
2020-06-15 11:32:45 -07:00
Joel Brobecker
55be81f225 Add support for hooks.update-hook configuration option
This option allows users to specify a script to be run at update time,
for each reference being updated. This script can then be used to perform
additional checks on top of the standard checks already provided by
our git-hooks.

Change-Id: Iff527f1c9c0ba516ea5181c5f8c066c5175ef0ee
TN: T209-001
2020-06-15 11:32:45 -07:00
Joel Brobecker
844000b025 Add support for hooks.post-receive-hook config file.
For NC20-013.
2014-12-20 19:05:28 -05:00
Joel Brobecker
48f8a7b4b8 Add support for --submitter-email option in post-receive hook.
This allows a user to override the email address used when sending
email notifications.

For N213-060.
2014-02-17 21:10:39 +01:00
Joel Brobecker
cc03d0e1c8 post_receive.py: Fix pep8 warnings. 2013-12-26 14:43:40 +04:00
Joel Brobecker
2801e33c61 Always send commit emails, even if the commit is pre-existent.
The only exception is if the commit is accessible from a branch
matching the hooks.no-email config.

For MC20-019.
2013-12-25 19:36:56 +04:00
Joel Brobecker
b7a8891f73 New attribute AbstractUpdate.email_info
The primary motivation behind this patch is simplification of
the code, after having noticed that both the update and post-receive
hooks create the object.  So we can make it an attribute computed
at instantiation time, and simplify many of the methods implemented
by this class.

The second motivation behind this patch is also a slight performance
improvement, measurable when the number of files changed by a push
is getting more important. This is the change in pre_commit_checks.py,
which now takes an extra argument providing the project/repo name,
instead of recomputing it (involving running git) for each and every
file being checked.

The performance gain is fairly modest, measured to be around 4ms per
file being checked, but worth taking, given the fact that it does not
complicate the code in pre_commit_checks.
2013-01-03 14:20:25 +04:00
Joel Brobecker
6696e1cdf4 Reject update if hooks.mailinglist is not set.
For LC30-003.
2012-12-30 10:50:42 +04:00
Joel Brobecker
2c74534672 Create a daemon to send all emails.
This allows the main script to return without having to wait
for all emails to be sent, especially since there is a delay
of several seconds being introduced between each email being
sent.

For LC28-010.
2012-12-29 18:41:02 +04:00
Joel Brobecker
bd3bb58a20 Implement an email queue
The hooks now enqueue all emails in that queue, and post_receive_email
now triggers the flushing of that queue at the end of the script
execution.  The emails are still sent within the same process, but
the goal is to daemonize the part that sends it.

Part of LC28-010.
2012-12-29 17:19:14 +04:00
Joel Brobecker
cc23df1c5e print hooks.mailinglist warning in post_receive.py...
... rather than have EmailInfo.__init__ do it but controlled via
a parameter. We only want to do it once at the start of the post-
receive phase.  Doing it this way ensures that it happens exactly
as planned, in case we (slightly unintentionally) instantiate
this class more than once - and with print_warnings left as the
default, which is True.
2012-12-29 17:18:14 +04:00
Joel Brobecker
49f0d1642f Do not catch InvalidUpdate in post_receive.py.
This should never happen, as we want to (and do) catch those
situations during the "update" phase.  The exception handler
was therefore dead code by construction.
2012-12-10 11:02:37 +04:00
Joel Brobecker
3f3aef3ba2 Add Updates.pre_update_refs attribute.
This attribute is used to store the value of all references
before an update is applied.

This was computed on-demand by expand_new_commit_to_list, but we want
to make this a parameter of this function, in order to allow us to
call this function from any hook.  In particular, in the post-receive
hook, all reference values have already been updated, so the only
way to get the value of a reference prior to the update is by reverse-
applying the ref updates passed by argument to the post-receive hook.

The ultimate goal of this patch is to re-use expand_new_commit_to_list
during the phase where we send emails for each new commit.
2012-12-09 14:30:25 +04:00
Joel Brobecker
322f354336 Fix incorrect parameter order in post_receive_one debug trace.
Adjust all affected testcases accordingly.
2012-12-09 14:00:59 +04:00
Joel Brobecker
6a4cbaeee2 fix call to warn in post_receive_one.
Detected while working on unit-testing it...
For LB23-003.
2012-11-22 20:52:36 -08:00
Joel Brobecker
e729a670bf Merge the AbstractRefChange class into the updates.AbstractUpdate class.
This finally merges the two parallel infrastructures defined in
post_receive.py and the update modules+sub-modules.  This allows
us to treat each type of update within its own module, rather
than having a gigantic post_receive.py file.  Also, every aspect
related to a given update is all handled within the same module.

There was a unit test for post_receive.py's AbstractRefChange,
which has now been replaced by the corresponding unit test for
class update.AbstractUpdate.  This also required a minor upgrade
of the unit-test infrastructure.

The changes should all be internal. There should be no user-visible
changes.
2012-11-22 18:47:27 -08:00
Joel Brobecker
138b98ea3e Introduce the updates.emails.Email class.
Update post_receive.py to use it. Also delete update.emails.send_email,
as this service is now taken care of by the Email class.
2012-11-22 16:23:57 -08:00
Joel Brobecker
c764116a85 Create new updates.emails.EmailInfo class.
This class computes various pieces of info needed when sending
emails, and aggregates that info into one object for easy use
across functions.  Adjust the rest of the code accordingly.
2012-11-22 15:48:07 -08:00
Joel Brobecker
ee16a31a0f Remove Unnecessary imports in post_receive.py.
Some I forgot to do, probably in the following commit:
    commit 9b208be4cd
    Move email sending out of post_receive.py...
2012-11-22 14:48:29 -08:00
Joel Brobecker
97bb0d5ae3 Delete PostReceiveError and use InvalidUpdate instead.
This will simplify things when we merge the code for the update
and post-receive hooks.
2012-11-18 14:53:10 -08:00
Joel Brobecker
9b208be4cd Move email sending out of post_receive.py...
I chose to put it inside its own submodule of updates.
2012-11-18 14:25:12 -08:00
Joel Brobecker
de657028a1 Change terminology for tags: unannotated -> lightweight.
Unannotated was too clunky and too close to annotated.
2012-11-18 11:10:03 -08:00
Joel Brobecker
9819d2ed5c post_receive: Rename parameter from refs to updated_refs.
It makes it clearer what the refs are.  Otherwise, it's possible to get
confused and think that these are all the refs in the repository.
2012-11-17 16:10:36 -08:00