Exemplo n.º 1
0
        public async Task PostAsync([FromBody] IssueEventPayload data)
        {
            IssueModel       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");
            }
        }
Exemplo n.º 2
0
        public async Task PredictAndApplyLabelAsync(int number, string title, string body, GithubObjectType issueOrPr, ILogger logger)
        {
            if (_client == null)
            {
                await GitSetupAsync();
            }
            if (_regex == null)
            {
                _regex = new Regex(@"@[a-zA-Z0-9_//-]+");
            }
            var userMentions = _regex.Matches(body).Select(x => x.Value).ToArray();

            string label;

            if (issueOrPr == GithubObjectType.Issue)
            {
                IssueModel issue = CreateIssue(number, title, body, userMentions);
                label = Predictor.Predict(issue, logger, _threshold);
            }
            else
            {
                PrModel pr = await CreatePullRequest(number, title, body, userMentions);

                label = Predictor.Predict(pr, 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} {number} confidently.");
            }
        }
Exemplo n.º 3
0
 public LabelSuggestion Predict(IssueModel issue, ILogger logger)
 {
     return(Predict(issue, _modelHolder.IssuePredEngine, logger));
 }
Exemplo n.º 4
0
 public static string Predict(IssueModel issue, ILogger logger, double threshold)
 {
     return(Predict(issue, ref issuePredEngine, logger, threshold));
 }