diff options
author | ETL <etlweather@keylimebox.org> | 2016-03-12 16:53:26 -0500 |
---|---|---|
committer | ETL <etlweather@keylimebox.org> | 2016-03-12 16:53:26 -0500 |
commit | 71f22c557eece1a0e991c29c54b8d00b5cee6673 (patch) | |
tree | 5c8d23c286c7401f89a14dd91e83d6043ce2bdf0 /GitAutoDeploy.py | |
parent | 997e40d045ee710b74a9b35afaa5dc26b7c66bc0 (diff) | |
download | Git-Auto-Deploy-71f22c557eece1a0e991c29c54b8d00b5cee6673.zip Git-Auto-Deploy-71f22c557eece1a0e991c29c54b8d00b5cee6673.tar.gz Git-Auto-Deploy-71f22c557eece1a0e991c29c54b8d00b5cee6673.tar.bz2 |
Changes to a more versatile filter mechanism.
I found myself needing to filter the build events using the build
status (GitLab sends web hook events on build status changes so you
get "running" events which aren't very useful in deploy context).
Instead of building a whole lot of variable, parsing all possible
options I or others may want in the future, I coded the changes so that
any element from the web hook data is simply available for filtering.
I put in some code so that the earlier functionality works too -
specifically the action filter option which isn't an attribute in
GitLab's web hook data.
Diffstat (limited to 'GitAutoDeploy.py')
-rwxr-xr-x | GitAutoDeploy.py | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py index c1d98ca..fd4e193 100755 --- a/GitAutoDeploy.py +++ b/GitAutoDeploy.py @@ -171,7 +171,7 @@ class WebhookRequestHandler(BaseHTTPRequestHandler): from threading import Timer # Extract repository URL(s) from incoming request body - repo_urls, ref, action = self.get_repo_params_from_request() + repo_urls, ref, action, data = self.get_repo_params_from_request() self.send_response(200) self.send_header('Content-type', 'text/plain') self.end_headers() @@ -179,7 +179,8 @@ class WebhookRequestHandler(BaseHTTPRequestHandler): # Wait one second before we do git pull (why?) Timer(1.0, GitAutoDeploy.process_repo_urls, (repo_urls, ref, - action)).start() + action, + data)).start() def log_message(self, format, *args): """Overloads the default message logging method to allow messages to @@ -320,7 +321,7 @@ class WebhookRequestHandler(BaseHTTPRequestHandler): logger.error("ERROR - Unable to recognize request origin. Don't know how to handle the request.") logger.info("Event details - ref: %s; action: %s" % (ref or "master", action)) - return repo_urls, ref or "master", action + return repo_urls, ref or "master", action, data # Used to describe when a filter does not match a request @@ -394,7 +395,7 @@ class GitAutoDeploy(object): return mpid @staticmethod - def process_repo_urls(urls, ref, action): + def process_repo_urls(urls, ref, action, data): import os import time import logging @@ -413,36 +414,23 @@ class GitAutoDeploy(object): try: # Verify that all filters matches the request (if any filters are specified) if 'filters' in repo_config: - for filter in repo_config['filters']: - - # Filter with both action and ref? - if 'action' in filter and 'ref' in filter: - - if filter['action'] == action and filter['ref'] == ref: - # This filter is a match, OK to proceed - continue - - raise FilterMatchError() + filter_matched = True; - # Filter with only action? - if 'action' in filter: + # at least one filter must match + for filter in repo_config['filters']: - if filter['action'] == action: - # This filter is a match, OK to proceed + # all options specified in the filter must match + for filter_key, filter_value in filter.iteritems(): + # support for earlier version so it's non-breaking functionality. + if filter_key == 'action' and filter_value == action: continue - raise FilterMatchError() - - # Filter with only ref? - if 'ref' in filter: - - if filter['ref'] == ref: - # This filter is a match, OK to proceed + if filter_key not in data or filter_value != data[filter_key]: + filter_matched = False continue - raise FilterMatchError() - - # Filter does not match, do not process this repo config + if not filter_matched: + logger.info ("No filter matched") raise FilterMatchError() except FilterMatchError as e: |