コード例 #1
0
ファイル: Program.cs プロジェクト: JTOne123/GitHubMassUpdater
        private static async Task <IEnumerable <string> > SearchOnThePage(IEnumerable <string> pageItems, string branch)
        {
            var repoCollection = new RepositoryCollection();

            foreach (var githubRepo in pageItems)
            {
                if (Uri.IsWellFormedUriString(githubRepo, UriKind.Absolute))
                {
                    var uri = new Uri(githubRepo);

                    if (uri.Segments.Count() < 3)
                    {
                        continue;
                    }

                    var user = uri.Segments[1].Replace("/", "");
                    var repo = uri.Segments[2].Replace("/", "").Replace(".git", "");

                    Console.WriteLine($"user {user}, repo {repo}");

                    if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(repo))
                    {
                        Console.WriteLine($"Bad repo - {user}/{repo}");
                        continue;
                    }

                    repoCollection.Add(user, repo);
                }
            }

            var data = await SearchInGitHubAsync(repoCollection, branch);

            return(data);
        }
コード例 #2
0
        public void LoadFrom(Section section)
        {
            Verify.Argument.IsNotNull(section, "section");

            var localRepositories = section.TryGetSection("LocalRepositories");

            if (localRepositories != null)
            {
                LoadGroupContent(_local, localRepositories);
            }
            var recentRepositories = section.TryGetSection("RecentRepositories");

            if (recentRepositories != null)
            {
                _recent.Clear();
                foreach (var repositorySection in recentRepositories.Sections)
                {
                    var repository = TryLoadRepositoryFrom(repositorySection);
                    if (repository != null)
                    {
                        _recent.Add(repository);
                    }
                }
            }
        }
コード例 #3
0
        public void can_add_repos_and_check_status()
        {
            var repos        = new RepositoryCollection();
            var branchedRepo = new GitRepository(dir("OnLocalBranch"));

            branchedRepo.RefreshLocalStatus();
            repos.Add(branchedRepo);
            Assert.AreEqual(RepoStatus.Clean, repos.WorstStatus());
        }
コード例 #4
0
        /// <summary>
        /// Get a repository collection from a text string.
        /// </summary>
        /// <param name="text">The text to parse.</param>
        /// <returns>The repository collection (or null).</returns>
        static protected RepositoryCollection GetRepositories(string text)
        {
            var repositories = new RepositoryCollection();

            foreach (string part in GetNonEmptyItems(text))
            {
                repositories.Add(part);
            }

            return(repositories.Count > 0 ? repositories : null);
        }
コード例 #5
0
        public async Task <IEnumerable <string> > Query(Dependent dep)
        {
            var repoColl = new RepositoryCollection();

            repoColl.Add(dep.User, dep.Repository);
            SearchCodeResult?projs = null;

            for (int i = 0; i < 10; i++)
            {
                try
                {
                    System.Console.WriteLine($"{dep} searching for project files");
                    projs = await _githubClientProvider.Client.Search.SearchCode(new SearchCodeRequest()
                    {
                        Extensions = new string[] { "csproj" },
                        Repos      = repoColl
                    });
                    await PrintAndWaitForReset();

                    if (projs.IncompleteResults)
                    {
                        System.Console.WriteLine($"{dep} failed to retrieve contained projects.  Trying again");
                    }
                    else if (projs.Items.Count == 0)
                    {
                        System.Console.WriteLine($"{dep} contained projects returned zero.  Trying again");
                    }
                    else
                    {
                        break;
                    }
                    await Task.Delay(5000);
                }
                catch (HttpRequestException)
                {
                    System.Console.WriteLine($"{dep} failed to retrieve patcher listings.  Trying again");
                }
            }

            if (projs?.IncompleteResults ?? true)
            {
                throw new ArgumentException($"{dep} failed to retrieve patcher listings");
            }

            var ret = projs.Items
                      .OrderBy(i => i.Name)
                      .Select(i => i.Path)
                      .ToArray();

            System.Console.WriteLine($"{dep} retrieved project files:{Environment.NewLine}   {string.Join($"{Environment.NewLine}   ", ret)}");
            return(ret);
        }
コード例 #6
0
        private static RepositoryCollection createRepositoryCollection(IEnumerable <string> repos)
        {
            if (repos == null || !repos.Any())
            {
                return(null);
            }

            var coll = new RepositoryCollection();

            foreach (var repo in repos)
            {
                coll.Add(repo);
            }

            return(coll);
        }
コード例 #7
0
        /// <summary>
        /// Imports the source (REPO tags) from the GEDCOM XML file.
        /// </summary>
        private void ImportRepositories()
        {
            // Get list of people.
            XmlNodeList list = doc.SelectNodes("/root/REPO");

            foreach (XmlNode node in list)
            {
                Repository repository = new Repository();

                // Import details about the person.
                repository.Id                = GetId(node);
                repository.RepositoryName    = GetValue(node, "NAME");
                repository.RepositoryAddress = GetValue(node, "ADDR");
                repositories.Add(repository);
            }
        }
コード例 #8
0
ファイル: StatusReport.cs プロジェクト: anurse/AspNetReports
        public static async Task <StatusReportModel> GenerateReportModelAsync(GitHubClient github, DataStore data, Data.Team team, string milestone, DateTime startDate, DateTime endDate, ILoggerFactory loggerFactory)
        {
            var logger = loggerFactory.CreateLogger <StatusReport>();
            var model  = new StatusReportModel();

            model.Name       = team.Name;
            model.ReportDate = endDate.ToString("yyyy-MM-dd");

            var cache = new GitHubCache(github, data, loggerFactory.CreateLogger <GitHubCache>());

            // Establish the time window. Exclude the endDate.
            var range = new DateRange(startDate, endDate.AddDays(-1));

            logger.LogInformation("Using date range {Range}", range);

            var releaseMilestone = data.GetMilestone(milestone);

            model.Milestone = new List <MilestoneDates>()
            {
                ComputeMilestoneDates(data, endDate, releaseMilestone, logger)
            };

            var repos = new RepositoryCollection();

            foreach (var repo in data.Organization.Repositories)
            {
                repos.Add(repo.Owner, repo.Name);
            }

            await GeneratePullRequestInfoAsync(github, data, team, model, cache, range, repos, logger);
            await GenerateIssueInfoAsync(github, team, repos, milestone, model, logger);

            // Try to render burndown data
            var burndown = await data.LoadBurndownAsync(milestone);

            // Check for burndown data for the end date
            if (!burndown.Weeks.Any(w => w.EndDate.Year == endDate.Year && w.EndDate.Month == endDate.Month && w.EndDate.Day == endDate.Day))
            {
                logger.LogWarning("No burndown data is associated with today's date! The burndown data in this report may be out-of-date.");
            }

            model.Burndown = GenerateBurndownModel(team, burndown);

            return(model);
        }
コード例 #9
0
        public async Task <SearchCodeResult> Search(SearchCodeRequest search)
        {
            CheckInitialised();
            var repos = new RepositoryCollection();

            foreach (var repo in search.Repos)
            {
                repos.Add(repo.owner, repo.name);
            }

            var result = await _client.Search.SearchCode(
                new Octokit.SearchCodeRequest(search.Term)
            {
                Repos   = repos,
                In      = new[] { CodeInQualifier.Path },
                PerPage = search.PerPage
            });

            return(new SearchCodeResult(result.TotalCount));
        }
コード例 #10
0
        private void GetRepositories()
        {
            if (RepositoryCollection != null && RepositoryCollection.Any())
            {
                RepositoryCollection.Clear();
            }
            if (_repositoryTypeDictionary != null && _repositoryTypeDictionary.Any())
            {
                _repositoryTypeDictionary.Clear();
            }

            using (var session = DbService.Instance.SessionFactory.OpenSession())
            {
                var repositories =
                    session.QueryOver <Repository>().List <Repository>();
                repositories.ForEach(repository =>
                {
                    RepositoryCollection.Add(repository.Name);
                    _repositoryTypeDictionary.Add(repository.Name, repository.Type);
                });
            }
        }
コード例 #11
0
        public async Task <SearchCodeResult> Search(SearchCodeRequest search)
        {
            CheckInitialised();

            return(await ExceptionHandler(async() =>
            {
                var repos = new RepositoryCollection();
                foreach (var repo in search.Repos)
                {
                    repos.Add(repo.Owner, repo.Name);
                }
                var result = await _client.Search.SearchCode(
                    new Octokit.SearchCodeRequest()
                {
                    Repos = repos,
                    Extensions = search.Extensions,
                    In = new[] { CodeInQualifier.Path },
                    PerPage = search.PerPage
                });
                return new SearchCodeResult(result.TotalCount);
            }));
        }
        public GitHubScanner(
            ProjectFileParser projectFileParser,
            string organization,
            string accessToken,
            string repos)
        {
            _projectFileParser = projectFileParser;

            var proxy      = new WebProxy();
            var connection = new Connection(
                new ProductHeaderValue(AppName),
                new HttpClientAdapter(() => HttpMessageHandlerFactory.CreateDefault(proxy)));

            var token = accessToken ?? throw new InvalidOperationException(
                                  $"Access token can't be empty. For unauthenticated requests rate limit = 60 calls per hour!");

            _client = new GitHubClient(new ProductHeaderValue(AppName))
            {
                Credentials = new Credentials(token),
            };

            if (string.IsNullOrWhiteSpace(organization))
            {
                throw new ArgumentNullException(nameof(organization));
            }
            _organization = organization;

            if (!string.IsNullOrWhiteSpace(repos))
            {
                _repos = new RepositoryCollection();
                var reposArr = repos.Split(',', StringSplitOptions.RemoveEmptyEntries);
                foreach (var repo in reposArr)
                {
                    var trimmedRepo = repo.Trim();
                    _repos.Add(organization, trimmedRepo);
                }
            }
        }
コード例 #13
0
ファイル: Repositories.xaml.cs プロジェクト: karmicka/Source
        private void Add()
        {
            int y = 0;

            string oldRepositoryIDs = string.Empty;

            foreach (Repository s in repository)
            {
                oldRepositoryIDs += s.Id + "E";
            }

            do
            {
                y++;
            }while (oldRepositoryIDs.Contains("R" + y.ToString() + "E"));

            string repositoryID = "R" + y.ToString();

            Repository newRepository = new Repository(repositoryID, "", "");

            repository.Add(newRepository);
            repository.OnContentChanged();
        }
コード例 #14
0
        public static async Task <Issue> FindExistingPullRequestToUpdate(
            GitHubClient client, User currentUser, Repository upstreamRepo,
            Repository forkRepo, string forkBranch)
        {
            // Search for candidate PRs (same author, still open, etc.)
            var fromBaseRef   = $"{forkRepo.Owner.Login}:{forkBranch}";
            var searchInRepos = new RepositoryCollection();

            searchInRepos.Add(upstreamRepo.Owner.Login, upstreamRepo.Name);
            var searchRequest = new SearchIssuesRequest
            {
                Repos  = searchInRepos,
                Type   = IssueTypeQualifier.PullRequest,
                Author = currentUser.Login,
                State  = ItemState.Open
            };
            var searchResults = await client.Search.SearchIssues(searchRequest);

            // Of the candidates, find the highest-numbered one that is requesting a
            // pull from the same fork and branch. GitHub only allows there to be one
            // of these at any given time, but we're more likely to find it faster
            // by searching from newest to oldest.
            var candidates = searchResults.Items.OrderByDescending(item => item.Number);

            foreach (var prInfo in candidates)
            {
                var pr = await client.PullRequest.Get(upstreamRepo.Id, prInfo.Number);

                if (pr.Head?.Repository?.Id == forkRepo.Id && pr.Head?.Ref == forkBranch)
                {
                    return(prInfo);
                }
            }

            return(null);
        }
コード例 #15
0
        public async Task <int> OnExecuteAsync()
        {
            var loggerFactory = CreateLoggerFactory();
            var logger        = loggerFactory.CreateLogger <StatusCommand>();

            if (string.IsNullOrEmpty(Milestone))
            {
                throw new CommandLineException("Missing required option '--milestone'.");
            }

            logger.LogInformation("Preparing burndown for {Milestone}", Milestone);

            var data = await LoadDataStoreAsync();

            var github = GetGitHubClient();

            logger.LogDebug("Loading existing burndown...");
            var burndown = await data.LoadBurndownAsync(Milestone);

            logger.LogDebug("Loaded existing burndown.");

            var repos = new RepositoryCollection();

            foreach (var repo in data.Organization.Repositories)
            {
                repos.Add(repo.Owner, repo.Name);
            }

            // Query for issues
            var query = new SearchIssuesRequest()
            {
                Is        = new[] { IssueIsQualifier.Issue },
                Milestone = Milestone,
                Repos     = repos,
            };
            var results = await github.SearchIssuesLogged(query, logger);

            // Create area breakdowns
            var areas = new Dictionary <string, AreaBurndown>();

            foreach (var issue in results)
            {
                foreach (var label in issue.Labels)
                {
                    if (label.Name.StartsWith("area-"))
                    {
                        if (!areas.TryGetValue(label.Name, out var areaBurndown))
                        {
                            areaBurndown      = new AreaBurndown(label.Name);
                            areas[label.Name] = areaBurndown;
                        }

                        if (issue.State == ItemState.Open)
                        {
                            areaBurndown.Open += 1;
                        }
                        else if (issue.Labels.Any(l => l.Name.Equals("accepted")))
                        {
                            Debug.Assert(issue.State == ItemState.Closed);
                            areaBurndown.Accepted += 1;
                        }
                        else
                        {
                            Debug.Assert(issue.State == ItemState.Closed);
                            areaBurndown.Closed += 1;
                        }
                    }
                }
            }

            // Add the item to the existing burndown and save
            burndown.Weeks.Add(new WeekBurndown(DateTime.Now, areas.Values.OrderBy(a => a.Label).ToList()));
            logger.LogDebug("Saving burndown...");
            await data.SaveBurndownAsync(Milestone, burndown);

            logger.LogDebug("Saved burndown.");

            return(0);
        }
コード例 #16
0
        static async Task Main(string[] args)
        {
            var    currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location).Replace("MainApp\\bin\\Debug", "");
            var    credsFilePath    = currentDirectory + "Creds.txt";
            string username         = string.Empty;
            string password         = string.Empty;

            Console.WriteLine("Welcome to the Github Repo PR Extractor\n");

            if (!File.Exists(credsFilePath))
            {
                Console.Write("Would you like us to save your username or password? \nYou won't have to enter it next time (y/n):- ");
                var saveCredentials = Console.ReadLine();

                Console.Write("Please enter your BD email address:- ");
                username = Console.ReadLine();

                Console.Write("Please enter your password:- ");
                password = Console.ReadLine();

                if (saveCredentials.ToLower() == "y")
                {
                    CreateCredsFile(username, password, credsFilePath);
                    Console.WriteLine("\n\nALERT!! A Creds.txt file is created with your credentials. Keep them safe");
                }
            }
            else
            {
                Console.WriteLine("Logging you in!!");
                var creds = File.ReadAllLines(credsFilePath);
                username = creds[0];
                password = creds[1];

                Console.WriteLine($"Welcome {username}\n");
            }

            var prodHeader    = new ProductHeaderValue(GitHubIdentity);
            var credentials   = new Credentials(username, password);
            var enterpriseUrl = "https://github-rd.carefusion.com/vanguard";
            var client        = new GitHubClient(prodHeader, new Uri(enterpriseUrl))
            {
                Credentials = credentials
            };

            var repoNameFile = "RepositoryNames.txt";
            var repoNamePath = currentDirectory + repoNameFile;
            var allRepoNames = File.ReadAllLines(repoNamePath);

            try
            {
                Console.WriteLine("Please mention the start date (dd/MM/yyyy)");
                StartDate = DateTime.Parse(Console.ReadLine());

                Console.WriteLine("Please mention the end date (dd/MM/yyyy)");
                EndDate = DateTime.Parse(Console.ReadLine());
            }
            catch
            {
                Console.WriteLine("You were wrong. Try again!!");
                Console.ReadKey();
                Environment.Exit(0);
            }

            var excelWorkbookName  = "PRsList " + StartDate.ToShortDateString() + " to " + EndDate.ToShortDateString();
            var excelWorkSheetName = "PRDetails";
            var excelWorkbookPath  = currentDirectory + excelWorkbookName;

            var excelExport = new ExcelExport(excelWorkbookPath, excelWorkSheetName);

            var rc = new RepositoryCollection();

            foreach (var repoName in allRepoNames)
            {
                rc.Add($"vanguard/{repoName}");
            }

            var searchIssuesRequest = new SearchIssuesRequest
            {
                Merged    = new DateRange(StartDate, EndDate),
                Type      = IssueTypeQualifier.PullRequest,
                Repos     = rc,
                SortField = IssueSearchSort.Merged,
                Page      = 1,
                PerPage   = 100
            };

            var filteredPrs = await client.Search.SearchIssues(searchIssuesRequest);

            var totalNumberOfPrs = filteredPrs.TotalCount;

            Console.WriteLine($"Found {totalNumberOfPrs} of PRs within our range\n");

            var totalFilteredPRs = (List <Issue>)filteredPrs.Items;

            // Max page size is 100
            while ((totalNumberOfPrs / (searchIssuesRequest.Page * 100)) >= 1)
            {
                // 403 = 1 * 100, 2 * 100, 3 * 100, 4 * 100, 5 * 3
                searchIssuesRequest.PerPage = ((totalNumberOfPrs - searchIssuesRequest.Page * 100) < 100) ? (totalNumberOfPrs - searchIssuesRequest.Page * 100) : 100;
                searchIssuesRequest.Page   += 1;
                filteredPrs = await client.Search.SearchIssues(searchIssuesRequest);

                totalFilteredPRs.AddRange(filteredPrs.Items);
            }

            var prsToBeAdded = new List <Issue>();

            Console.WriteLine("Checking if any PRs have any review comments...");

            foreach (var filteredPr in totalFilteredPRs)
            {
                var reviewCommentsCount = (await client.PullRequest.ReviewComment.GetAll("vanguard", filteredPr.GetName(), filteredPr.Number)).Count;
                if (reviewCommentsCount > 0)
                {
                    prsToBeAdded.Add(filteredPr);
                }
            }
            if (prsToBeAdded.Any())
            {
                Console.WriteLine($"Found {prsToBeAdded.Count} PRs with CR Comments");
                excelExport.GenerateExcel <Issue>(prsToBeAdded);
                excelExport.SaveAndCloseExcel();
            }
            else
            {
                Console.WriteLine("No PR found in our range with CR comments.\nHave a Nice Day!!");
                Console.ReadKey();
            }
        }
コード例 #17
0
ファイル: HomeController.cs プロジェクト: hahmed/Sprint
        public async Task<ActionResult> Stats()
        {
            var vm = new StatsViewModel();

            var issueSearch = new SearchIssuesRequest
            {
                Comments = Range.GreaterThan(25),
                Created = DateRange.GreaterThan(new DateTime(DateTime.Now.Year, 01, 01)),
                SortField = IssueSearchSort.Comments,
                Language = Language.Ruby,
                Order = SortDirection.Descending
            };
            var mostCommented = await _githubClient.Search.SearchIssues(issueSearch);
            vm.MostCommentedIssue = mostCommented.Items.OrderByDescending(x=> x.Comments).Take(10).ToList();

            var repoSearch = new SearchRepositoriesRequest
            {
                Created = DateRange.GreaterThan(new DateTime(DateTime.Now.Year, 01, 01)),
                Language = Language.CSharp,
                SortField = RepoSearchSort.Stars,
                Order = SortDirection.Descending
            };
            var mostStarred = await _githubClient.Search.SearchRepo(repoSearch);
            vm.MostStarred = mostStarred.Items.Take(10).ToList();

            var repo = new RepositoryCollection();
            repo.Add("rails", "rails");
            issueSearch = new SearchIssuesRequest
            {
                 Repos = repo,
                 Created = DateRange.GreaterThan(new DateTime(DateTime.Now.Year, 01, 01)),
            };
            var railsIssues = await _githubClient.Search.SearchIssues(issueSearch);
            var dic = new Dictionary<DayOfWeek, List<Issue>>();
            foreach (var issue in railsIssues.Items)
            {
                if(dic.ContainsKey(issue.CreatedAt.DayOfWeek))
                {
                    dic[issue.CreatedAt.DayOfWeek].Add(issue);
                }
                else
                {
                    dic.Add(issue.CreatedAt.DayOfWeek, new List<Issue> { issue });
                }
            }

            vm.RailsIssues = dic;

            return View(vm);
        }