Esempio n. 1
0
        public async Task SetAnalysisState(long stepId, AnalysisResolution resolution, bool isAlreadyExists, int issueId, string title, string message, long suiteId, SystemUser user)
        {
            var suite = await _dbContext.TestSuites.FirstOrDefaultAsync(p => p.Id == suiteId);

            var gitClient = new GithubApiClient(user.GitHubAccount, user.GitHubToken);
            var step      = await GetStep(stepId);

            if (step == null)
            {
                throw new Exception("Can't find requested step!");
            }
            var newAnalysis = new StepAnalysisItem
            {
                AddedBy            = user,
                AnalysisResolution = resolution,
                Message            = message
            };

            switch (resolution)
            {
            case AnalysisResolution.CannotReproduce:
                if (isAlreadyExists)
                {
                    var existingIssue = gitClient.GetIssue(issueId);
                    if (existingIssue == null)
                    {
                        throw new Exception("Can't find requested issue id");
                    }
                    //gitClient.AddComment(issueId, message);
                    newAnalysis.GitHubId = issueId;
                }
                else
                {
                    var issue = gitClient.CreateNewIssue(title, message, suite.GitHubProjectId);
                    newAnalysis.GitHubId = issue.number;
                    await _testLabProvider.AddNewIssue(issue.number, suiteId, user);
                }
                break;

            case AnalysisResolution.KnownIssue:
                //gitClient.AddComment(issueId, message);
                newAnalysis.GitHubId = issueId;
                break;

            case AnalysisResolution.NewIssue:
                var newIssue = gitClient.CreateNewIssue(title, message, suite.GitHubProjectId);
                newAnalysis.GitHubId = newIssue.number;
                await _testLabProvider.AddNewIssue(newIssue.number, suiteId, user);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(resolution), resolution, null);
            }
            step.StepAnalysisItem.Add(newAnalysis);
            await _dbContext.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task <IActionResult> ImportIssues(ImportIssuesViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            try
            {
                var user = await _usersProvider.GetUser(User.GetUserId());

                if (model.TestSuiteId == 0)
                {
                    await _testLabProvider.AddNewTestSuite(model.ProjectId, user);

                    return(RedirectToAction("Index", "TestLab"));
                }
                var issueId = await _testLabProvider.AddNewIssue(model.IssueId, model.TestSuiteId, user);

                return(RedirectToAction("TestCase", "TestLab", new { @id = issueId }));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                ModelState.AddModelError(string.Empty, e.Message);
            }
            return(View(model));
        }