<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace TfvcBranchPolicy.CheckinPolicy.Common
{
    [Serializable]
    public class LockBranchPolicy : IBranchPolicy
    {
        [OptionalField(VersionAdded = 2)]
        private Boolean _IsLocked;
        [OptionalField(VersionAdded = 2)]
        private Boolean _IsByPassEnabled;
        [OptionalField(VersionAdded = 2)]
        private string _BypassString;

        public string BypassString
        {
            get
            {
                return _BypassString;
            }
            set
            {
                _BypassString = value;
            }
        }
        public Boolean IsLocked
        {
            get
            {
                return _IsLocked;
            }
            set
            {
                _IsLocked = value;
            }
        }

        public Boolean IsByPassEnabled
        {
            get
            {
                return _IsByPassEnabled;
            }
            set
            {
                _IsByPassEnabled = value;
            }
        }

        public List<BranchPolicyFailure> EvaluatePendingCheckin(BranchPattern branchPattern, Microsoft.TeamFoundation.VersionControl.Client.IPendingCheckin pendingCheckin)
        {
            List<BranchPolicyFailure> branchPolicyFailures = new List<BranchPolicyFailure>();
            if (branchPolicyFailures == null)
            {
                throw new ArgumentNullException("branchPolicyFailures");
            }

            Boolean lockedWithNoBypass = false;
            Boolean lockedWithUnmatchedBypass = false;
            // Evaluate LockPolicy
            if (IsLocked && !IsByPassEnabled)
            {
                lockedWithNoBypass = true;
            }
            else if (IsLocked && IsByPassEnabled)
            {

                if ((pendingCheckin.PendingChanges.Comment != null) && (BypassString != null))
                {
                    if (!pendingCheckin.PendingChanges.Comment.Contains(BypassString))
                    {
                        lockedWithUnmatchedBypass = true;
                    }

                }
                else
                {<commit_msg>Addds regex bypass support for fixes#4 +semver:minor<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace TfvcBranchPolicy.CheckinPolicy.Common
{
    [Serializable]
    public class LockBranchPolicy : IBranchPolicy
    {
        [OptionalField(VersionAdded = 2)]
        private Boolean _IsLocked;
        [OptionalField(VersionAdded = 2)]
        private Boolean _IsByPassEnabled;
        [OptionalField(VersionAdded = 2)]
        private string _BypassString;

        public string BypassString
        {
            get
            {
                return _BypassString;
            }
            set
            {
                _BypassString = value;
            }
        }
        public Boolean IsLocked
        {
            get
            {
                return _IsLocked;
            }
            set
            {
                _IsLocked = value;
            }
        }

        public Boolean IsByPassEnabled
        {
            get
            {
                return _IsByPassEnabled;
            }
            set
            {
                _IsByPassEnabled = value;
            }
        }

        public List<BranchPolicyFailure> EvaluatePendingCheckin(BranchPattern branchPattern, Microsoft.TeamFoundation.VersionControl.Client.IPendingCheckin pendingCheckin)
        {
            List<BranchPolicyFailure> branchPolicyFailures = new List<BranchPolicyFailure>();
            if (branchPolicyFailures == null)
            {
                throw new ArgumentNullException("branchPolicyFailures");
            }

            Boolean lockedWithNoBypass = false;
            Boolean lockedWithUnmatchedBypass = false;
            // Evaluate LockPolicy
            if (IsLocked && !IsByPassEnabled)
            {
                lockedWithNoBypass = true;
            }
            else if (IsLocked && IsByPassEnabled)
            {
                if ((pendingCheckin.PendingChanges.Comment != null) && (BypassString != null))
                {

                    if (!System.Text.RegularExpressions.Regex.Match(pendingCheckin.PendingChanges.Comment, BypassString).Success)
                    {
                        lockedWithUnmatchedBypass = true;
                    }
                }
                else
                {
{'fraction_non_alphanumeric': 0.06421433127790772, 'fraction_numerical': 0.001488411652136934, 'mean_word_length': 1.386605783866058, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6343620', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1126, 'n_words': 215}