Пример #1
0
        static async Task InternalMainAsync(string[] args)
        {
            if (!CommandLine.Parser.TryParse(args, out s_cmdLine))
            {
                return;
            }

            // if we have specified a token, use that.
            if (s_cmdLine.Token == null)
            {
                Colorizer.WriteLine("[Red!Error] Please specify a GitHub access token!");
            }

            s_gitHub = GitHubHelpers.GetGitHubClientWithToken(s_cmdLine.Token);

            if (s_cmdLine.Action == CommandAction.Create)
            {
                await CreateObjectsInGitHubAsync();
            }
            else if (s_cmdLine.Action == CommandAction.CreateOrUpdate)
            {
                await CreateOrUpdateObjectsInGitHubAsync();
            }
            else if (s_cmdLine.Action == CommandAction.List)
            {
                await ListObjectsAsync();
            }
            else if (s_cmdLine.Action == CommandAction.Check)
            {
                await CheckObjectsAsync();
            }
        }
Пример #2
0
        public BaseFunction(ILogger log)
        {
            _log = log;

            _log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
            if (!Parser.TryParse(new string[0], out _cmdLine, s_parserOptions))
            {
                return;
            }
            log.LogInformation("Command Line arguments parsed!");

            // we have to get the token.
            _gitHub = GitHubHelpers.CreateGitHubClient(_cmdLine.Token);

            log.LogInformation("Created GitHub client");
        }
Пример #3
0
        static async Task InternalMainAsync(string[] args)
        {
            if (!CommandLine.Parser.TryParse(args, out s_cmdLine))
            {
                return;
            }

            // if we have specified a token, use that.
            if (s_cmdLine.Token == null)
            {
                Colorizer.WriteLine("[Red!Error] Please specify a GitHub access token!");
            }

            s_gitHub = GitHubHelpers.GetGitHubClientWithToken(s_cmdLine.Token);

            IEnumerable <GitHubObject> objects = GitHubObject.Parse(s_cmdLine.ObjectsFile);

            if (s_cmdLine.Action == CommandAction.Create)
            {
                await CreateObjectsInGitHubAsync();
            }
            else if (s_cmdLine.Action == CommandAction.CreateOrUpdate)
            {
                await CreateOrUpdateObjectsInGitHubAsync();
            }
            else if (s_cmdLine.Action == CommandAction.List)
            {
                List <RepositoryInfo> reposToList = RepositoryInfo.Parse(s_cmdLine.RepositoriesList).ToList();

                foreach (var repo in reposToList)
                {
                    Colorizer.WriteLine("Processing [Magenta!{0}\\{1}] repo.", repo.Owner, repo.Name);

                    foreach (var milestone in s_gitHub.ListMilestonesAsync(repo).Result)
                    {
                        Colorizer.Write("Title: [Yellow!{0}]", milestone.Title);
                        if (!string.IsNullOrEmpty(milestone.Description))
                        {
                            Colorizer.Write(", Description: [Yellow!{0}]", milestone.Description);
                        }
                        if (milestone.DueOn.HasValue)
                        {
                            Colorizer.Write(", DueOn: [Yellow!{0}]", milestone.DueOn.Value.Date.ToShortDateString());
                        }

                        Colorizer.WriteLine($", Open issues: [Cyan!{milestone.OpenIssues}],  Closed issues: [Green!{milestone.ClosedIssues}]  ");
                    }
                }
            }
            else if (s_cmdLine.Action == CommandAction.Check)
            {
                // This checks that the objects in the list, they exist on those repos
                List <GitHubObject>          objectsToCheck       = GitHubObject.Parse(s_cmdLine.ObjectsFile);
                IEnumerable <RepositoryInfo> repoToCreateObjectIn = RepositoryInfo.Parse(s_cmdLine.RepositoriesList);

                foreach (RepositoryInfo repo in repoToCreateObjectIn)
                {
                    Colorizer.WriteLine("Processing [Magenta!{0}\\{1}] repo.", repo.Owner, repo.Name);

                    // we can check labels and milestones.
                    HashSet <Creator.Models.Objects.Label>     labelsInRepo     = new HashSet <Creator.Models.Objects.Label>(await s_gitHub.ListLabelsAsync(repo));
                    HashSet <Creator.Models.Objects.Milestone> milestonesInRepo = new HashSet <Creator.Models.Objects.Milestone>(await s_gitHub.ListMilestonesAsync(repo));

                    List <GitHubObject> foundObjects = new List <GitHubObject>();

                    foreach (GitHubObject item in objectsToCheck)
                    {
                        switch (item)
                        {
                        case Creator.Models.Objects.Milestone milestone:
                            if (milestonesInRepo.Contains(milestone))
                            {
                                foundObjects.Add(item);
                            }
                            break;

                        case Creator.Models.Objects.Label label:
                            if (labelsInRepo.Contains(label))
                            {
                                foundObjects.Add(item);
                            }
                            break;

                        default:
                            throw new InvalidOperationException($"Unknown type {item.GetType()}.");
                        }
                    }

                    // remove all the found objets from the initial list.
                    foreach (GitHubObject item in foundObjects)
                    {
                        objectsToCheck.Remove(item);
                    }

                    if (objectsToCheck.Count == 0)
                    {
                        Colorizer.WriteLine("[Green!Done]: All requested objects are present");
                    }
                    else
                    {
                        Colorizer.WriteLine("[Red!Done]: The following were not found:");
                        foreach (var item in objectsToCheck)
                        {
                            Console.WriteLine(item.ToString());
                        }
                    }
                }
            }
        }