コード例 #1
0
        public IActionResult RebuildReleaseDefinitions()
        {
            var vsts = new Classes.VSTS.Vsts(HttpContext.Session.GetString(Session.TOKEN));

            ViewBag.RepoCount = vsts.GetRepos(HttpContext.Session.GetString(Session.SELECTED_PROJ)).Count;

            if (!_inReleaseProcess)
            {
                var options = new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.NeverRemove);
                _cache.Remove(CACHE.RELEASES);
                ConstructReleaseDefinitions();
                //                Task.Run(() => SetReleaseDefinitions(HttpContext.Session.GetString(Session.SELECTED_PROJ)));
            }
            return(View("ProjectRepositories"));
        }
コード例 #2
0
        public IActionResult FoundProject([DataSourceRequest] DataSourceRequest request, string project)
        {
            _logger.LogInformation("This is a test");

            ViewBag.Project = project;

            HttpContext.Session.SetString(Session.SELECTED_PROJ, project);
            HttpContext.Session.SetString(Session.HEARTBEAT, System.DateTime.Now.ToString());

            var vsts = new Classes.VSTS.Vsts(HttpContext.Session.GetString(Session.TOKEN));

            ViewBag.RepoCount = vsts.GetRepos(project).Count;

            Task.Run(() => SetBuildDefinitions(project));
            Task.Run(() => SetReleaseDefinitions(project));

            return(View("ProjectRepositories"));
        }
コード例 #3
0
        public IActionResult GetRepos([DataSourceRequest] DataSourceRequest request, string projectName)
        {
            var startingFolder          = string.Empty;
            List <RepositoryVM> results = new List <RepositoryVM>();

            try
            {
                CreateStartingFolder(ref startingFolder);

                var vsts = new Classes.VSTS.Vsts(HttpContext.Session.GetString(Session.TOKEN));


                var repos = vsts.GetRepos(projectName);
                var items = repos.Repositories.OrderBy(t => t.Name).ToList();
                Parallel.ForEach(items, new ParallelOptions {
                    MaxDegreeOfParallelism = 1
                }, item =>
                {
                    var toAdd = new RepositoryVM()
                    {
                        Guid            = item.Guid,
                        Name            = item.Name,
                        Url             = item.RemoteUrl,
                        DefaultBranch   = item.DefaultBranch,
                        DirectoryOnDisk = false
                    };
                    if (System.IO.Directory.Exists(startingFolder))
                    {
                        var projectStartingFolder = startingFolder;
                        CreateStartingProjectFolder(ref projectStartingFolder);
                        if (System.IO.Directory.Exists(startingFolder))
                        {
                            toAdd.DirectoryOnDisk = System.IO.Directory.Exists(projectStartingFolder + @"\" + item.Name);
                        }
                    }
                    results.Add(toAdd);
                });
            }
            catch (System.Exception foo)
            {
                System.Diagnostics.Debug.WriteLine($"Get Repos: {foo.Message}");
            }
            return(Json(results.ToDataSourceResult(request)));
        }
コード例 #4
0
        public IActionResult RebuildBuildDefinitions()
        {
            var vsts = new Classes.VSTS.Vsts(HttpContext.Session.GetString(Session.TOKEN));

            ViewBag.RepoCount = vsts.GetRepos(HttpContext.Session.GetString(Session.SELECTED_PROJ)).Count;

            try
            {
                if (!_inBuildProcess)
                {
                    var options = new MemoryCacheEntryOptions().SetPriority(CacheItemPriority.NeverRemove);
                    _cache.Remove(CACHE.BUILDS);
                    ConstructBuildDefinitions();
//                    var background = Task.Run(() => SetBuildDefinitions(HttpContext.Session.GetString(Session.SELECTED_PROJ)));
                }
            }
            catch (System.Exception exx)
            {
                System.Diagnostics.Debug.WriteLine($"Rebuild Build Definitions:  {exx.Message}");
            }
            return(View("ProjectRepositories"));
        }
コード例 #5
0
        public JsonResult PullAllRepositories(int pos)
        {
            var repoName = string.Empty;

            try
            {
                // get starting folder from login
                var startingFolder = string.Empty;

                CreateStartingFolder(ref startingFolder);

                if (System.IO.Directory.Exists(startingFolder))
                {
                    CreateStartingProjectFolder(ref startingFolder);

                    if (System.IO.Directory.Exists(startingFolder))
                    {
                        var mainBat = startingFolder + @"\PullAllRepositories.bat";

                        if (System.IO.File.Exists(mainBat))
                        {
                            System.IO.File.Delete(mainBat);
                        }

                        var vsts  = new Classes.VSTS.Vsts(HttpContext.Session.GetString(Session.TOKEN));
                        var repos = vsts.GetRepos(HttpContext.Session.GetString(Session.SELECTED_PROJ));

                        var repo = repos.Repositories[pos];

                        repoName = repo.Name;

                        int    ndx     = repo.RemoteUrl.LastIndexOf(@"/");
                        string theFile = repo.RemoteUrl.Substring(ndx + 1);

                        if (System.IO.Directory.Exists($@"{startingFolder}\{theFile}"))
                        {
                            return(Json(new JsonMessage(true, "Already exists")));
                        }
                        else
                        {
                            var bat = new Classes.GitBatch(mainBat)
                            {
                                Redirect      = true,
                                RedirectError = $@"{startingFolder.Replace(@"\\", @"\")}\ErrorPullAll{pos}.txt",
                                RedirectFile  = $@"{startingFolder.Replace(@"\\", @"\")}\OutputPullAll{pos}.txt"
                            };

                            bat.AddLine($"echo start");

                            bat.AddLine($"echo Working on '{theFile}'");
                            bat.AddCD(startingFolder);
                            bat.AddLine($@"git clone {repo.RemoteUrl}");

                            bat.AddCD($@"{startingFolder}\{theFile}");
                            //bat.AddLine($"git checkout -b master origin/master");
                            //bat.AddCheckout("master", "origin/master");
                            //bat.AddCheckout("release", "origin/release");

                            bat.AddCD(startingFolder);

                            bat.Write();
                            bat.GitRun(startingFolder, HttpContext.Session.GetString(Session.USER), HttpContext.Session.GetString(Session.GIT));

                            return(Json(new JsonMessage(true, "Success")));
                        }
                    }
                    else
                    {
                        return(Json(new JsonMessage(false, $"Unable to find starting folder {startingFolder}")));
                    }
                }
                else
                {
                    return(Json(new JsonMessage(false, $"Unable to find starting folder {startingFolder}")));
                }
            }
            catch (System.Exception ex)
            {
                return(Json(new JsonMessage(false, $"{repoName} - Failed to clone - [{ex.Message}]")));
            }
        }