Exemplo n.º 1
0
        public async Task <ComponentTreeMeasure> GetMeasuresComponentTreeAsync(string component, string[] metricKeys, AvailableMeasureFields[] additionalFields = null, bool?asc = null,
                                                                               int?metricPeriodSort             = null, string metricSort = null, MetricSortFilters?metricSortFilter = null, int?p = null, int?ps = null, string q = null,
                                                                               ComponentQualifiers[] qualifiers = null, MeasureSortFields[] s = null, MeasureSearchStrategies?strategy = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(component)]        = component,
                [nameof(metricKeys)]       = string.Join(",", metricKeys),
                [nameof(additionalFields)] = additionalFields == null ? null : string.Join(",", additionalFields.Select(AvailableMeasureFieldsConverter.ToString)),
                [nameof(asc)] = BooleanConverter.ToString(asc),
                [nameof(metricPeriodSort)] = metricPeriodSort,
                [nameof(metricSort)]       = metricSort,
                [nameof(metricSortFilter)] = metricSortFilter == null ? null : MetricSortFiltersConverter.ToString(metricSortFilter),
                [nameof(p)]          = p,
                [nameof(ps)]         = ps,
                [nameof(q)]          = q,
                [nameof(qualifiers)] = qualifiers == null ? null : string.Join(",", qualifiers.Select(ComponentQualifiersConverter.ToString)),
                [nameof(s)]          = s == null ? null : string.Join(",", s.Select(MeasureSortFieldsConverter.ToString)),
                [nameof(strategy)]   = strategy == null ? null : MeasureSearchStrategiesConverter.ToString(strategy)
            };

            return(await GetMeasuresUrl("component_tree")
                   .SetQueryParams(queryParamValues)
                   .GetJsonAsync <ComponentTreeMeasure>()
                   .ConfigureAwait(false));
        }
Exemplo n.º 2
0
        public async Task <Rule> ShowRuleAsync(string key, bool?actives = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(key)]     = key,
                [nameof(actives)] = BooleanConverter.ToString(actives)
            };

            return(await GetRulesUrl("show")
                   .SetQueryParams(queryParamValues)
                   .GetJsonFirstNodeAsync <Rule>()
                   .ConfigureAwait(false));
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <Tuple <int, string, string, string> > > GetScmSourcesAsync(string key, bool?commitsByLine = null, string from = null, string to = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(key)]       = key,
                ["commits_by_line"] = BooleanConverter.ToString(commitsByLine),
                [nameof(from)]      = from,
                [nameof(to)]        = to
            };

            return(await GetSourcesUrl("scm")
                   .SetQueryParams(queryParamValues)
                   .GetJsonFirstNodeAsync <IEnumerable <Tuple <int, string, string, string> >, TupleFourTypesConverter <int, string, string, string> >()
                   .ConfigureAwait(false));
        }
Exemplo n.º 4
0
        public async Task <SearchQualityProfiles> SearchQualityProfilesAsync(bool?defaults = null, string language = null, string project = null, string qualityProfile = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(defaults)]       = BooleanConverter.ToString(defaults),
                [nameof(language)]       = language,
                [nameof(project)]        = project,
                [nameof(qualityProfile)] = qualityProfile
            };

            return(await GetQualityProfilesUrl("search")
                   .SetQueryParams(queryParamValues)
                   .GetJsonAsync <SearchQualityProfiles>()
                   .ConfigureAwait(false));
        }
Exemplo n.º 5
0
        public async Task <bool> SetProjectBranchAutomaticDeletionProtectionAsync(string project, string branch, bool value)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(project)] = project,
                [nameof(branch)]  = branch,
                [nameof(value)]   = BooleanConverter.ToString(value)
            };

            var response = await GetProjectBranchesUrl("set_automatic_deletion_protection")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseAsync(response).ConfigureAwait(false));
        }
Exemplo n.º 6
0
        public async Task <IssuesList> SearchIssuesAsync(AvailableIssueFields[] additionalFields = null, bool?asc  = null, bool?assigned         = null, string[] assignees = null,
                                                         string[] author            = null, string[] componentKeys = null, DateTime?createdAfter = null, DateTime?createdAt = null, DateTime?createdBefore = null, string createdInLast = null,
                                                         string[] cwe               = null, Facets[] facets = null, string[] issues       = null, string[] languages = null, bool?onComponentsOnly = null, OwaspTop10Types[] owaspTop10 = null,
                                                         int?p                      = null, int?ps = null, IssueResolutions[] resolutions = null, bool?resolved      = null, string[] rules = null, IssueSortFields[] s = null,
                                                         SansTop25Types[] sansTop25 = null, Severities[] severities = null, bool?sinceLeakPeriod = null, SonarSourceSecurityTypes[] sonarSourceSecurity = null,
                                                         IssueStatuses[] statuses   = null, string[] tags           = null, IssueTypes[] types = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(additionalFields)] = additionalFields == null ? null : string.Join(",", additionalFields.Select(AvailableIssueFieldsConverter.ToString)),
                [nameof(asc)]              = BooleanConverter.ToString(asc),
                [nameof(assigned)]         = BooleanConverter.ToString(assigned),
                [nameof(assignees)]        = assignees == null ? null : string.Join(",", assignees),
                [nameof(author)]           = author,
                [nameof(componentKeys)]    = componentKeys == null ? null : string.Join(",", componentKeys),
                [nameof(createdAfter)]     = DateTimeToStringConverter.ToString(createdAfter),
                [nameof(createdAt)]        = DateTimeToStringConverter.ToString(createdAt),
                [nameof(createdBefore)]    = DateTimeToStringConverter.ToString(createdBefore),
                [nameof(createdInLast)]    = createdInLast,
                [nameof(cwe)]              = cwe == null ? null : string.Join(",", cwe),
                [nameof(facets)]           = facets == null ? null : string.Join(",", facets.Select(FacetsConverter.ToString)),
                [nameof(issues)]           = issues == null ? null : string.Join(",", issues),
                [nameof(languages)]        = languages == null ? null : string.Join(",", languages),
                [nameof(onComponentsOnly)] = onComponentsOnly,
                [nameof(owaspTop10)]       = owaspTop10 == null ? null : string.Join(",", owaspTop10.Select(OwaspTop10TypesConverter.ToString)),
                [nameof(p)]                   = p,
                [nameof(ps)]                  = ps,
                [nameof(resolutions)]         = resolutions == null ? null : string.Join(",", resolutions.Select(IssueResolutionsConverter.ToString)),
                [nameof(resolved)]            = BooleanConverter.ToString(resolved),
                [nameof(rules)]               = rules,
                [nameof(s)]                   = s,
                [nameof(sansTop25)]           = sansTop25 == null ? null : string.Join(",", sansTop25.Select(SansTop25TypesConverter.ToString)),
                [nameof(severities)]          = severities == null ? null : string.Join(",", severities.Select(SeveritiesConverter.ToString)),
                [nameof(sinceLeakPeriod)]     = BooleanConverter.ToString(sinceLeakPeriod),
                [nameof(sonarSourceSecurity)] = sonarSourceSecurity == null ? null : string.Join(",", sonarSourceSecurity.Select(SonarSourceSecurityTypesConverter.ToString)),
                [nameof(statuses)]            = statuses == null ? null : string.Join(",", statuses.Select(IssueStatusesConverter.ToString)),
                [nameof(tags)]                = tags,
                [nameof(types)]               = types == null ? null : string.Join(",", types.Select(IssueTypesConverter.ToString))
            };

            return(await GetIssuesUrl("search")
                   .SetQueryParams(queryParamValues)
                   .GetJsonAsync <IssuesList>()
                   .ConfigureAwait(false));
        }
Exemplo n.º 7
0
        public async Task <bool> ActivateQualityProfileRuleAsync(string key, string rule, IDictionary <string, string> parameters = null, bool?reset = null, Severities?severity = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(key)]      = key,
                [nameof(rule)]     = rule,
                ["params"]         = parameters,         // XXX
                [nameof(reset)]    = BooleanConverter.ToString(reset),
                [nameof(severity)] = SeveritiesConverter.ToString(severity)
            };

            var response = await GetQualityProfilesUrl("activate_rule")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseAsync(response).ConfigureAwait(false));
        }
Exemplo n.º 8
0
        public async Task <IEnumerable <ProjectComponent> > SearchProjectsAsync(DateTime?analyzedBefore = null, bool?onProvisionedOnly = null, int?p = null, string[] projects = null, int?ps = null, string q = null, ProjectQualifiers[] qualifiers = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(analyzedBefore)]    = DateTimeToStringConverter.ToString(analyzedBefore),
                [nameof(onProvisionedOnly)] = BooleanConverter.ToString(onProvisionedOnly),
                [nameof(p)]          = p,
                [nameof(projects)]   = projects == null ? null : string.Join(",", projects),
                [nameof(ps)]         = ps,
                [nameof(q)]          = q,
                [nameof(qualifiers)] = qualifiers == null ? null : string.Join(",", qualifiers.Select(ProjectQualifiersConverter.ToString)),
            };

            return(await GetProjectsUrl("search")
                   .SetQueryParams(queryParamValues)
                   .GetJsonNamedNodeAsync <IEnumerable <ProjectComponent> >("components")
                   .ConfigureAwait(false));
        }
Exemplo n.º 9
0
        public async Task <ComponentsTree> GetComponentsTreeAsync(string component, bool?asc = null, int?p = null, int?ps = null, string q = null, ComponentQualifiers[] qualifiers = null, string[] s = null, ComponentTreeStrategies?strategy = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(component)]  = component,
                [nameof(asc)]        = BooleanConverter.ToString(asc),
                [nameof(p)]          = p,
                [nameof(ps)]         = ps,
                [nameof(q)]          = q,
                [nameof(qualifiers)] = qualifiers == null ? null : string.Join(",", qualifiers.Select(ComponentQualifiersConverter.ToString)),
                [nameof(s)]          = s == null ? null : string.Join(",", s),
                [nameof(strategy)]   = ComponentTreeStrategiesToStringConverter.ToString(strategy)
            };

            return(await GetComponentsUrl("tree")
                   .SetQueryParams(queryParamValues)
                   .GetJsonAsync <ComponentsTree>()
                   .ConfigureAwait(false));
        }
Exemplo n.º 10
0
        public async Task <User> CreateUserAsync(string login, string name, string email = null, bool?local = null, string password = null, string[] scmAccount = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(login)]      = login,
                [nameof(name)]       = name,
                [nameof(email)]      = email,
                [nameof(local)]      = BooleanConverter.ToString(local),
                [nameof(password)]   = password,
                [nameof(scmAccount)] = scmAccount
            };

            var response = await GetUsersUrl("create")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseFirstNodeAsync <User>(response).ConfigureAwait(false));
        }
Exemplo n.º 11
0
        public async Task <IEnumerable <CeTask> > GetCeActivityAsync(string component = null, DateTime?maxExecutedAt = null, DateTime?minSubmittedAt = null, bool?onlyCurrents = null,
                                                                     int?ps           = null, string q = null, CeTaskStatuses[] status = null, string type = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(component)]      = component,
                [nameof(maxExecutedAt)]  = DateTimeToStringConverter.ToString(maxExecutedAt),
                [nameof(minSubmittedAt)] = DateTimeToStringConverter.ToString(minSubmittedAt),
                [nameof(onlyCurrents)]   = BooleanConverter.ToString(onlyCurrents),
                [nameof(ps)]             = ps,
                [nameof(q)]      = q,
                [nameof(status)] = status == null ? null : string.Join(",", status.Select(CeTaskStatusesConverter.ToString)),
                [nameof(type)]   = type
            };

            return(await GetCeUrl("activity")
                   .SetQueryParams(queryParamValues)
                   .GetJsonFirstNodeAsync <IEnumerable <CeTask> >()
                   .ConfigureAwait(false));
        }
Exemplo n.º 12
0
        public async Task <IEnumerable <Rule> > SearchRulesAsync(bool?activation         = null, Severities[] activeSeverities = null, bool?asc        = null, DateTime?availableSince = null,
                                                                 string[] cwe            = null, AvailableRuleFields[] f       = null, Facets[] facets = null, bool?includeExternal    = null, RuleInheritanceTypes[] inheritance = null, bool?isTemplate = null,
                                                                 string[] languages      = null, OwaspTop10Types[] owaspTop10  = null, int?p           = null, int?ps = null, string q = null, string qprofile = null, string[] repositories = null,
                                                                 string ruleKey          = null, RuleSortFields?s = null, SansTop25Types[] sansTop25   = null, Severities[] severities = null, SonarSourceSecurityTypes[] sonarSourceSecurity = null,
                                                                 RuleStatuses[] statuses = null, string[] tags    = null, string templateKey           = null, IssueTypes[] types      = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(activation)]          = BooleanConverter.ToString(activation),
                ["active_severities"]         = activeSeverities == null ? null : string.Join(",", activeSeverities.Select(SeveritiesConverter.ToString)),
                [nameof(asc)]                 = BooleanConverter.ToString(asc),
                ["available_since"]           = DateTimeToStringConverter.ToString(availableSince, "yyyy-MM-dd"),
                [nameof(cwe)]                 = cwe == null ? null : string.Join(",", cwe),
                [nameof(f)]                   = f == null ? null : string.Join(",", f.Select(AvailableRuleFieldsConverter.ToString)),
                [nameof(facets)]              = facets == null ? null : string.Join(",", facets.Select(FacetsConverter.ToString)),
                ["include_external"]          = BooleanConverter.ToString(includeExternal),
                [nameof(inheritance)]         = inheritance == null ? null : string.Join(",", string.Join(",", inheritance.Select(RuleInheritanceTypesConverter.ToString))),
                ["is_template"]               = BooleanConverter.ToString(isTemplate),
                [nameof(languages)]           = languages == null ? null : string.Join(",", languages),
                [nameof(owaspTop10)]          = owaspTop10 == null ? null : string.Join(",", owaspTop10.Select(OwaspTop10TypesConverter.ToString)),
                [nameof(p)]                   = p,
                [nameof(ps)]                  = ps,
                [nameof(q)]                   = q,
                [nameof(qprofile)]            = qprofile,
                [nameof(repositories)]        = repositories == null ? null : string.Join(",", repositories),
                ["rule_key"]                  = ruleKey,
                [nameof(s)]                   = s == null ? null : RuleSortFieldsConverter.ToString(s),
                [nameof(sansTop25)]           = sansTop25 == null ? null : string.Join(",", sansTop25.Select(SansTop25TypesConverter.ToString)),
                [nameof(severities)]          = severities == null ? null : string.Join(",", severities.Select(SeveritiesConverter.ToString)),
                [nameof(sonarSourceSecurity)] = sonarSourceSecurity == null ? null : string.Join(",", sonarSourceSecurity.Select(SonarSourceSecurityTypesConverter.ToString)),
                [nameof(statuses)]            = statuses == null ? null : string.Join(",", statuses.Select(RuleStatusesConverter.ToString)),
                [nameof(tags)]                = tags == null ? null : string.Join(",", tags),
                ["template_key"]              = templateKey,
                [nameof(types)]               = types == null ? null : string.Join(",", types.Select(IssueTypesConverter.ToString))
            };

            return(await GetRulesUrl("search")
                   .SetQueryParams(queryParamValues)
                   .GetJsonNamedNodeAsync <IEnumerable <Rule> >("rules")
                   .ConfigureAwait(false));
        }
Exemplo n.º 13
0
        public async Task <bool> ActivateQualityProfileRulesAsync(string targetKey, bool?activation = null, Severities[] activeSeverities = null, bool?asc          = null,
                                                                  DateTime?availableSince           = null, string[] cwe = null, RuleInheritanceTypes[] inheritance = null, bool?isTemplate = null, string[] languages = null,
                                                                  OwaspTop10Types[] owaspTop10      = null, string q     = null, string qprofile = null, string[] repositories              = null, string ruleKey = null, RuleSortFields?s = null,
                                                                  SansTop25Types[] sansTop25        = null, Severities[] severities = null, SonarSourceSecurityTypes[] sonarSourceSecurity = null, RuleStatuses[] statuses = null,
                                                                  string[] tags = null, Severities?targetSeverity                   = null, string templateKey = null, IssueTypes[] types = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                [nameof(targetKey)]           = targetKey,
                [nameof(activation)]          = BooleanConverter.ToString(activation),
                ["active_severities"]         = activeSeverities,
                [nameof(asc)]                 = BooleanConverter.ToString(asc),
                ["available_since"]           = DateTimeToStringConverter.ToString(availableSince, "yyyy-MM-dd"),
                [nameof(cwe)]                 = cwe == null ? null : string.Join(",", cwe),
                [nameof(inheritance)]         = inheritance == null ? null : string.Join(",", inheritance.Select(RuleInheritanceTypesConverter.ToString)),
                ["is_template"]               = BooleanConverter.ToString(isTemplate),
                [nameof(languages)]           = languages == null ? null : string.Join(",", languages),
                [nameof(owaspTop10)]          = owaspTop10 == null ? null : string.Join(",", owaspTop10.Select(OwaspTop10TypesConverter.ToString)),
                [nameof(q)]                   = q,
                [nameof(qprofile)]            = qprofile,
                [nameof(repositories)]        = repositories == null ? null : string.Join(",", repositories),
                ["rule_key"]                  = ruleKey,
                [nameof(s)]                   = s == null ? null : string.Join(",", s),
                [nameof(sansTop25)]           = sansTop25 == null ? null : string.Join(",", sansTop25.Select(SansTop25TypesConverter.ToString)),
                [nameof(severities)]          = severities == null ? null : string.Join(",", severities.Select(SeveritiesConverter.ToString)),
                [nameof(sonarSourceSecurity)] = sonarSourceSecurity == null ? null : string.Join(",", sonarSourceSecurity.Select(SonarSourceSecurityTypesConverter.ToString)),
                [nameof(statuses)]            = statuses == null ? null : string.Join(",", statuses.Select(RuleStatusesConverter.ToString)),
                [nameof(tags)]                = tags == null ? null : string.Join(",", tags),
                [nameof(targetSeverity)]      = SeveritiesConverter.ToString(targetSeverity),
                ["template_key"]              = templateKey,
                [nameof(types)]               = types == null ? null : string.Join(",", types.Select(IssueTypesConverter.ToString))
            };

            var response = await GetQualityProfilesUrl("activate_rules")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseAsync(response).ConfigureAwait(false));
        }
Exemplo n.º 14
0
        public async Task <IssueBulkChange> BulkChangeIssuesAsync(string[] addTags = null, string assign       = null, string comment = null, string doTransition = null,
                                                                  string[] issues  = null, string[] removeTags = null, bool?sendNotifications = null, Severities?setSeverity = null, IssueTypes?type = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                ["add_tags"]                = addTags,
                [nameof(assign)]            = assign,
                [nameof(comment)]           = comment,
                ["do_transition"]           = doTransition,
                [nameof(issues)]            = issues == null ? null : string.Join(",", issues),
                ["remove_tags"]             = removeTags,
                [nameof(sendNotifications)] = BooleanConverter.ToString(sendNotifications),
                ["set_severity"]            = setSeverity,
                ["set_type"]                = type == null ? null : IssueTypesConverter.ToString(type)
            };

            var response = await GetIssuesUrl("bulk_change")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseAsync <IssueBulkChange>(response).ConfigureAwait(false));
        }
Exemplo n.º 15
0
        public async Task <Rule> CreateRuleAsync(string customKey, string markdownDescription, string name, IDictionary <string, string> parameters = null, bool?preventReactivation = null,
                                                 Severities?severity = null, RuleStatuses?status = null, string templateKey = null, IssueTypes?type = null)
        {
            var queryParamValues = new Dictionary <string, object>
            {
                ["custom_key"]           = customKey,
                ["markdown_description"] = markdownDescription,
                [nameof(name)]           = name,
                ["params"] = parameters?.Select(x => $"{x.Key}={x.Value}"),
                ["prevent_reactivation"] = BooleanConverter.ToString(preventReactivation),
                [nameof(severity)]       = SeveritiesConverter.ToString(severity),
                [nameof(status)]         = RuleStatusesConverter.ToString(status),
                ["template_key"]         = templateKey,
                [nameof(type)]           = IssueTypesConverter.ToString(type)
            };

            var response = await GetRulesUrl("create")
                           .SetQueryParams(queryParamValues)
                           .PostAsync(s_emptyHttpContent)
                           .ConfigureAwait(false);

            return(await HandleResponseFirstNodeAsync <Rule>(response).ConfigureAwait(false));
        }