def handle_commit(self, user=None, notify=None):
        if not self.pk:
            raise RuntimeError(
                "handle_commit() on unsaved WebHookMapping"
            )

        if user is None:
            user = self.user.username
        if notify is None:
            notify = self.notify

        self.lsr.tag = ""
        self.lsr.handled = False
        self.lsr.save()

        if not notify:
            return

        message = "Commit(s) pushed by %s to %s branch of %s" % (
            user, self.branch, self.repourl
        )
        if not self.mapped:
            message = "%s, which is not mapped yet. Please map it." % message

        fields = self.to_fields()
        fields['msg'] = message
        print message.encode('utf-8')
        launch_notify(fields)
Esempio n. 2
0
    def handle_commit(self, user=None, notify=None):
        if not self.pk:
            raise RuntimeError("handle_commit() on unsaved WebHookMapping")

        if user is None:
            user = self.user.username
        if notify is None:
            notify = self.notify

        self.lsr.tag = ""
        self.lsr.handled = False
        self.lsr.save()

        if not notify:
            return

        message = "Commit(s) pushed by %s to %s branch of %s" % (
            user, self.branch, self.repourl)
        if not self.mapped:
            message = "%s, which is not mapped yet. Please map it." % message

        fields = self.to_fields()
        fields['msg'] = message
        print message.encode('utf-8')
        launch_notify(fields)
    def trigger_build(self, user=None, tag=None, force=False):
        if not self.pk:
            raise RuntimeError(
                "trigger_build() on unsaved WebHookMapping"
            )

        # Only fire for projects which allow webhooks. We can't just
        # rely on validation since a Project may forbid hooks after
        # the hook was created
        if self.project_disabled:
            print "Project has build disabled"
            return

        handled = self.lsr.handled and self.lsr.tag == tag and not force
        if handled:
            print "build already handled, skipping"
        build = self.build and self.mapped and not handled
        qp = None
        if user is None:
            user = self.user.username

        if build:
            if tag:
                self.lsr.tag = tag

            # Find possible queue period objects
            qps = QueuePeriod.objects.filter(
                projects__name=self.project,
                projects__obs=self.obs,
            )
            for qp in qps:
                if qp.delay() and not qp.override(webuser=user):
                    print "Build trigger for %s delayed by %s" % (self, qp)
                    print qp.comment
                    build = False
                    break
            else:
                qp = None

        message = self._get_build_message(user, force, handled, qp)
        fields = self.to_fields()
        fields['msg'] = message

        if self.notify:
            launch_notify(fields)

        if build:
            fields = self.to_fields()
            launch_build(fields)
            self.lsr.handled = True

        self.lsr.save()

        return message
Esempio n. 4
0
    def trigger_build(self, user=None, tag=None, force=False):
        if not self.pk:
            raise RuntimeError("trigger_build() on unsaved WebHookMapping")

        # Only fire for projects which allow webhooks. We can't just
        # rely on validation since a Project may forbid hooks after
        # the hook was created
        if self.project_disabled:
            print "Project has build disabled"
            return

        handled = self.lsr.handled and self.lsr.tag == tag and not force
        if handled:
            print "build already handled, skipping"
        build = self.build and self.mapped and not handled
        qp = None
        if user is None:
            user = self.user.username

        if build:
            if tag:
                self.lsr.tag = tag

            # Find possible queue period objects
            qps = QueuePeriod.objects.filter(
                projects__name=self.project,
                projects__obs=self.obs,
            )
            for qp in qps:
                if qp.delay() and not qp.override(webuser=user):
                    print "Build trigger for %s delayed by %s" % (self, qp)
                    print qp.comment
                    build = False
                    break
            else:
                qp = None

        message = self._get_build_message(user, force, handled, qp)
        fields = self.to_fields()
        fields['msg'] = message

        if self.notify:
            launch_notify(fields)

        if build:
            fields = self.to_fields()
            launch_build(fields)
            self.lsr.handled = True

        self.lsr.save()

        return message