コード例 #1
0
        public async Task <RoslynExportProfileResponse> GetRoslynExportProfileAsync(string qualityProfileName,
                                                                                    SonarQubeLanguage language, CancellationToken token)
        {
            EnsureIsConnected();

            var request = new RoslynExportProfileRequest {
                QualityProfileName = qualityProfileName, LanguageKey = language.Key
            };
            var roslynExportResult = await this.sonarqubeClient.GetRoslynExportProfileAsync(request, token);

            roslynExportResult.EnsureSuccess();

            return(roslynExportResult.Value);
        }
コード例 #2
0
        public Language(string id, string name, string fileSuffix, SonarQubeLanguage serverLanguage)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException(nameof(id));
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (string.IsNullOrWhiteSpace(fileSuffix))
            {
                throw new ArgumentNullException(nameof(fileSuffix));
            }

            this.Id   = id;
            this.Name = name;
            this.FileSuffixAndExtension = fileSuffix;
            this.ServerLanguage         = serverLanguage ?? throw new ArgumentNullException(nameof(serverLanguage));
        }
コード例 #3
0
        public async Task <SonarQubeQualityProfile> GetQualityProfileAsync(string projectKey, string organizationKey,
                                                                           SonarQubeLanguage language, CancellationToken token)
        {
            EnsureIsConnected();

            var qualityProfileRequest = new QualityProfileRequest {
                ProjectKey = projectKey, OrganizationKey = organizationKey
            };
            var qualityProfilesResult = await this.sonarqubeClient.GetQualityProfilesAsync(qualityProfileRequest, token);

            // Special handling for the case when a project was not analyzed yet, in which case a 404 is returned
            if (qualityProfilesResult.StatusCode == HttpStatusCode.NotFound)
            {
                qualityProfileRequest = new QualityProfileRequest {
                    ProjectKey = null, OrganizationKey = organizationKey
                };
                qualityProfilesResult = await this.sonarqubeClient.GetQualityProfilesAsync(qualityProfileRequest, token);
            }

            qualityProfilesResult.EnsureSuccess();

            var profilesWithGivenLanguage = qualityProfilesResult.Value.Where(x => x.Language == language.Key).ToList();

            var qualityProfile = profilesWithGivenLanguage.Count > 1
                ? profilesWithGivenLanguage.Single(x => x.IsDefault)
                : profilesWithGivenLanguage.Single();

            var qualityProfileChangeLogRequest = new QualityProfileChangeLogRequest
            {
                PageSize          = 1,
                QualityProfileKey = qualityProfile.Key
            };
            var changeLog = await this.sonarqubeClient.GetQualityProfileChangeLogAsync(qualityProfileChangeLogRequest, token);

            changeLog.EnsureSuccess();

            return(SonarQubeQualityProfile.FromResponse(qualityProfile, changeLog.Value.Events.Single().Date));
        }
コード例 #4
0
        public void Language_Ctor_ArgChecks()
        {
            // Arrange
            var key            = "k";
            var name           = "MyName";
            var fileSuffix     = "suffix";
            var serverLanguage = new SonarQubeLanguage("serverKey", "serverName");

            // Act + Assert
            // Nulls
            Action act = () => new Language(name, null, fileSuffix, serverLanguage);

            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("name");

            act = () => new Language(null, key, fileSuffix, serverLanguage);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("id");

            act = () => new Language(name, key, null, serverLanguage);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("fileSuffix");

            act = () => new Language(name, key, fileSuffix, null);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("serverLanguage");
        }
コード例 #5
0
 public async Task <RoslynExportProfileResponse> GetRoslynExportProfileAsync(string qualityProfileName,
                                                                             string organizationKey, SonarQubeLanguage language, CancellationToken token) =>
 await InvokeRequestAsync <IGetRoslynExportProfileRequest, RoslynExportProfileResponse>(
     request =>
 {
     request.QualityProfileName = qualityProfileName;
     request.LanguageKey        = language.Key;
     request.OrganizationKey    = organizationKey;
 },
     token);
コード例 #6
0
        public async Task <SonarQubeQualityProfile> GetQualityProfileAsync(string projectKey, string organizationKey, SonarQubeLanguage language, CancellationToken token)
        {
            var qualityProfiles = await InvokeRequestAsync <IGetQualityProfilesRequest, SonarQubeQualityProfile[]>(
                request =>
            {
                request.ProjectKey      = projectKey;
                request.OrganizationKey = organizationKey;
            },
                token);

            // Consider adding the language filter to the request configuration above and removing this line
            var profilesWithGivenLanguage = qualityProfiles.Where(x => x.Language == language.Key).ToList();

            if (profilesWithGivenLanguage.Count == 0)
            {
                throw new InvalidOperationException($"The {language.PluginName} plugin is not installed on the connected SonarQube.");
            }

            var qualityProfile = profilesWithGivenLanguage.Count > 1
                ? profilesWithGivenLanguage.Single(x => x.IsDefault)
                : profilesWithGivenLanguage.Single();

            var changeLog = await InvokeRequestAsync <IGetQualityProfileChangeLogRequest, DateTime[]>(
                request =>
            {
                request.Page               = 1;
                request.PageSize           = 1;
                request.QualityProfileKey  = qualityProfile.Key;
                request.QualityProfileName = qualityProfile.Name;
                request.LanguageName       = language.Key;
                request.OrganizationKey    = organizationKey;
            },
                token);

            var updatedDate = changeLog.Any() ? changeLog.Single() : qualityProfile.TimeStamp;

            return(new SonarQubeQualityProfile(qualityProfile.Key, qualityProfile.Name, qualityProfile.Language,
                                               qualityProfile.IsDefault, updatedDate));
        }
コード例 #7
0
        public async Task <RoslynExportProfileResponse> GetRoslynExportProfileAsync(string qualityProfileName,
                                                                                    string organizationKey, SonarQubeLanguage language, CancellationToken token)
        {
            EnsureIsConnected();

            var request = this.serverVersion >= new Version(6, 6)
                ? new RoslynExportProfileRequestV66Plus {
                QualityProfileName = qualityProfileName, OrganizationKey = organizationKey, LanguageKey = language.Key
            }
                : new RoslynExportProfileRequest {
                QualityProfileName = qualityProfileName, OrganizationKey = organizationKey, LanguageKey = language.Key
            };
            var roslynExportResult = await this.sonarqubeClient.GetRoslynExportProfileAsync(request, token);

            roslynExportResult.EnsureSuccess();

            return(roslynExportResult.Value);
        }