Ejemplo n.º 1
0
 def matchesNoRejectStatuses(self, change):
     # statuses are ANDed
     # If any of the rejected statusses are present, we return false
     for rstatus in self.reject_statuses:
         for status in change.status:
             if re2.fullmatch(rstatus, status):
                 return False
     return True
Ejemplo n.º 2
0
def regex_match(rule_regex: str, local):
    regex = re2.compile(rule_regex)
    try:
        if re2.fullmatch(regex, local):
            return True
    except TypeError:  # re2 bug "Argument 'pattern' has incorrect type (expected bytes, got PythonRePattern)"
        LOG.w("use re instead of re2 for %s %s", rule_regex, local)
        regex = re.compile(rule_regex)
        if re.fullmatch(regex, local):
            return True
    return False
Ejemplo n.º 3
0
 def matchesRequiredStatuses(self, change):
     # statuses are ORed
     # A PR head can have multiple statuses on it. If the change
     # statuses and the filter statuses are a null intersection, there
     # are no matches and we return false
     if self.required_statuses:
         for required_status in self.required_statuses:
             for status in change.status:
                 if re2.fullmatch(required_status, status):
                     return True
         return False
     return True
def membership(regex, string):
    # print(regex)
    #print(regex, string)
    return bool(re.fullmatch(regex, string))
Ejemplo n.º 5
0
    def matches(self, event, change):
        # event types are ORed
        matches_type = False
        for etype in self.types:
            if etype.match(event.type):
                matches_type = True
        if self.types and not matches_type:
            return FalseWithReason("Types %s doesn't match %s" % (
                self.types, event.type))

        # branches are ORed
        matches_branch = False
        for branch in self.branches:
            if branch.match(event.branch):
                matches_branch = True
        if self.branches and not matches_branch:
            return FalseWithReason("Branches %s doesn't match %s" % (
                self.branches, event.branch))

        # refs are ORed
        matches_ref = False
        if event.ref is not None:
            for ref in self.refs:
                if ref.match(event.ref):
                    matches_ref = True
        if self.refs and not matches_ref:
            return FalseWithReason(
                "Refs %s doesn't match %s" % (self.refs, event.ref))
        if self.ignore_deletes and event.newrev == EMPTY_GIT_REF:
            # If the updated ref has an empty git sha (all 0s),
            # then the ref is being deleted
            return FalseWithReason("Ref deletion are ignored")

        # comments are ORed
        matches_comment_re = False
        for comment_re in self.comments:
            if (event.comment is not None and
                comment_re.search(event.comment)):
                matches_comment_re = True
        if self.comments and not matches_comment_re:
            return FalseWithReason("Comments %s doesn't match %s" % (
                self.comments, event.comment))

        # actions are ORed
        matches_action = False
        for action in self.actions:
            if (event.action == action):
                matches_action = True
        if self.actions and not matches_action:
            return FalseWithReason("Actions %s doesn't match %s" % (
                self.actions, event.action))

        # check_runs are ORed
        if self.check_runs:
            check_run_found = False
            for check_run in self.check_runs:
                if re2.fullmatch(check_run, event.check_run):
                    check_run_found = True
                    break
            if not check_run_found:
                return FalseWithReason("Check_runs %s doesn't match %s" % (
                    self.check_runs, event.check_run))

        # labels are ORed
        if self.labels and event.label not in self.labels:
            return FalseWithReason("Labels %s doesn't match %s" % (
                self.labels, event.label))

        # unlabels are ORed
        if self.unlabels and event.unlabel not in self.unlabels:
            return FalseWithReason("Unlabels %s doesn't match %s" % (
                self.unlabels, event.unlabel))

        # states are ORed
        if self.states and event.state not in self.states:
            return FalseWithReason("States %s doesn't match %s" % (
                self.states, event.state))

        # statuses are ORed
        if self.statuses:
            status_found = False
            for status in self.statuses:
                if re2.fullmatch(status, event.status):
                    status_found = True
                    break
            if not status_found:
                return FalseWithReason("Statuses %s doesn't match %s" % (
                    self.statuses, event.status))

        return self.matchesStatuses(change)
Ejemplo n.º 6
0
def validate_ttp(ttp: str) -> bool:
    regex = r"^(O?[BCTFSU]\d{4}(\.\d{3})?)|(E\d{4}(\.m\d{2})?)$"
    return bool(re.fullmatch(regex, ttp, flags=re.IGNORECASE))
Ejemplo n.º 7
0
        endcount += 1

    negset = set()
    for i in range(0, 1000):
        # random regex생성
        str_list = []

        for j in range(0, random.randrange(1, 15)):
            if random.random() < 0.5:
                str_list.append('0')
            else:
                str_list.append('1')
        tmp = ''.join(str_list)

        # random regex가 맞지 않다면 추가
        if not bool(re.fullmatch(repr(regex), tmp)):
            negset.add(tmp + "\n")

        if len(negset) == 10:
            break

    if not len(negset) == 10:
        continue

    fname = "rand3_benchmarks/no" + str(no) + ".txt"
    f = open(fname, 'w')

    f.write(repr(regex) + "\n")

    f.write('++\n')
Ejemplo n.º 8
0
    def matches(self, event, change):
        # event types are ORed
        matches_type = False
        for etype in self.types:
            if etype.match(event.type):
                matches_type = True
        if self.types and not matches_type:
            return False

        # branches are ORed
        matches_branch = False
        for branch in self.branches:
            if branch.match(event.branch):
                matches_branch = True
        if self.branches and not matches_branch:
            return False

        # refs are ORed
        matches_ref = False
        if event.ref is not None:
            for ref in self.refs:
                if ref.match(event.ref):
                    matches_ref = True
        if self.refs and not matches_ref:
            return False
        if self.ignore_deletes and event.newrev == EMPTY_GIT_REF:
            # If the updated ref has an empty git sha (all 0s),
            # then the ref is being deleted
            return False

        # comments are ORed
        matches_comment_re = False
        for comment_re in self.comments:
            if (event.comment is not None
                    and comment_re.search(event.comment)):
                matches_comment_re = True
        if self.comments and not matches_comment_re:
            return False

        # actions are ORed
        matches_action = False
        for action in self.actions:
            if (event.action == action):
                matches_action = True
        if self.actions and not matches_action:
            return False

        # labels are ORed
        if self.labels and event.label not in self.labels:
            return False

        # unlabels are ORed
        if self.unlabels and event.unlabel not in self.unlabels:
            return False

        # states are ORed
        if self.states and event.state not in self.states:
            return False

        # statuses are ORed
        if self.statuses:
            status_found = False
            for status in self.statuses:
                if re2.fullmatch(status, event.status):
                    status_found = True
                    break
            if not status_found:
                return False

        if not self.matchesStatuses(change):
            return False

        return True
Ejemplo n.º 9
0
def referral_route():
    if request.method == "POST":
        if request.form.get("form-name") == "create":
            code = request.form.get("code")
            if re.fullmatch(_REFERRAL_PATTERN, code) is None:
                flash(
                    "At least 3 characters. Only lowercase letters, "
                    "numbers, dashes (-) and underscores (_) are currently supported.",
                    "error",
                )
                return redirect(url_for("dashboard.referral_route"))

            if Referral.get_by(code=code):
                flash("Code already used", "error")
                return redirect(url_for("dashboard.referral_route"))

            name = request.form.get("name")
            referral = Referral.create(user_id=current_user.id,
                                       code=code,
                                       name=name)
            Session.commit()
            flash("A new referral code has been created", "success")
            return redirect(
                url_for("dashboard.referral_route", highlight_id=referral.id))
        elif request.form.get("form-name") == "update":
            referral_id = request.form.get("referral-id")
            referral = Referral.get(referral_id)
            if referral and referral.user_id == current_user.id:
                referral.name = request.form.get("name")
                Session.commit()
                flash("Referral name updated", "success")
                return redirect(
                    url_for("dashboard.referral_route",
                            highlight_id=referral.id))
        elif request.form.get("form-name") == "delete":
            referral_id = request.form.get("referral-id")
            referral = Referral.get(referral_id)
            if referral and referral.user_id == current_user.id:
                Referral.delete(referral.id)
                Session.commit()
                flash("Referral deleted", "success")
                return redirect(url_for("dashboard.referral_route"))

    # Highlight a referral
    highlight_id = request.args.get("highlight_id")
    if highlight_id:
        highlight_id = int(highlight_id)

    referrals = Referral.filter_by(user_id=current_user.id).all()
    # make sure the highlighted referral is the first referral
    highlight_index = None
    for ix, referral in enumerate(referrals):
        if referral.id == highlight_id:
            highlight_index = ix
            break

    if highlight_index:
        referrals.insert(0, referrals.pop(highlight_index))

    payouts = Payout.filter_by(user_id=current_user.id).all()

    return render_template("dashboard/referral.html", **locals())