Example #1
0
        public IActionResult ManuallyRequestEnginesLoaded(string owner, string repo)
        {
            // TODO: Add a threshold for how many repo engine loads are allowed
            if (!owner.Equals(_owner, StringComparison.OrdinalIgnoreCase))
            {
                return(BadRequest($"Only predictions for {_owner} are supported"));
            }

            var modelHolder = _modelHolderFactory.CreateModelHolder(owner, repo);

            if (modelHolder == null)
            {
                return(BadRequest($"Repo {_owner}/{repo} is not yet configured for label prediction."));
            }

            if (modelHolder.IsIssueEngineLoaded && (modelHolder.UseIssuesForPrsToo || modelHolder.IsPrEngineLoaded))
            {
                // queued hosted serrvice: task to only download and load models
                Logger.LogInformation("! Checked to see if prediction engines were loaded: {Owner}/{Repo}", _owner, repo);
                return(Ok($"Loaded {owner}/{repo}"));
            }
            return(Ok($"Prediction engines for {owner}/{repo} are still loading."));
        }
Example #2
0
        public async Task <LabelSuggestion> PredictUsingModelsFromStorageQueue(string owner, string repo, int number)
        {
            if (_regex == null)
            {
                _regex = new Regex(@"@[a-zA-Z0-9_//-]+");
            }
            var modelHolder = _modelHolderFactory.CreateModelHolder(owner, repo);

            if (modelHolder == null)
            {
                throw new InvalidOperationException($"Repo {owner}/{repo} is not yet configured for label prediction.");
            }
            if (!modelHolder.IsIssueEngineLoaded || (!modelHolder.UseIssuesForPrsToo && !modelHolder.IsPrEngineLoaded))
            {
                throw new InvalidOperationException("load engine before calling predict");
            }

            var iop = await _gitHubClientWrapper.GetIssue(owner, repo, number);

            bool isPr = iop.PullRequest != null;


            string          body            = iop.Body ?? string.Empty;
            var             userMentions    = _regex.Matches(body).Select(x => x.Value).ToArray();
            LabelSuggestion labelSuggestion = null;

            if (isPr && !_useIssueLabelerForPrsToo)
            {
                var prModel = await CreatePullRequest(owner, repo, iop.Number, iop.Title, iop.Body, userMentions, iop.User.Login);

                labelSuggestion = Predictor.Predict(prModel, _logger, modelHolder);
                _logger.LogInformation("predicted with pr model the new way");
                _logger.LogInformation(string.Join(",", labelSuggestion.LabelScores.Select(x => x.LabelName)));
                return(labelSuggestion);
            }
            var issueModel = CreateIssue(iop.Number, iop.Title, iop.Body, userMentions, iop.User.Login);

            labelSuggestion = Predictor.Predict(issueModel, _logger, modelHolder);
            _logger.LogInformation("predicted with issue model the new way");
            _logger.LogInformation(string.Join(",", labelSuggestion.LabelScores.Select(x => x.LabelName)));
            return(labelSuggestion);
        }