From b2863a860fe615f38112c48fb838f3ca831f8dc0 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 23 Jul 2019 15:34:45 +0300 Subject: Add: webhook for jobs --- api.py | 19 +++++++++++++++++++ curl.sh | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/api.py b/api.py index 6f6a6c7..feea489 100755 --- a/api.py +++ b/api.py @@ -188,9 +188,11 @@ class VCSWorker(API): MAX_CLONE_TIME = 1 MAX_REMOVE_TIME = 60 MAX_CREATE_REPO_TIME = 5 + MAX_SET_WEBHOOK_TIME = 60 MAX_PUSH_TIME = 60 GITLAB_DOMAIN = 'wmf-gitlab3.vm.liw.fi' GITLAB_PROJECT = 'liw' + WEBHOOK_URL = 'https://wmf2-controller.vm.liw.fi/webhook' def __init__(self, gitlab_token, artifact_token): self._gitlab_token = gitlab_token @@ -231,6 +233,7 @@ class VCSWorker(API): self._list_vars(T, D, P, name) and self._set_var(T, D, P, name, key, value) and self._list_vars(T, D, P, name) and + self._add_job_webhook(T, D, P, name) and self._push(dirname, D, P, ref, name)) if update(): @@ -308,6 +311,22 @@ class VCSWorker(API): ] return runcmd('.', argv, self.MAX_CREATE_REPO_TIME) + def _add_job_webhook(self, token, gitlab_domain, gitlab_project, name): + webhook_url = self.WEBHOOK_URL + logging.info('Adding webhook for jobs: %s', webhook_url) + name = urllib.parse.quote('%s/%s' % (gitlab_project, name), safe='') + + url = 'https://%s/api/v4/projects/%s/hooks' % (gitlab_domain, name) + argv = [ + 'curl', + url, + '-sv', '-X' 'POST', + '-d', 'url=%s' % webhook_url, + '-d', 'job_events=true', + '-HPRIVATE-TOKEN: %s' % token, + ] + return runcmd('.', argv, self.MAX_SET_WEBHOOK_TIME) + def _push(self, dirname, gitlab_domain, gitlab_project, ref, name): logging.info('Pushing %s to %s as %s', dirname, gitlab_domain, name) url = 'ssh://git@%s/%s/%s.git' % (gitlab_domain, gitlab_project, name) diff --git a/curl.sh b/curl.sh index 095c21f..493b0f8 100755 --- a/curl.sh +++ b/curl.sh @@ -33,6 +33,10 @@ case "$cmd" in https://wmf2-deployer.vm.liw.fi/publish ;; + status) + runcurl https://wmf2-controller.vm.liw.fi/status + ;; + *) echo "eek" 1>&2 exit 1 -- cgit v1.2.1