Exemplo n.º 1
0
 public static void Commit(RepositoryVO repository, string message)
 {
     if (repository.HasChangesNotCommited)
     {
         ProcessService.Execute("git", string.Format(@"commit -m ""{0}""", message), repository.Path);
     }
 }
Exemplo n.º 2
0
        public static void UpdateStatus(RepositoryVO repository)
        {
            string response = ProcessService.Execute("git", "status", repository.Path);
            Match  match    = Regex.Match(response, ER_BRANCH);

            repository.Branch = match.Groups["name"].Value;
            repository.HasChangesNotStaged = Regex.IsMatch(response, ER_HASCHANGES_NOT_STAGED);
            if (!repository.HasChangesNotStaged)
            {
                repository.HasChangesNotStaged = Regex.IsMatch(response, ER_HASCHANGES_UNTRACKED_FILES);
            }
            repository.Head = null;
            match           = Regex.Match(response, ER_BRANCH_AHREAD);
            if ((match != null) && (!string.IsNullOrEmpty(match.Groups["head"].Value)))
            {
                repository.Head = Int32.Parse(match.Groups["head"].Value);
            }
            match = Regex.Match(response, ER_BRANCH_BEHIND);
            if ((match != null) && (!string.IsNullOrEmpty(match.Groups["head"].Value)))
            {
                repository.Head = 0 - Int32.Parse(match.Groups["head"].Value);
            }
            repository.HasChangesNotCommited = Regex.IsMatch(response, ER_HASCHANGES_NOT_COMMITED);
            repository.HasUnmergedPaths      = Regex.IsMatch(response, ER_HASCHANGES_UNMERGED_PATH);
        }
Exemplo n.º 3
0
 public static bool IsConfiguratedCode()
 {
     if (_codePath == null)
     {
         string response = ProcessService.Execute("where", "code");
         if (response.Contains("INFO:"))
         {
             _codePath = "";
         }
         else
         {
             _codePath = "";
             string[] lines = response.Split("\r\n");
             for (int i = lines.Length - 1; i >= 0; i--)
             {
                 string line = lines[i].Trim();
                 if (string.IsNullOrEmpty(line))
                 {
                     continue;
                 }
                 _codePath = line;
                 break;
             }
         }
     }
     return(!string.IsNullOrEmpty(_codePath));
 }
Exemplo n.º 4
0
 public static void Add(RepositoryVO repository)
 {
     if (repository.HasChangesNotStaged)
     {
         ProcessService.Execute("git", "add .", repository.Path);
     }
 }
Exemplo n.º 5
0
 public static void Push(RepositoryVO repository)
 {
     if ((!repository.Head.HasValue) || (repository.Head.Value < 0))
     {
         return;
     }
     ProcessService.Execute("git", "push", repository.Path);
 }
Exemplo n.º 6
0
 public static void AddPullRequestReviewer(RepositoryVO repository, PullRequestVO pullRequest, string reviewerEmail)
 {
     if (!IsConfigurated())
     {
         return;
     }
     List <string> reviewers = new List <string>();
     string        command   = _vstsPath;
     string        arguments = string.Format("code pr reviewers add --id {0} --reviewers {1}", pullRequest.ID, reviewerEmail);
     string        response  = ProcessService.Execute(command, arguments, repository.Path);
 }
Exemplo n.º 7
0
        public static void CheckoutBranch(RepositoryVO repository, string branch)
        {
            if (repository.Branch == branch)
            {
                return;
            }
            List <string> branchs = ListBranchs(repository);

            if (branchs.Contains(branch))
            {
                ProcessService.Execute("git", string.Format(@"checkout {0}", branch), repository.Path);
            }
        }
Exemplo n.º 8
0
        public static bool HasCommits(RepositoryVO repository, WorkItemVO workItem, string branchBase)
        {
            string response = ProcessService.Execute("git", string.Format("cherry {0} {1}", branchBase, workItem.TaskID), repository.Path);

            string[] lines = response.Split("\r\n");
            foreach (string line in lines)
            {
                if (!string.IsNullOrEmpty(line.Trim()))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 9
0
        private static Dictionary <string, List <string> > ListFiles(RepositoryVO repository)
        {
            Dictionary <string, List <string> > files = new Dictionary <string, List <string> >();
            string response = ProcessService.Execute("git", "status", repository.Path);

            string[]      lines      = response.Split("\n");
            string        lastSector = null;
            List <string> buffer     = new List <string>();

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                line = line.Trim();
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                if (line.Contains("(") && line.Contains(")"))
                {
                    continue;
                }
                string sector = GetLineSector(line);
                if (sector != null)
                {
                    if ((lastSector != null) && (buffer.Count > 0))
                    {
                        files.Add(lastSector, buffer);
                    }
                    buffer     = new List <string>();
                    lastSector = sector;
                    continue;
                }
                if (lastSector != null)
                {
                    buffer.Add(line);
                }
            }
            if ((lastSector != null) && (buffer.Count > 0))
            {
                if (files.ContainsKey(lastSector))
                {
                    files[lastSector].AddRange(buffer);
                }
                else
                {
                    files.Add(lastSector, buffer);
                }
            }
            return(files);
        }
Exemplo n.º 10
0
        public static List <string> ListPullRequestReviewers(RepositoryVO repository, PullRequestVO pullRequest)
        {
            if (!IsConfigurated())
            {
                return(null);
            }
            List <string> reviewers = new List <string>();
            string        command   = _vstsPath;
            string        arguments = @"code pr reviewers list --id " + pullRequest.ID;
            string        response  = ProcessService.Execute(command, arguments, repository.Path);
            TableVO       table     = new TableVO(response);

            foreach (TableRowVO row in table.Rows)
            {
                reviewers.Add(row.GetValue("Email"));
            }
            return(reviewers);
        }
Exemplo n.º 11
0
        public static void CreateBranch(RepositoryVO repository, WorkItemVO workItem)
        {
            string branch = workItem.TaskID;

            if (repository.Branch == branch)
            {
                return;
            }
            List <string> branchs = ListBranchs(repository);

            if (branchs.Contains(branch))
            {
                CheckoutBranch(repository, branch);
                return;
            }
            ProcessService.Execute("git", string.Format(@"checkout -b {0}", branch), repository.Path);
            ProcessService.Execute("git", string.Format(@"push --set-upstream origin {0}", branch), repository.Path);
        }
Exemplo n.º 12
0
        public static List <PullRequestVO> ListPullRequests(string workingDirectory)
        {
            if (!IsConfigurated())
            {
                return(null);
            }
            List <PullRequestVO> pullRequests = new List <PullRequestVO>();
            string  command   = _vstsPath;
            string  arguments = @"code pr list";
            string  response  = ProcessService.Execute(command, arguments, workingDirectory);
            TableVO table     = new TableVO(response);

            foreach (TableRowVO row in table.Rows)
            {
                PullRequestVO pullRequest = new PullRequestVO();
                pullRequest.ID         = Int32.Parse(row.GetValue("ID"));
                pullRequest.Title      = row.GetValue("Title");
                pullRequest.Repository = row.GetValue("Repository");
                pullRequests.Add(pullRequest);
            }
            return(pullRequests);
        }
Exemplo n.º 13
0
        public static List <string> ListBranchs(RepositoryVO repository)
        {
            List <string> branchs  = new List <string>();
            string        response = ProcessService.Execute("git", "branch -a", repository.Path);

            string[] lines = response.Split("\n");
            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                if (line.StartsWith("*"))
                {
                    line = line.Substring(1);
                }
                line = line.Trim();
                if (line.StartsWith("remotes/origin/"))
                {
                    line = line.Substring("remotes/origin/".Length);
                }
                if (line.EndsWith("\r"))
                {
                    line = line.Substring(0, line.Length - ("\r".Length));
                }
                if (line.Contains("->"))
                {
                    continue;
                }
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                if (branchs.Contains(line))
                {
                    continue;
                }
                branchs.Add(line);
            }
            return(branchs);
        }
Exemplo n.º 14
0
        public static List <WorkItemVO> ListWorkItems(string workingDirectory)
        {
            List <WorkItemVO> workItems = new List <WorkItemVO>();

            if (!IsConfigurated())
            {
                return(null);
            }
            string command   = _vstsPath;
            string arguments = @"work item query --wiql ""SELECT System.ID, System.Title FROM workitems WHERE[System.AssignedTo] = @Me AND[System.State] = 'In Progress' ORDER BY System.ID DESC""";
            string response  = ProcessService.Execute(command, arguments, workingDirectory);

            string[] lines = response.Split("\r\n");
            foreach (string line in lines)
            {
                WorkItemVO workItem = CreateWorkItem(line.Trim());
                if (workItem != null)
                {
                    workItems.Add(workItem);
                }
            }
            return(workItems);
        }
Exemplo n.º 15
0
 public static void CreatePullRequest(RepositoryVO repository, WorkItemVO workItem)
 {
     string command   = _vstsPath;
     string arguments = string.Format(@"code pr create --title ""{0} {1}"" --work-items {2}", workItem.TaskID, workItem.Name, workItem.Code);
     string response  = ProcessService.Execute(command, arguments, repository.Path);
 }
Exemplo n.º 16
0
 public static void Pull(RepositoryVO repository)
 {
     ProcessService.Execute("git", "pull", repository.Path);
 }
Exemplo n.º 17
0
 public static void Fetch(RepositoryVO repository)
 {
     ProcessService.Execute("git", "fetch", repository.Path);
 }
Exemplo n.º 18
0
 public static void MergeBranch(RepositoryVO repository, string branchBase)
 {
     ProcessService.Execute("git", string.Format(@"merge {0}", branchBase), repository.Path);
 }