Example #1
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");
            }
        }
Example #2
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.");
            }
        }
Example #3
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.");
            }
        }
Example #4
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.");
            }
        }