Ejemplo n.º 1
0
        private NewIssue CreateNewIssue(PortingInfo ruleToPort, string title)
        {
            var newIssue = new NewIssue(title);

            AddLabel(FxCopPortLabel, newIssue.Labels);

            AddAreaLabel(ruleToPort, newIssue.Labels);

            switch (ruleToPort.Disposition)
            {
            case Disposition.NeedsReview:
                AddLabel(NeedsReviewLabel, newIssue.Labels);
                break;

            case Disposition.Cut:
                AddLabel(CutLabel, newIssue.Labels);
                break;

            case Disposition.Ported:
                AddLabel(PortedLabel, newIssue.Labels);
                break;
            }

            if (ruleToPort.Soon)
            {
                AddLabel(UrgencySoonLabel, newIssue.Labels);
            }

            newIssue.Body = FormatIssueBody(ruleToPort);

            return(newIssue);
        }
Ejemplo n.º 2
0
        private string MakeIssueTitle(PortingInfo ruleToPort)
        {
            // Don't localize this. Otherwise people with different locales would file issues
            // with different titles, and you would get duplicates.
            const string FxCopPortTitlePrefix = "Port FxCop rule";

            return($"{FxCopPortTitlePrefix} {ruleToPort.Id}: {ruleToPort.Name}");
        }
Ejemplo n.º 3
0
 private string FormatIssueBody(PortingInfo ruleToPort)
 {
     // Don't localize this. We want all the issues in English.
     return
         ($"**Title:** {ruleToPort.Title}\n\n" +
          $"**Description:**\n\n{ruleToPort.Description}\n\n" +
          $"**Dependency:** {ruleToPort.Dependency}\n\n" +
          $"**Notes:**\n\n{ruleToPort.Notes}");
 }
Ejemplo n.º 4
0
        private void AddAreaLabel(PortingInfo ruleToPort, Collection <string> labels)
        {
            string areaLabel;

            if (!s_analyzerNameToLabelNameDictionary.TryGetValue(ruleToPort.ProposedAnalyzer, out areaLabel))
            {
                _log.WarnFormat(Resources.WarningNoAreaAssigned, ruleToPort.ProposedAnalyzer, ruleToPort.Id);
            }
            else
            {
                AddLabel(areaLabel, labels);
            }
        }
Ejemplo n.º 5
0
        private IssueUpdate CreateIssueUpdate(PortingInfo ruleToPort, Issue existingIssue)
        {
            IssueUpdate issueUpdate = existingIssue.ToUpdate();

            issueUpdate.Body = FormatIssueBody(ruleToPort);

            if (existingIssue.State == ItemState.Open && (ruleToPort.Disposition == Disposition.Cut || ruleToPort.Disposition == Disposition.Ported))
            {
                _log.InfoFormat(Resources.InfoClosingIssue, existingIssue.Number);
                issueUpdate.State = ItemState.Closed;
            }

            if (existingIssue.State == ItemState.Closed && (ruleToPort.Disposition != Disposition.Cut && ruleToPort.Disposition != Disposition.Ported))
            {
                _log.InfoFormat(Resources.InfoReopeningIssue, existingIssue.Number);
                issueUpdate.State = ItemState.Open;
            }

            return(issueUpdate);
        }
Ejemplo n.º 6
0
        private async Task <Issue> FileIssueAsync(PortingInfo ruleToPort, string title)
        {
            Issue issue = null;

            NewIssue newIssue = CreateNewIssue(ruleToPort, title);

            if (_options.DryRun)
            {
                _log.Info(Resources.InfoDryRunIssueNotCreated);
                issue = MakeFakeIssue(newIssue);
            }
            else
            {
                issue = await _issuesClient.Create(_options.RepoOwner, _options.RepoName, newIssue);

                _log.InfoFormat(Resources.InfoIssueCreated, issue.Number);
            }

            return(issue);
        }
Ejemplo n.º 7
0
        private async Task UpdateIssueAsync(PortingInfo ruleToPort, Issue existingIssue)
        {
            int issueNumber = existingIssue.Number;

            IssueUpdate issueUpdate = CreateIssueUpdate(ruleToPort, existingIssue);

            if (_options.DryRun)
            {
                _log.Info(Resources.InfoDryRunIssueNotUpdated);
            }
            else
            {
                await _issuesClient.Update(_options.RepoOwner, _options.RepoName, issueNumber, issueUpdate);

                _log.InfoFormat(Resources.InfoIssueUpdated, issueNumber);
            }

            // The GitHub Issues API doesn't let you add or remove individual labels in the course of
            // an Update operation. Use the IssuesLabels API to do that.
            await UpdateIssueLabelsAsync(ruleToPort, existingIssue);
        }
Ejemplo n.º 8
0
        private async Task UpdateIssueLabelsAsync(PortingInfo ruleToPort, Issue existingIssue)
        {
            var existingLabelNames = new Collection <string>(existingIssue.Labels.Select(label => label.Name).ToList());

            var labelNamesToAdd    = new Collection <string>();
            var labelNamesToRemove = new Collection <string>();

            AddLabel(FxCopPortLabel, labelNamesToAdd, existingLabelNames);

            if (ruleToPort.Soon)
            {
                AddLabel(UrgencySoonLabel, labelNamesToAdd, existingLabelNames);
            }
            else
            {
                RemoveLabel(UrgencySoonLabel, labelNamesToRemove, existingLabelNames);
            }

            switch (ruleToPort.Disposition)
            {
            case Disposition.NeedsReview:
                AddLabel(NeedsReviewLabel, labelNamesToAdd, existingLabelNames);
                RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames);
                RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames);
                break;

            case Disposition.Port:
                RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames);
                RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames);
                RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames);
                break;

            case Disposition.Cut:
                AddLabel(CutLabel, labelNamesToAdd, existingLabelNames);
                RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames);
                RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames);
                break;

            case Disposition.Ported:
                AddLabel(PortedLabel, labelNamesToAdd, existingLabelNames);
                RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames);
                RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames);
                break;
            }

            RemoveAreaLabels(existingLabelNames, labelNamesToRemove);
            AddAreaLabel(ruleToPort, labelNamesToAdd);

            if (_options.DryRun)
            {
                _log.Info(Resources.InfoDryRunLabelsNotUpdated);
            }
            else
            {
                if (labelNamesToAdd.Any())
                {
                    await _issuesLabelsClient.AddToIssue(
                        _options.RepoOwner,
                        _options.RepoName,
                        existingIssue.Number,
                        labelNamesToAdd.ToArray());
                }

                // Take care not to remove any labels we've just added.
                //
                // For some reason the "Remove" API doesn't take an array.
                foreach (string labelName in labelNamesToRemove.Except(labelNamesToAdd))
                {
                    await _issuesLabelsClient.RemoveFromIssue(
                        _options.RepoOwner,
                        _options.RepoName,
                        existingIssue.Number,
                        labelName);
                }
            }
        }
Ejemplo n.º 9
0
 private string FormatIssueBody(PortingInfo ruleToPort)
 {
     // Don't localize this. We want all the issues in English.
     return
         $"**Title:** {ruleToPort.Title}\n\n" +
         $"**Description:**\n\n{ruleToPort.Description}\n\n" +
         $"**Dependency:** {ruleToPort.Dependency}\n\n" +
         $"**Notes:**\n\n{ruleToPort.Notes}";
 }
Ejemplo n.º 10
0
        private IssueUpdate CreateIssueUpdate(PortingInfo ruleToPort, Issue existingIssue)
        {
            IssueUpdate issueUpdate = existingIssue.ToUpdate();
            issueUpdate.Body = FormatIssueBody(ruleToPort);

            if (existingIssue.State == ItemState.Open && (ruleToPort.Disposition == Disposition.Cut || ruleToPort.Disposition == Disposition.Ported))
            {
                _log.InfoFormat(Resources.InfoClosingIssue, existingIssue.Number);
                issueUpdate.State = ItemState.Closed;
            }

            if (existingIssue.State == ItemState.Closed && (ruleToPort.Disposition != Disposition.Cut && ruleToPort.Disposition != Disposition.Ported))
            {
                _log.InfoFormat(Resources.InfoReopeningIssue, existingIssue.Number);
                issueUpdate.State = ItemState.Open;
            }

            return issueUpdate;
        }
Ejemplo n.º 11
0
        private async Task UpdateIssueLabelsAsync(PortingInfo ruleToPort, Issue existingIssue)
        {
            var existingLabelNames = new Collection<string>(existingIssue.Labels.Select(label => label.Name).ToList());

            var labelNamesToAdd = new Collection<string>();
            var labelNamesToRemove = new Collection<string>();

            AddLabel(FxCopPortLabel, labelNamesToAdd, existingLabelNames);

            if (ruleToPort.Soon)
            {
                AddLabel(UrgencySoonLabel, labelNamesToAdd, existingLabelNames);
            }
            else
            {
                RemoveLabel(UrgencySoonLabel, labelNamesToRemove, existingLabelNames);
            }

            switch (ruleToPort.Disposition)
            {
                case Disposition.NeedsReview:
                    AddLabel(NeedsReviewLabel, labelNamesToAdd, existingLabelNames);
                    RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames);
                    RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames);
                    break;

                case Disposition.Port:
                    RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames);
                    RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames);
                    RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames);
                    break;

                case Disposition.Cut:
                    AddLabel(CutLabel, labelNamesToAdd, existingLabelNames);
                    RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames);
                    RemoveLabel(PortedLabel, labelNamesToRemove, existingLabelNames);
                    break;

                case Disposition.Ported:
                    AddLabel(PortedLabel, labelNamesToAdd, existingLabelNames);
                    RemoveLabel(CutLabel, labelNamesToRemove, existingLabelNames);
                    RemoveLabel(NeedsReviewLabel, labelNamesToRemove, existingLabelNames);
                    break;
            }

            RemoveAreaLabels(existingLabelNames, labelNamesToRemove);
            AddAreaLabel(ruleToPort, labelNamesToAdd);

            if (_options.DryRun)
            {
                _log.Info(Resources.InfoDryRunLabelsNotUpdated);
            }
            else
            {
                if (labelNamesToAdd.Any())
                {
                    await _issuesLabelsClient.AddToIssue(
                        _options.RepoOwner,
                        _options.RepoName,
                        existingIssue.Number,
                        labelNamesToAdd.ToArray());
                }

                // Take care not to remove any labels we've just added.
                //
                // For some reason the "Remove" API doesn't take an array.
                foreach (string labelName in labelNamesToRemove.Except(labelNamesToAdd))
                {
                    await _issuesLabelsClient.RemoveFromIssue(
                        _options.RepoOwner,
                        _options.RepoName,
                        existingIssue.Number,
                        labelName);
                }
            }
        }
Ejemplo n.º 12
0
 private void AddAreaLabel(PortingInfo ruleToPort, Collection<string> labels)
 {
     string areaLabel;
     if (!s_analyzerNameToLabelNameDictionary.TryGetValue(ruleToPort.ProposedAnalyzer, out areaLabel))
     {
         _log.WarnFormat(Resources.WarningNoAreaAssigned, ruleToPort.ProposedAnalyzer, ruleToPort.Id);
     }
     else
     {
         AddLabel(areaLabel, labels);
     }
 }
Ejemplo n.º 13
0
        private NewIssue CreateNewIssue(PortingInfo ruleToPort, string title)
        {
            var newIssue = new NewIssue(title);
            AddLabel(FxCopPortLabel, newIssue.Labels);

            AddAreaLabel(ruleToPort, newIssue.Labels);

            switch (ruleToPort.Disposition)
            {
                case Disposition.NeedsReview:
                    AddLabel(NeedsReviewLabel, newIssue.Labels);
                    break;

                case Disposition.Cut:
                    AddLabel(CutLabel, newIssue.Labels);
                    break;

                case Disposition.Ported:
                    AddLabel(PortedLabel, newIssue.Labels);
                    break;
            }

            if (ruleToPort.Soon)
            {
                AddLabel(UrgencySoonLabel, newIssue.Labels);
            }

            newIssue.Body = FormatIssueBody(ruleToPort);

            return newIssue;
        }
Ejemplo n.º 14
0
        private string MakeIssueTitle(PortingInfo ruleToPort)
        {
            // Don't localize this. Otherwise people with different locales would file issues
            // with different titles, and you would get duplicates.
            const string FxCopPortTitlePrefix = "Port FxCop rule";

            return $"{FxCopPortTitlePrefix} {ruleToPort.Id}: {ruleToPort.Name}";
        }
Ejemplo n.º 15
0
        private async Task UpdateIssueAsync(PortingInfo ruleToPort, Issue existingIssue)
        {
            int issueNumber = existingIssue.Number;

            IssueUpdate issueUpdate = CreateIssueUpdate(ruleToPort, existingIssue);
            if (_options.DryRun)
            {
                _log.Info(Resources.InfoDryRunIssueNotUpdated);
            }
            else
            {
                await _issuesClient.Update(_options.RepoOwner, _options.RepoName, issueNumber, issueUpdate);
                _log.InfoFormat(Resources.InfoIssueUpdated, issueNumber);
            }

            // The GitHub Issues API doesn't let you add or remove individual labels in the course of
            // an Update operation. Use the IssuesLabels API to do that.
            await UpdateIssueLabelsAsync(ruleToPort, existingIssue);
        }
Ejemplo n.º 16
0
        private async Task<Issue> FileIssueAsync(PortingInfo ruleToPort, string title)
        {
            Issue issue = null;

            NewIssue newIssue = CreateNewIssue(ruleToPort, title);
            if (_options.DryRun)
            {
                _log.Info(Resources.InfoDryRunIssueNotCreated);
                issue = MakeFakeIssue(newIssue);
            }
            else
            {
                issue = await _issuesClient.Create(_options.RepoOwner, _options.RepoName, newIssue);
                _log.InfoFormat(Resources.InfoIssueCreated, issue.Number);
            }

            return issue;
        }