Exemple #1
0
        public async Task PredictAndApplyLabelAsync(int number, string title, string body, ILogger logger)
        {
            if (_client == null)
            {
                await GitSetupAsync();
            }

            var corefxIssue = new GitHubIssue
            {
                Number = number,
                Title  = title,
                Body   = body
            };

            string label = Predictor.Predict(corefxIssue, logger, _threshold);
            Issue  issueGithubVersion = await _client.Issue.Get(_repoOwner, _repoName, number);

            if (label != null && issueGithubVersion.Labels.Count == 0)
            {
                var issueUpdate = new IssueUpdate();
                issueUpdate.AddLabel(label);
                issueUpdate.Milestone = issueGithubVersion.Milestone?.Number; // The number of milestone associated with the issue.

                await _client.Issue.Update(_repoOwner, _repoName, number, issueUpdate);
            }
            else
            {
                logger.LogInformation($"! The Model is not able to assign the label to the Issue {corefxIssue.Number} confidently.");
            }
        }
Exemple #2
0
        public async Task PredictAndApplyLabelAsync(int number, string title, string body, int?milestone, ILogger logger)
        {
            if (_client == null)
            {
                await GitSetupAsync();
            }

            var corefxIssue = new GitHubIssue
            {
                ID          = number.ToString(),
                Title       = title,
                Description = body
            };

            string label = await Predictor.PredictAsync(corefxIssue, logger, _threshold);

            if (label != null)
            {
                var issueUpdate = new IssueUpdate();
                issueUpdate.AddLabel(label);
                issueUpdate.Milestone = milestone; // The number of milestone associated with the issue.

                await _client.Issue.Update(_repoOwner, _repoName, number, issueUpdate);
            }
            else
            {
                logger.LogInformation($"! The Model is not able to assign the label to the Issue {corefxIssue.ID} confidently.");
            }
        }
Exemple #3
0
        public async Task PredictAndApplyLabelAsync(int number, string title, string body, ILogger logger)
        {
            var corefxIssue = new GitHubIssue
            {
                ID          = number.ToString(),
                Title       = title,
                Description = body
            };

            string label = await Predictor.PredictAsync(corefxIssue, logger);

            if (label != null)
            {
                var issueUpdate = new IssueUpdate();
                issueUpdate.AddLabel(label);

                await _client.Issue.Update(_repoOwner, _repoName, number, issueUpdate);

                logger.LogInformation($"Issue {corefxIssue.ID} : \"{corefxIssue.Title}\" was labeled as: {label}");
            }
            else
            {
                logger.LogInformation($"The Model is not able to assign the label to the Issue {corefxIssue.ID} confidently.");
            }
        }
Exemple #4
0
        public static async Task <string> PredictAsync(GitHubIssue issue, ILogger logger, double threshold)
        {
            PredictionModel <GitHubIssue, GitHubIssuePrediction> model = await PredictionModel.ReadAsync <GitHubIssue, GitHubIssuePrediction>(ModelPath);

            GitHubIssuePrediction prediction = model.Predict(issue);

            float[] probabilities  = prediction.Probabilities;
            float   maxProbability = probabilities.Max();

            logger.LogInformation($"# {maxProbability.ToString()} {prediction.Area} for #{issue.ID} {issue.Title}");
            return(maxProbability > threshold ? prediction.Area : null);
        }
Exemple #5
0
        public static async Task <string> PredictAsync(GitHubIssue issue, ILogger logger)
        {
            PredictionModel <GitHubIssue, GitHubIssuePrediction> model = await PredictionModel.ReadAsync <GitHubIssue, GitHubIssuePrediction>(ModelPath);

            GitHubIssuePrediction prediction = model.Predict(issue);

            float[] probabilities  = prediction.Probabilities;
            float   maxProbability = probabilities.Max();

            logger.LogInformation($"Label {prediction.Area} for {issue.ID} is predicted with confidence {maxProbability.ToString()}");

            return(maxProbability > 0.8 ? prediction.Area : null);
        }
Exemple #6
0
        public static string Predict(GitHubIssue issue, ILogger logger, double threshold)
        {
            if (predEngine == null)
            {
                MLContext    mlContext = new MLContext();
                ITransformer mlModel   = mlContext.Model.Load(ModelPath, out DataViewSchema inputSchema);
                predEngine = mlContext.Model.CreatePredictionEngine <GitHubIssue, GitHubIssuePrediction>(mlModel);
            }

            GitHubIssuePrediction prediction = predEngine.Predict(issue);

            float[] probabilities  = prediction.Score;
            float   maxProbability = probabilities.Max();

            logger.LogInformation($"# {maxProbability.ToString()} {prediction.Area} for #{issue.Number} {issue.Title}");
            return(maxProbability > threshold ? prediction.Area : null);
        }
Exemple #7
0
        public async Task PostAsync([FromBody]IssueEventPayload data)
        {
            GitHubIssue issue = data.Issue;
            List<object> labels = issue.Labels;

            if (data.Action == "opened" && labels.Count == 0)
            {
                string title = issue.Title;
                int number = issue.Number;
                string body = issue.Description;

                await Issuelabeler.PredictAndApplyLabelAsync(number, title, body, Logger);
                Logger.LogInformation("! Labeling completed");
            }
            else
            {
                Logger.LogInformation($"! The issue {issue.Number.ToString()} is already opened or it already has a label");
            }
        }
Exemple #8
0
        public async Task PostAsync([FromBody] IssueEventPayload data)
        {
            GitHubIssue      issueOrPullRequest = data.Issue ?? data.Pull_Request;
            GithubObjectType issueOrPr          = data.Issue == null ? GithubObjectType.PullRequest : GithubObjectType.Issue;

            if (data.Action == "opened" && issueOrPullRequest.Labels.Count == 0)
            {
                string title  = issueOrPullRequest.Title;
                int    number = issueOrPullRequest.Number;
                string body   = issueOrPullRequest.Body;

                await Issuelabeler.PredictAndApplyLabelAsync(number, title, body, issueOrPr, Logger);

                Logger.LogInformation("! Labeling completed");
            }
            else
            {
                Logger.LogInformation($"! The {issueOrPr} {issueOrPullRequest.Number} is already opened or it already has a label");
            }
        }
Exemple #9
0
        public async Task PredictAndApplyLabelAsync(int number, string title, string body, GithubObjectType issueOrPr, ILogger logger)
        {
            if (_client == null)
            {
                await GitSetupAsync();
            }

            var corefxIssue = new GitHubIssue
            {
                Number    = number,
                Title     = title,
                Body      = body,
                IssueOrPr = issueOrPr,
                IsPR      = issueOrPr == GithubObjectType.PullRequest,
                FilePaths = string.Empty
            };

            if (corefxIssue.IsPR)
            {
                IReadOnlyList <PullRequestFile> prFiles = await _client.PullRequest.Files(_repoOwner, _repoName, number);

                corefxIssue.FilePaths = String.Join(";", prFiles.Select(x => x.FileName));
            }

            string label = Predictor.Predict(corefxIssue, logger, _threshold);
            Issue  issueGithubVersion = await _client.Issue.Get(_repoOwner, _repoName, number);

            if (label != null && issueGithubVersion.Labels.Count == 0)
            {
                var issueUpdate = new IssueUpdate();
                issueUpdate.AddLabel(label);
                issueUpdate.Milestone = issueGithubVersion.Milestone?.Number; // The number of milestone associated with the issue.

                await _client.Issue.Update(_repoOwner, _repoName, number, issueUpdate);
            }
            else
            {
                logger.LogInformation($"! The Model is not able to assign the label to the {issueOrPr} {corefxIssue.Number} confidently.");
            }
        }
Exemple #10
0
        public async Task PredictAndApplyLabelAsync(int number, string title, string body, GithubObjectType issueOrPr, ILogger logger)
        {
            if (_client == null)
            {
                await GitSetupAsync();
            }

            var corefxIssue = new GitHubIssue
            {
                Number    = number,
                Title     = title,
                Body      = body,
                IssueOrPr = issueOrPr
            };

            string label = Predictor.Predict(corefxIssue, logger, _threshold);
            Issue  issueGithubVersion = await _client.Issue.Get(_repoOwner, _repoName, number);

            if (label.Equals("area-System.Net.Http.SocketsHttpHandler", StringComparison.OrdinalIgnoreCase))
            {
                label = "area-System.Net.Http";
            }

            if (label != null && issueGithubVersion.Labels.Count == 0)
            {
                var issueUpdate = new IssueUpdate();
                issueUpdate.AddLabel(label);
                issueUpdate.Milestone = issueGithubVersion.Milestone?.Number; // The number of milestone associated with the issue.

                await _client.Issue.Update(_repoOwner, _repoName, number, issueUpdate);
            }
            else
            {
                logger.LogInformation($"! The Model is not able to assign the label to the {issueOrPr} {corefxIssue.Number} confidently.");
            }
        }