Beispiel #1
0
        private static CommitRow CreateCommitRow(TeamFoundationRequestContext requestContext, TeamFoundationGitCommitService commitService,
                                                 TfsGitCommit gitCommit, CommitRowType rowType, PushNotification pushNotification, Dictionary <byte[], List <string> > refNames)
        {
            var    commitManifest = commitService.GetCommitManifest(requestContext, gitCommit.Repository, gitCommit.ObjectId);
            string repoUri        = gitCommit.Repository.GetRepositoryUri(requestContext);

            var commitRow = new CommitRow()
            {
                CommitId     = gitCommit.ObjectId,
                Type         = rowType,
                CommitUri    = repoUri + "/commit/" + gitCommit.ObjectId.ToHexString(),
                AuthorTime   = gitCommit.GetLocalAuthorTime(requestContext),
                Author       = gitCommit.GetAuthor(requestContext),
                AuthorName   = gitCommit.GetAuthorName(requestContext),
                AuthorEmail  = gitCommit.GetAuthorEmail(requestContext),
                Comment      = gitCommit.GetComment(requestContext),
                ChangeCounts = commitManifest.ChangeCounts
            };
            List <string> refs = null;

            refNames.TryGetValue(gitCommit.ObjectId, out refs);
            commitRow.RefNames = refs;

            return(commitRow);
        }
        public override Validation CheckRule(TeamFoundationRequestContext requestContext, PushNotification pushNotification, TfsGitRepository repository)
        {
            var result = new Validation();

            foreach (var refUpdateResult in pushNotification.RefUpdateResults)
            {
                // new or deleted refs have id==0
                if (IsNullHash(refUpdateResult.OldObjectId) ||
                    IsNullHash(refUpdateResult.NewObjectId))
                {
                    continue;
                }

                TfsGitCommit gitCommit = repository.LookupObject(requestContext, refUpdateResult.NewObjectId) as TfsGitCommit;
                if (gitCommit == null)
                {
                    continue;
                }

                string authorEmail = gitCommit.GetAuthorEmail(requestContext);
                if (!AuthorEmail.Any(pattern => Regex.IsMatch(authorEmail, pattern)))
                {
                    result.Fails         = true;
                    result.ReasonCode    = 2;
                    result.ReasonMessage = string.Format(
                        "Author email '{0}' on commit {1} is not admitted",
                        authorEmail,
                        gitCommit.ObjectId.DisplayHash());
                    break;
                }

                string committerEmail = gitCommit.GetCommitterEmail(requestContext);
                if (!CommitterEmail.Any(pattern => Regex.IsMatch(committerEmail, pattern)))
                {
                    result.Fails         = true;
                    result.ReasonCode    = 3;
                    result.ReasonMessage = string.Format(
                        "Committer email '{0}' on commit {1} is not admitted",
                        authorEmail,
                        gitCommit.ObjectId.DisplayHash());
                    break;
                } //if
            }     //for changes

            return(result);
        }