Grep branch from TFS ISubscriber git server plugin

Viewed 88

I am writing a TFS server side git plugin that responds to pushes and I have most of the logic worked out. The TFS in question is on-premise.

The objective: I would like to grep the branch being checked into for the existence of a file with a certain extension using the library. Essentially: git grep res -- '*.foo'. I have included a cut down version of the code.

I have searched and searched for days. Sadly this library is very poorly documented and I have have been extremely frustrated finding an answer. I really hope someone can help.

PLEASE refrain from suggesting usage of the "git" command line. I wish to use the library for this purpose, and avoid shelling out to the command line.

Here is the example code:

using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
using Microsoft.TeamFoundation.Common;
using Microsoft.TeamFoundation.Framework.Server;
using Microsoft.TeamFoundation.Git.Server;
using System.IO;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using System.Configuration;
using System.Reflection;
using System.Runtime.InteropServices;

namespace TFS.Plugins
{
    public class PluginPushSubscriber : ISubscriber
    {
        public string Name { get { return this.GetType().Name; } }

        public SubscriberPriority Priority { get { return SubscriberPriority.Normal; } }

        public Type[] SubscribedTypes()
        {
            return new Type[1] { typeof(PushNotification) };
        }

        public string Description
        {
            get { return "PluginPushSubscriber"; }
        }

        public EventNotificationStatus ProcessEvent(
            IVssRequestContext requestContext,
            NotificationType notificationType,
            object notificationEventArgs,
            out int statusCode,
            out string statusMessage,
            out ExceptionPropertyCollection properties)
        {
            //init the out variables
            statusCode = 0;
            statusMessage = string.Empty;
            properties = null;

            //DecisionPoint is where the action result (Permitted or Denied) can be drawn from subscriber logic.
            if (notificationType != NotificationType.DecisionPoint) { return EventNotificationStatus.ActionPermitted; }
            if (!(notificationEventArgs is PushNotification pushNotification)) { return EventNotificationStatus.ActionPermitted; }

            try
            {
                ***// I HAVE THE REPO....  I WOULD ALSO LIKE TO QUERY (GREP) THE BRANCH*** 

                var repositoryService = requestContext.GetService<ITeamFoundationGitRepositoryService>();
                using (var repository = repositoryService.FindRepositoryById(requestContext, pushNotification.RepositoryId))
                {
                }
            }
            catch (Exception ex)
            {
                //TODO: log the exception
                return EventNotificationStatus.ActionDenied;
            }

            return EventNotificationStatus.ActionApproved;
        }

    }
}
0 Answers
Related