Ejemplo n.º 1
0
        private static async Task Bootstrapper(
            string githubPersonalAccessToken,
            string githubOrg,
            string githubRepo,
            string clubhouseKey,
            string clubhouseProjectName,
            IDictionary <string, string> userMapping,
            string clubhouseWebhookUrl)
        {
            var clubhouse = new ClubHouseStoryImporter(clubhouseKey, userMapping);
            var project   = await clubhouse.PopulateProject(clubhouseProjectName);

            Console.WriteLine($"Found Clubhouse Project: {project.Name}");
            var users = await clubhouse.PopulateUsers();

            Console.WriteLine($"Found Clubhouse Users: {users.Count}");
            Console.WriteLine("Fetching Issues...");
            var githubProvider = new GitHubIssueListProvider(githubPersonalAccessToken, githubOrg, githubRepo);

            if (!string.IsNullOrEmpty(clubhouseWebhookUrl))
            {
                await githubProvider.ConfigureWebHook(clubhouseWebhookUrl);
            }

            var issues = await githubProvider.GetIssues();

            Console.WriteLine($"Found {issues.Count} issues for repository {githubRepo}");
            Console.WriteLine("Converting to Clubhouse Stories...");
            var epicCounter = 0;

            for (int i = 0; i < issues.Count; i++)
            {
                DrawTextProgressBar(i + 1, issues.Count);
                var creation = await clubhouse.ConvertToStory(issues[i], githubProvider);

                if (creation.epicId > 0)
                {
                    epicCounter++;
                }
            }
            Console.WriteLine("");
            if (epicCounter > 0)
            {
                Console.WriteLine($"We've created or aligned {epicCounter} Epics to match GitHub milestones");
            }
            Console.WriteLine("All set, are you sure you'd like to proceed? [Y/N] ");
            Console.WriteLine("");

            var proceed = Console.ReadKey();

            if (proceed.Key == ConsoleKey.Y)
            {
                Console.WriteLine("Bulk Importing Stories...");
                await clubhouse.BatchLoadStories();
            }
            else
            {
                Console.WriteLine("Exiting...");
            }
        }
        public async Task <(Story story, int epicId)> ConvertToStory(Octokit.Issue issue, GitHubIssueListProvider ghProvider)
        {
            var story = new Story
            {
                CreatedAt   = issue.CreatedAt.DateTime,
                Name        = issue.Title,
                Description = issue.Body,
                ProjectId   = Project.Id,
            };

            story.RequestedById = GitHubUser2ClubHouseUser(issue.User);
            story.OwnerIds      = issue.Assignees.Select(GitHubUser2ClubHouseUser).ToList();

            var clubHouseEpicId = await GetOrCreateClubhouseEpic(issue);

            if (clubHouseEpicId > 0)
            {
                story.EpicId = clubHouseEpicId;
            }

            if (issue.Comments > 0)
            {
                foreach (var comment in await ghProvider.GetIssueComments(issue.Number))
                {
                    story.Comments.Add(new Comment
                    {
                        AuthorId  = GitHubUser2ClubHouseUser(comment.User),
                        CreatedAt = comment.CreatedAt.DateTime,
                        Text      = comment.Body
                    });
                }
            }
            _stories.Add(story);
            return(story, clubHouseEpicId);
        }