Example #1
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);
            }
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
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);
 }
Example #10
0
 public static void Pull(RepositoryVO repository)
 {
     ProcessService.Execute("git", "pull", repository.Path);
 }
Example #11
0
 public static void Fetch(RepositoryVO repository)
 {
     ProcessService.Execute("git", "fetch", repository.Path);
 }
Example #12
0
 public static void MergeBranch(RepositoryVO repository, string branchBase)
 {
     ProcessService.Execute("git", string.Format(@"merge {0}", branchBase), repository.Path);
 }