sonarqube 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 801fefe171e320dd14316a7c77780e29fcd1d48a42d0a72d95c82963dad8c295
4
- data.tar.gz: 225697afc310666c0be1f710ed4be1f84d6e8fb16c2eddb66a19b170f279a74c
3
+ metadata.gz: 0f97d9312e91b553eececceee3faa5749c597a9410bd897e82d8790b967b6a43
4
+ data.tar.gz: 7e96a1dd2c6611cf1af13963e622137a84e377ed537230f5a818c98cb26fe737
5
5
  SHA512:
6
- metadata.gz: f925f8ec8136457b91748054cf76a03a315187f0d7145163573821f8c5d2ab1d13c13f30e2afe0280f83e6fe4232c5fccd40e10803a03f86bcb44f66a4d061fb
7
- data.tar.gz: 432d2e44abb168f23bc425c5e673edbea93bc06f55addd0a05863c734e5d2d4a5f1db812ea3c66595d2c46c5079d126c9b532099eca4892bd1789393af02dc8d
6
+ metadata.gz: 7c5b2bac929779842c7aee2c666faf33332d259a70ed749a4d7ee4edbaf523979c7f5bed6444586123ff9f09fe12f90a2bb6ca37250d7988318abd98883ed504
7
+ data.tar.gz: d4001184c48629d9c5c886868f70d42da634d4f279d630745899e20e6be51fae28f350514bc61447f019c236e20ed881588364fa761ae7fdf7287b09bbfc8050
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Sonarqube::Client
4
+ # Defines methods related to tokens.
5
+ # @see https://SONAR_URL/web_api/api/qualitygates
6
+ module QualityGates
7
+ ALLOWED_OPERATORS = %w[LT GT].freeze
8
+ ALLOWED_METRICS = %w[
9
+ coverage new_coverage duplicated_lines_density
10
+ new_duplicated_lines_density reliability_rating new_reliability_rating
11
+ maintainability_rating new_maintainability_rating
12
+ ].freeze
13
+ # Create new quality gate.
14
+ #
15
+ # @example
16
+ # Sonarqube.create_quality_gate('name_quality_gate')
17
+ #
18
+ # # Gracefully continue if gate already exists
19
+ # begin
20
+ # Sonarqube.create_quality_gate('name_quality_gate')
21
+ # rescue Sonarqube::Error::BadRequest => error
22
+ # raise unless error.message =~ /Name has already been taken/
23
+ # end
24
+ #
25
+ # @param [String] name (required) Quality Gate name.
26
+ # @return [Sonarqube::ObjectifiedHash]
27
+ def create_quality_gate(name)
28
+ raise ArgumentError, 'Missing required parameters' if name.nil?
29
+
30
+ body = { name: name }
31
+ post('/api/qualitygates/create', body: body)
32
+ end
33
+ alias quality_gate_create create_quality_gate
34
+
35
+ # Create condition for a quality gate.
36
+ #
37
+ # @example
38
+ # # Create a condition that errors when coverage is below 90%
39
+ # Sonarqube.create_quality_gate_condition('name_quality_gate', 'coverage', '90')
40
+ #
41
+ # # Create a condition that errors when code duplication is > 3%
42
+ # Sonarqube.create_quality_gate_condition('name_quality_gate', 'duplicated_lines_density',
43
+ # '3', 'GT')
44
+ #
45
+ # @param [String] name (required) Quality Gate name.
46
+ # @param [String] metric (required) SonarQube metric name.
47
+ # @param [String] error_threshold (required) Error threshold value
48
+ # @param [String] operator (required) Operator - LT for <; GT for >
49
+ # @return [Sonarqube::ObjectifiedHash]
50
+ def create_quality_gate_condition(name, metric, error_threshold, operator = 'LT')
51
+ raise ArgumentError, 'Missing required parameters' if name.nil? || metric.nil? || error_threshold.nil?
52
+ unless ALLOWED_OPERATORS.include?(operator)
53
+ raise ArgumentError, "Operator must be in #{ALLOWED_OPERATORS.join(', ')}"
54
+ end
55
+ raise ArgumentError, "Metric must be in #{ALLOWED_METRICS.join(', ')}" unless ALLOWED_METRICS.include?(metric)
56
+
57
+ body = {
58
+ gateName: name,
59
+ metric: metric,
60
+ error: error_threshold,
61
+ op: operator
62
+ }
63
+ post('/api/qualitygates/create_condition', body: body)
64
+ end
65
+ alias quality_gate_condition_create create_quality_gate_condition
66
+
67
+ # Set the default quality gate.
68
+ #
69
+ # @example
70
+ # Sonarqube.set_default_quality_gate('name_quality_gate')
71
+ #
72
+ # @param [String] name (required) Quality Gate name.
73
+ # @return [Sonarqube::ObjectifiedHash]
74
+ # rubocop:disable Naming/AccessorMethodName
75
+ def set_default_quality_gate(name)
76
+ raise ArgumentError, 'Missing required parameters' if name.nil?
77
+
78
+ body = { name: name }
79
+ post('/api/qualitygates/set_as_default', body: body)
80
+ end
81
+ # rubocop:enable Naming/AccessorMethodName
82
+ alias default_quality_gate_set set_default_quality_gate
83
+
84
+ # List quality gates.
85
+ #
86
+ # @example
87
+ # Sonarqube.list_quality_gates
88
+ #
89
+ # @return [Sonarqube::ObjectifiedHash].
90
+ def list_quality_gates
91
+ get('/api/qualitygates/list')
92
+ end
93
+ alias quality_gates_list list_quality_gates
94
+ end
95
+ end
@@ -9,6 +9,7 @@ module Sonarqube
9
9
  include Groups
10
10
  include Permissions
11
11
  include Projects
12
+ include QualityGates
12
13
  include Tokens
13
14
  include Users
14
15
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sonarqube
4
- VERSION = '1.2.1'
4
+ VERSION = '1.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sonarqube
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mariani Lucas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-08 00:00:00.000000000 Z
11
+ date: 2021-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -108,6 +108,7 @@ files:
108
108
  - lib/sonarqube/client/groups.rb
109
109
  - lib/sonarqube/client/permissions.rb
110
110
  - lib/sonarqube/client/projects.rb
111
+ - lib/sonarqube/client/quality_gates.rb
111
112
  - lib/sonarqube/client/tokens.rb
112
113
  - lib/sonarqube/client/users.rb
113
114
  - lib/sonarqube/configuration.rb
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  - !ruby/object:Gem::Version
135
136
  version: '0'
136
137
  requirements: []
137
- rubygems_version: 3.1.2
138
+ rubygems_version: 3.1.6
138
139
  signing_key:
139
140
  specification_version: 4
140
141
  summary: A Ruby wrapper for the Sonarqube API