Beispiel #1
0
        public async Task <GitHubIssue> UpdateGitHubIssueAsync(GitHubIssue issue)
        {
            if (issue == null)
            {
                throw new ArgumentNullException("issue");
            }

            var issueInternal = _mapper.Map <GitHubIssue, GitHubIssueInternal>(issue);

            _context.Entry(issueInternal).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await IssueExists(issue.Id))
                {
                    throw new EntityNotFoundException($"Issue with id {issue.Id} not found", "Issue", issue.Id);
                }
                else
                {
                    throw;
                }
            }

            return(_mapper.Map <GitHubIssueInternal, GitHubIssue>(issueInternal));
        }
Beispiel #2
0
        public string Prediction(GitHubIssue issue)
        {
            var prediction = predEngine.Predict(issue);

            Console.WriteLine($"=============== Single Prediction just-trained-model - Result: {prediction.Area} ===============");
            return(prediction.Area);
        }
Beispiel #3
0
        // Build and Train the Model
        public static IEstimator <ITransformer> BuildAndTrainModel(IDataView trainingDataView,
                                                                   IEstimator <ITransformer> pipeline)
        {
            var trainingPipeline = pipeline
                                   .Append(_mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy("Label", "Features"))
                                   .Append(_mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

            _trainedModel = trainingPipeline.Fit(trainingDataView);

            _predEngine = _mlContext.Model.CreatePredictionEngine <GitHubIssue, IssuePrediction>(_trainedModel);
            GitHubIssue issue = new GitHubIssue()
            {
                Title       = "WebSockets communication is slow in my machine",
                Description =
                    "The WebSockets communication used under the covers by SignalR looks like is going slow in my development machine.."
            };

            // Cross Validation

            /*var cvResults =
             *  _mlContext.MulticlassClassification.CrossValidate(data: _trainingDataView, trainingPipeline, 5);
             * foreach (var r in cvResults)
             * {
             *  Console.WriteLine($"  Fold: {r.Fold}, AUC: {r.Metrics.TopKAccuracy}");
             *  Console.WriteLine($"  Confusion Matrix: {r.Metrics.ConfusionMatrix}");
             * }*/

            Console.WriteLine();

            var prediction = _predEngine.Predict(issue);

            Console.WriteLine($"=============== Single Prediction just-trained-model - Result: {prediction.Area} ===============");
            return(trainingPipeline);
        }
Beispiel #4
0
        public void TestPrediction1()
        {
            GitHubIssue issue = new GitHubIssue()
            {
                Title       = "WebSockets communication is slow in my machine",
                Description = "The WebSockets communication used under the covers by SignalR looks like is going slow in my development machine.."
            };

            var prediction = multiClassClassification.Prediction(issue);

            Assert.AreEqual(prediction, "area-System.Net");
        }
Beispiel #5
0
        public void TestPrediction2()
        {
            GitHubIssue issue = new GitHubIssue()
            {
                Title       = "Directory.CreateDirectory(directory) call when the directory already exists ends up in a StackOverflowException",
                Description = "Directory.CreateDirectory(directory) call when the directory already exists ends up in a StackOverflowException. It used to fail silently in System.IO."
            };

            var prediction = multiClassClassification.Prediction(issue);

            Assert.AreEqual(prediction, "area-System.IO");
        }
Beispiel #6
0
        public void TestPrediction3()
        {
            GitHubIssue issue = new GitHubIssue()
            {
                Title       = "Proposal: Add Task.WhenAny overloads with CancellationToke",
                Description = "It's a relatively common pattern to await on tasks which don't support cancellation (yet). One workaround is to pass new Task(() => {}, cancellationToken) as one of the tasks to Task.WhenAny, but I've also seen a variant where the token registration sets a TCS result and the TCS.Task is passed to WhenAny and even more complicated variants, but all of them are pretty inefficient and make the code unwieldy.\r\nThere are somewhat similar WaitAny overloads for sync-over-async code already."
            };

            var prediction = multiClassClassification.Prediction(issue);

            Assert.AreEqual(prediction, "area-System.Threading");
        }
Beispiel #7
0
        public void TestPrediction4()
        {
            GitHubIssue issue = new GitHubIssue()
            {
                Title       = "Allow X509Chain callers to prevent retrieval of missing certificates",
                Description = "Callers sometimes want to build a \"fully offline\" X509Chain, but the only exposed online/offline mode pertains to revocation processing. Alternatively, they may want to be in a \"limited online\" state, where the only network operations are for retrieving up-to-date CRL/OCSP responses for the end-entity certificate."
            };

            var prediction = multiClassClassification.Prediction(issue);

            Assert.AreEqual(prediction, "area-System.Security");
        }
Beispiel #8
0
        public void TestModel()
        {
            GitHubIssue singleIssue = new GitHubIssue()
            {
                Title       = "Entity Framework crashes",
                Description = "When connecting to the database, EF is crashing"
            };

            predEngine = mlContext.Model.CreatePredictionEngine <GitHubIssue, IssuePrediction>(trainedModel);
            var prediction = predEngine.Predict(singleIssue);

            Console.WriteLine($"=============== Single Prediction - Result: {prediction.Area} ===============");
        }
Beispiel #9
0
        public void GitHubIssueHandler()
        {
            var request = new GitHubIssue
            {
                IssueNumber = 1,
                Repository  = "AnyStatus",
                Owner       = "AlonAm"
            };

            new GitHubIssueMonitor().Handle(request);

            Assert.AreSame(State.Closed, request.State);
        }
 private SlackMessageAttachment BuildAttachment(GitHubIssue issue)
 {
     return(new SlackMessageAttachment()
     {
         Fallback = String.Format("Pull Request: '{0}' created on {1}", issue.Title, issue.CreatedAt),
         Footer = issue.User.Login,
         Title = issue.Title,
         Timestamp = issue.CreatedAt,
         FooterIcon = issue.User.AvatarUrl,
         TitleLink = issue.HtmlUrl,
         //Text = issue.Body.Length < 30 ? issue.Body : issue.Body.Substring(0, 30),
         Color = new SimpleColor("#27ae60")
     });
 }
Beispiel #11
0
        public async Task <List <GitHubIssue> > GetIssues()
        {
            List <GitHubIssue> gitHubIssues     = new List <GitHubIssue>();
            Connection         gitHubConnection = new Connection(new ProductHeaderValue("igniteui-angular"));
            GitHubClient       client           = new GitHubClient(gitHubConnection);

            IReadOnlyList <Issue> issues = await client.Issue.GetAllForRepository("igniteui", "igniteui-angular");

            foreach (var issue in issues)
            {
                GitHubIssue iss = new GitHubIssue(issue);
                gitHubIssues.Add(iss);
            }
            return(gitHubIssues);
        }
 private static SpecStatus GetSpecStatusFromProposal(GitHubIssue issue)
 {
     if (issue.Labels.Any(i => i.Name == "Proposal-Ready for Review"))
     {
         return(SpecStatus.ReadyForReview);
     }
     else if (issue.Labels.Any(i => i.Name == "Proposal-Has Concerns"))
     {
         return(SpecStatus.HasConcerns);
     }
     else
     {
         return(SpecStatus.Draft);
     }
 }
Beispiel #13
0
        //
        // GitHub mappers
        //

        public static PlasticTask MapToPlasticTask(this GitHubIssue issue)
        {
            if (issue == null)
            {
                return(null);
            }

            return(new PlasticTask()
            {
                Id = issue.Number.ToString(),
                Owner = issue.Assignee?.Login.ToString(),
                Title = issue.Title,
                Description = issue.Body,
                Status = "working"                 // TODO: Review possible values
            });
        }
        public async Task GitHubIssueHandler()
        {
            var issue = new GitHubIssue
            {
                IssueNumber = 1,
                Repository  = "AnyStatus",
                Owner       = "AnyStatus"
            };

            var request = HealthCheckRequest.Create(issue);

            var handler = new GitHubIssueStateCheck();

            await handler.Handle(request, CancellationToken.None);

            Assert.AreNotSame(State.None, request.DataContext.State);
        }
Beispiel #15
0
        public void OpenGitHubIssueInBrowser()
        {
            var gitHubIssue = new GitHubIssue
            {
                IssueNumber = 1,
                Name        = "name",
                Owner       = "owner",
                Repository  = "repository"
            };

            var processStarter = Substitute.For <IProcessStarter>();

            var handler = new OpenGitHubIssueInBrowser(processStarter);

            handler.Handle(gitHubIssue);

            processStarter.Received().Start(Arg.Any <string>());
        }
            static void EnsureNoCycles(GitHubIssue issue, Dictionary <string, List <GitHubIssue> > issueChildren, HashSet <GitHubIssue> ancestors)
            {
                var myChildren = issueChildren[issue.Id.ToString()];

                for (var i = myChildren.Count - 1; i >= 0; i--)
                {
                    var myChild = myChildren[i];
                    if (!ancestors.Add(myChild))
                    {
                        myChildren.RemoveAt(i);
                    }
                    else
                    {
                        EnsureNoCycles(myChild, issueChildren, ancestors);
                        ancestors.Remove(myChild);
                    }
                }
            }
Beispiel #17
0
    private static void PredictIssue(MLContext mlContext)
    {
        ITransformer loadedModel;

        using (var stream = new FileStream(_modelPath, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            loadedModel = mlContext.Model.Load(stream);
        }

        GitHubIssue singleIssue = new GitHubIssue()
        {
            Title = "Entity Framework crashes", Description = "When connecting to the database, EF is crashing"
        };

        var predEngine = loadedModel.CreatePredictionEngine <GitHubIssue, IssuePrediction>(mlContext);

        var prediction = predEngine.Predict(singleIssue);

        Console.WriteLine($"=============== Single Prediction - Result: {prediction.Area} ===============");
    }
        public async Task OpenGitHubIssueInBrowser()
        {
            var gitHubIssue = new GitHubIssue
            {
                IssueNumber = 1,
                Name        = "name",
                Owner       = "owner",
                Repository  = "repository"
            };

            var processStarter = Substitute.For <IProcessStarter>();

            var handler = new OpenGitHubIssueWebPage(processStarter);

            var request = OpenWebPageRequest.Create(gitHubIssue);

            await handler.Handle(request, CancellationToken.None);

            processStarter.Received().Start(Arg.Any <string>());
        }
Beispiel #19
0
        private async void btnPredic_Click(object sender, EventArgs e)
        {
            lblPredict.Text = "<Issue預測Label>";

            var issue = new GitHubIssue()
            {
                Title       = txtTitle.Text,
                Description = rtxtboxDescription.Text
            };

            if (Model == null || ModelPath != txtModelPath.Text)
            {
                ModelPath = txtModelPath.Text;

                Model = await PredictionModel.ReadAsync
                        <GitHubIssue, GithubIssueLabelPrediction>(ModelPath);
            }

            lblPredict.Text = Model.Predict(issue).Area;
        }
Beispiel #20
0
        public void BuildAndTrainModel(IEstimator <ITransformer> pipeline, bool forceRetrain)
        {
            var trainingPipeline = pipeline.Append(mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy("Label", "Features"))
                                   .Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

            if (LoadModel() && !forceRetrain)
            {
                return;
            }

            trainedModel = trainingPipeline.Fit(trainingDataView);
            predEngine   = mlContext.Model.CreatePredictionEngine <GitHubIssue, IssuePrediction>(trainedModel);

            GitHubIssue issue = new GitHubIssue()
            {
                Title       = "WebSockets communication is slow in my machine",
                Description = "The WebSockets communication used under the covers by SignalR looks like is going slow in my development machine.."
            };

            var prediction = predEngine.Predict(issue);

            Console.WriteLine($"=============== Single Prediction just-trained-model - Result: {prediction.Area} ===============");
        }
        public static void BuildAndTrainModel(string DataSetLocation, string ModelPath, MyTrainerStrategy selectedStrategy)
        {
            // Create MLContext to be shared across the model creation workflow objects
            // Set a random seed for repeatable/deterministic results across multiple trainings.
            var mlContext = new MLContext(seed: 1);

            // STEP 1: Common data loading configuration
            var trainingDataView = mlContext.Data.LoadFromTextFile <GitHubIssue>(DataSetLocation, hasHeader: true, separatorChar: '\t', allowSparse: false);

            // STEP 2: Common data process configuration with pipeline data transformations
            var dataProcessPipeline = mlContext.Transforms.Conversion.MapValueToKey(outputColumnName: "Label", inputColumnName: nameof(GitHubIssue.Area))
                                      .Append(mlContext.Transforms.Text.FeaturizeText(outputColumnName: "TitleFeaturized", inputColumnName: nameof(GitHubIssue.Title)))
                                      .Append(mlContext.Transforms.Text.FeaturizeText(outputColumnName: "DescriptionFeaturized", inputColumnName: nameof(GitHubIssue.Description)))
                                      .Append(mlContext.Transforms.Concatenate(outputColumnName: "Features", "TitleFeaturized", "DescriptionFeaturized"))
                                      .AppendCacheCheckpoint(mlContext);

            // Use in-memory cache for small/medium datasets to lower training time.
            // Do NOT use it (remove .AppendCacheCheckpoint()) when handling very large datasets.

            // (OPTIONAL) Peek data (such as 2 records) in training DataView after applying the ProcessPipeline's transformations into "Features"
            ConsoleHelper.PeekDataViewInConsole(mlContext, trainingDataView, dataProcessPipeline, 2);

            // STEP 3: Create the selected training algorithm/trainer
            IEstimator <ITransformer> trainer = null;

            switch (selectedStrategy)
            {
            case MyTrainerStrategy.SdcaMultiClassTrainer:
                trainer = mlContext.MulticlassClassification.Trainers.SdcaMaximumEntropy("Label", "Features");
                break;

            case MyTrainerStrategy.OVAAveragedPerceptronTrainer:
            {
                // Create a binary classification trainer.
                var averagedPerceptronBinaryTrainer = mlContext.BinaryClassification.Trainers.AveragedPerceptron("Label", "Features", numberOfIterations: 10);
                // Compose an OVA (One-Versus-All) trainer with the BinaryTrainer.
                // In this strategy, a binary classification algorithm is used to train one classifier for each class, "
                // which distinguishes that class from all other classes. Prediction is then performed by running these binary classifiers, "
                // and choosing the prediction with the highest confidence score.
                trainer = mlContext.MulticlassClassification.Trainers.OneVersusAll(averagedPerceptronBinaryTrainer);

                break;
            }

            default:
                break;
            }

            //Set the trainer/algorithm and map label to value (original readable state)
            var trainingPipeline = dataProcessPipeline.Append(trainer)
                                   .Append(mlContext.Transforms.Conversion.MapKeyToValue("PredictedLabel"));

            // STEP 4: Cross-Validate with single dataset (since we don't have two datasets, one for training and for evaluate)
            // in order to evaluate and get the model's accuracy metrics

            Console.WriteLine("=============== Cross-validating to get model's accuracy metrics ===============");

            //Measure cross-validation time
            var watchCrossValTime = System.Diagnostics.Stopwatch.StartNew();

            var crossValidationResults = mlContext.MulticlassClassification.CrossValidate(data: trainingDataView, estimator: trainingPipeline, numberOfFolds: 6, labelColumnName: "Label");

            //Stop measuring time
            watchCrossValTime.Stop();
            long elapsedMs = watchCrossValTime.ElapsedMilliseconds;

            Console.WriteLine($"Time Cross-Validating: {elapsedMs} miliSecs");

            ConsoleHelper.PrintMulticlassClassificationFoldsAverageMetrics(trainer.ToString(), crossValidationResults);

            // STEP 5: Train the model fitting to the DataSet
            Console.WriteLine("=============== Training the model ===============");

            //Measure training time
            var watch = System.Diagnostics.Stopwatch.StartNew();

            var trainedModel = trainingPipeline.Fit(trainingDataView);

            //Stop measuring time
            watch.Stop();
            long elapsedCrossValMs = watch.ElapsedMilliseconds;

            Console.WriteLine($"Time Training the model: {elapsedCrossValMs} miliSecs");

            // (OPTIONAL) Try/test a single prediction with the "just-trained model" (Before saving the model)
            GitHubIssue issue = new GitHubIssue()
            {
                ID = "Any-ID", Title = "WebSockets communication is slow in my machine", Description = "The WebSockets communication used under the covers by SignalR looks like is going slow in my development machine.."
            };
            // Create prediction engine related to the loaded trained model
            var predEngine = mlContext.Model.CreatePredictionEngine <GitHubIssue, GitHubIssuePrediction>(trainedModel);
            //Score
            var prediction = predEngine.Predict(issue);

            Console.WriteLine($"=============== Single Prediction just-trained-model - Result: {prediction.Area} ===============");
            //

            // STEP 6: Save/persist the trained model to a .ZIP file
            Console.WriteLine("=============== Saving the model to a file ===============");
            mlContext.Model.Save(trainedModel, trainingDataView.Schema, ModelPath);

            ConsoleHelper.ConsoleWriteHeader("Training process finalized");
        }
 internal bool IsTargetType(GitHubIssue issue)
 {
     return issue.Labels != null && issue.Labels.Select(label => label.Name).Any(name => name == issueKindName);
 }
Beispiel #23
0
 private static bool IsTargetMilestone(GitHubIssue issue, string milestone)
 {
     return(issue.Milestone != null && issue.Milestone.Title == milestone);
 }
Beispiel #24
0
 internal bool IsTargetType(GitHubIssue issue)
 {
     return(issue.Labels != null && issue.Labels.Select(label => label.Name).Any(name => name == issueKindName));
 }
 private bool IsIncludedInReleaseNotes(GitHubIssue issue)
 {
     return(issue.Labels.Any(label => IsReleaseNotesLabel(label)) &&
            !issue.Labels.Any(label => ignoreLabels.Contains(label.Name)));
 }
 private bool IsBugfix(GitHubIssue issue)
 {
     return issue.Labels != null && issue.Labels.Select(label => label.Name).Contains("bug");
 }
Beispiel #27
0
        public static void PredictIssue()
        {
            /*
             * Single Prediction
             * A single issue is created and stored as a new GitHubIssue, which is then used
             * for a prediction via the _predEngine.Predict function.
             */

            ITransformer loadedModel = _mlContext.Model.Load(_modelPath, out var modelInputSchema);

            GitHubIssue singleIssue = new GitHubIssue()
            {
                Title = "Entity Framework crashes", Description = "When connecting to the database, EF is crashing"
            };                                                                                                                                                   // Our single issue

            _predEngine = _mlContext.Model.CreatePredictionEngine <GitHubIssue, IssuePrediction>(loadedModel);
            var singleprediction = _predEngine.Predict(singleIssue);

            Console.WriteLine($"=============== Single Prediction - Result: {singleprediction.Area} ===============");


            /*
             * IEnumerable-based Batch Predictions
             * The following block of code, demonstrates the creation of manual entries and storing
             * them into area. Each of the indexes within the array is then predicted via the _predEngine.Predict function
             */

            IEnumerable <GitHubIssue> issues = new[]
            {
                new GitHubIssue
                {
                    Title       = "Entity Framework crashes",
                    Description = "When connecting to the database, EF is crashing"
                },
                new GitHubIssue
                {
                    Title       = "Github Down",
                    Description = "When going to the website, github says it is down"
                }
            };

            var batchPrediction = _predEngine;


            IDataView batchIssues = _mlContext.Data.LoadFromEnumerable(issues);


            IEnumerable <GitHubIssue> predictedResults =
                _mlContext.Data.CreateEnumerable <GitHubIssue>(batchIssues, reuseRowObject: false);

            foreach (GitHubIssue prediction in predictedResults)
            {
                Console.WriteLine($"=========================== Enumerated-based Batch Predictions ==================");
                Console.WriteLine($"*-> Title: {prediction.Title} | Prediction: {batchPrediction.Predict(prediction)}");
                Console.WriteLine($"=================================================================================");
            }



            /*
             * File-based Batch Predictions
             * The following block of code, demonstrates the ingestion of a file (myTestData.tsv) which has no
             * Area, to then predictteed via the _predEngine.Predict function.
             */
            _myTestDataView = _mlContext.Data.LoadFromTextFile <GitHubIssue>(_myTestDataPath, hasHeader: true);

            IEnumerable <GitHubIssue> filePredictedResults =
                _mlContext.Data.CreateEnumerable <GitHubIssue>(_myTestDataView, reuseRowObject: false);

            foreach (GitHubIssue prediction in filePredictedResults)
            {
                Console.WriteLine($"============================= File-based Batch Predictions ===========================");
                Console.WriteLine($"*-> Title: {prediction.Title} | Prediction: {batchPrediction.Predict(prediction).Area}");
                Console.WriteLine($"======================================================================================");
            }
        }
Beispiel #28
0
        private static TestCase ExtractTestCase(SystemUser systemUser, GitHubIssue issue, TestRailApiClient testRailClient,
                                                TestSuite newTestSuite)
        {
            var          testId       = issue.body.Split('/').Last();
            TestRailTest testRailTest = null;
            TestCase     newTest;

            if (int.TryParse(testId, out var tId))
            {
                testRailTest            = testRailClient.GetTest(tId);
                newTestSuite.TestRailId = testRailTest.suite_id;
                newTest = new TestCase
                {
                    Name          = testRailTest.title,
                    GitHubId      = issue.number,
                    Status        = Status.New,
                    TestRailId    = testRailTest.id,
                    TestSteps     = new List <TestStep>(),
                    Preconditions = testRailTest.custom_preconds
                };
            }
            else
            {
                newTest = new TestCase
                {
                    Name     = issue.title,
                    GitHubId = issue.number,
                    Status   = Status.ReadyForAutomation,
                    Message  = issue.body,
                    IsIssue  = true
                };
            }


            if (issue.Column == "Done")
            {
                newTest.Status     = Status.Finished;
                newTest.FinishedOn = issue.closed_at ?? DateTime.MinValue;
                newTest.StartedOn  = issue.created_at ?? DateTime.MinValue;
                newTest.Assignee   = systemUser;

                newTest.HistoryItems.Add(new TestCaseHistory
                {
                    Message = "status updated automatically on import"
                });
            }

            var steps = new List <TestStep>();

            if (testRailTest != null)
            {
                foreach (var customStepsSeparated in testRailTest.custom_steps_separated)
                {
                    steps.Add(new TestStep
                    {
                        Actual    = customStepsSeparated.content,
                        Expected  = customStepsSeparated.expected,
                        SortIndex = testRailTest.custom_steps_separated.IndexOf(customStepsSeparated)
                    });
                }
            }

            newTest.TestSteps = steps;
            newTest.HistoryItems.Add(new TestCaseHistory
            {
                Author  = systemUser,
                Message = "added test from Git Hub"
            });
            return(newTest);
        }
 private bool IsBugfix(GitHubIssue issue)
 {
     return(issue.Labels != null && issue.Labels.Select(label => label.Name).Contains("bug"));
 }
Beispiel #30
0
 public IssueViewModel(GitHubIssue issue)
 {
     _messageService = new MessageService();
     _githubService  = new GitHubService();
     GitHubIssue     = issue;
 }
 private static bool DoesIssueReference(GitHubIssue issue, int issueNumber)
 {
     return(issue.Body.Contains($"#{issueNumber}"));
 }