def check(self, branch, old_sha, new_sha):
        logging.debug("Run: branch=%s, old_sha=%s, new_sha=%s", branch,
                      old_sha, new_sha)
        logging.debug("params=%s", self.params)

        try:
            pusher = self.params['user_name']
            proj_key = self.params['proj_key']
            repo_name = self.params['repo_name']
            smtp_server = self.params['smtp_server']
            smtp_port = self.params['smtp_port']
            smtp_from = self.params['smtp_from']
            email_domail = self.params['email_domain']
        except KeyError as err:
            logging.error("%s not in hook settings", err)
            raise RuntimeError(
                "%s not in hook settings, check githooks configuration" % err)

        # Do not run the hook if the branch is being deleted
        if new_sha == '0' * 40:
            logging.debug("Deleting the branch, skip the hook")
            return True, []

        mails = self.compose_mail(branch, old_sha, new_sha)
        hookutil.send_mail(
            mails, smtp_from,
            "%s/%s - Hook email-mention: You were mentioned in a commit message"
            % (proj_key, repo_name), smtp_server, smtp_port)

        return True, []
Beispiel #2
0
    def check(self, branch, old_sha, new_sha):
        logging.debug("Run: branch=%s, old_sha=%s, new_sha=%s",
                      branch, old_sha, new_sha)
        logging.debug("params=%s", self.params)

        try:
            pusher = self.params['user_name']
            proj_key = self.params['proj_key']
            repo_name = self.params['repo_name']
            smtp_server = self.params['smtp_server']
            smtp_port = self.params['smtp_port']
            smtp_from = self.params['smtp_from']
            email_domail = self.params['email_domain']
        except KeyError as err:
            logging.error("%s not in hook settings", err)
            raise RuntimeError("%s not in hook settings, check githooks configuration" % err)

        # Do not run the hook if the branch is being deleted
        if new_sha == '0' * 40:
            logging.debug("Deleting the branch, skip the hook")
            return True, []

        mails = self.compose_mail(branch, old_sha, new_sha)
        hookutil.send_mail(mails, smtp_from,
            "%s/%s - Hook email-mention: You were mentioned in a commit message" % (proj_key, repo_name),
            smtp_server, smtp_port)

        return True, []
Beispiel #3
0
    def check(self, branch, old_sha, new_sha):
        logging.debug("Run: branch=%s, old_sha=%s, new_sha=%s", branch,
                      old_sha, new_sha)
        logging.debug("params=%s", self.params)

        try:
            pusher = self.params['user_name']
            proj_key = self.params['proj_key']
            repo_name = self.params['repo_name']
            smtp_server = self.params['smtp_server']
            smtp_port = self.params['smtp_port']
            smtp_from = self.params['smtp_from']
        except KeyError as err:
            logging.error("%s not in hook settings", err)
            raise RuntimeError(
                "%s not in hook settings, check githooks configuration" % err)

        # Do not run the hook if the branch is being deleted
        if new_sha == '0' * 40:
            logging.debug("Deleting the branch, skip the hook")
            return True, []

        # Check if branch matches any of the whitelist
        for branch_re in self.settings:
            try:
                branch_rec = re.compile(branch_re)
            except re.error:
                logging.warning("Branch regexp '%s' does not compile, skip",
                                branch_re)
                continue

            if branch_rec.match(branch):
                logging.debug("Matched: %s", branch_re)
                mails = self.compose_mail(branch, old_sha, new_sha)
                hookutil.send_mail(
                    mails, smtp_from,
                    "%s/%s - Hook notify: Files you subscribed to were modified"
                    % (proj_key, repo_name), smtp_server, smtp_port)

                return True, []

        logging.debug("Branch %s does not match any of %s, skip the hook",
                      branch, ', '.join(self.settings))

        return True, []
Beispiel #4
0
    def check(self, branch, old_sha, new_sha):
        logging.debug("Run: branch=%s, old_sha=%s, new_sha=%s",
                      branch, old_sha, new_sha)
        logging.debug("params=%s", self.params)

        try:
            pusher = self.params['user_name']
            proj_key = self.params['proj_key']
            repo_name = self.params['repo_name']
            smtp_server = self.params['smtp_server']
            smtp_port = self.params['smtp_port']
            smtp_from = self.params['smtp_from']
        except KeyError as err:
            logging.error("%s not in hook settings", err)
            raise RuntimeError("%s not in hook settings, check githooks configuration" % err)

        # Do not run the hook if the branch is being deleted
        if new_sha == '0' * 40:
            logging.debug("Deleting the branch, skip the hook")
            return True, []

        # Check if branch matches any of the whitelist
        for branch_re in self.settings:
            try:
                branch_rec = re.compile(branch_re)
            except re.error:
                logging.warning("Branch regexp '%s' does not compile, skip", branch_re)
                continue

            if branch_rec.match(branch):
                logging.debug("Matched: %s", branch_re)
                mails = self.compose_mail(branch, old_sha, new_sha)
                hookutil.send_mail(mails, smtp_from,
                    "%s/%s - Hook notify: Files you subscribed to were modified" % (proj_key, repo_name),
                    smtp_server, smtp_port)

                return True, []

        logging.debug("Branch %s does not match any of %s, skip the hook", branch, ', '.join(self.settings))

        return True, []