sonarqube 1.0.2 → 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 +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +2 -70
- data/lib/sonarqube/client/groups.rb +2 -2
- data/lib/sonarqube/client/permissions.rb +237 -0
- data/lib/sonarqube/client/quality_gates.rb +95 -0
- data/lib/sonarqube/client/tokens.rb +57 -0
- data/lib/sonarqube/client.rb +3 -0
- data/lib/sonarqube/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f97d9312e91b553eececceee3faa5749c597a9410bd897e82d8790b967b6a43
|
4
|
+
data.tar.gz: 7e96a1dd2c6611cf1af13963e622137a84e377ed537230f5a818c98cb26fe737
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c5b2bac929779842c7aee2c666faf33332d259a70ed749a4d7ee4edbaf523979c7f5bed6444586123ff9f09fe12f90a2bb6ca37250d7988318abd98883ed504
|
7
|
+
data.tar.gz: d4001184c48629d9c5c886868f70d42da634d4f279d630745899e20e6be51fae28f350514bc61447f019c236e20ed881588364fa761ae7fdf7287b09bbfc8050
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,30 @@
|
|
4
4
|
|
5
5
|
Please see: https://github.com/psyreactor/sonarqube-ruby/releases
|
6
6
|
|
7
|
+
### 1.2.1 (08/09/2020)
|
8
|
+
|
9
|
+
- Fix
|
10
|
+
* Fix groups parameter validation
|
11
|
+
|
12
|
+
### 1.2.0 (03/09/2020)
|
13
|
+
|
14
|
+
- New features
|
15
|
+
* Added support for permissions API
|
16
|
+
* Added support for premissions internal API
|
17
|
+
- Fix
|
18
|
+
* Fix Coverage
|
19
|
+
* Fix Documentation file name
|
20
|
+
- New
|
21
|
+
* Guard config
|
22
|
+
|
23
|
+
### 1.1.0 (24/08/2020)
|
24
|
+
|
25
|
+
- New features
|
26
|
+
* Added support for users_token API
|
27
|
+
- Fix
|
28
|
+
* Fix Readme
|
29
|
+
* Add site documentation
|
30
|
+
|
7
31
|
### 1.0.2 (24/08/2020)
|
8
32
|
|
9
33
|
- Fix
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://github.com/psyreactor/sonarqube/actions?query=workflow%3ARuby)
|
4
4
|
[](https://inch-ci.org/github/psyreactor/sonarqube)
|
5
|
+
[](https://coveralls.io/github/psyreactor/sonarqube)
|
5
6
|
[](https://rubygems.org/gems/sonarqube)
|
6
7
|
[](https://github.com/psyreactor/sonarqube/blob/master/LICENSE.txt)
|
7
8
|
|
@@ -9,7 +10,7 @@
|
|
9
10
|
[documentation](https://www.rubydoc.info/gems/sonarqube/frames)
|
10
11
|
|
11
12
|
Sonarqube is a Ruby wrapper and CLI for the Sonarqube API
|
12
|
-
As of version `1.
|
13
|
+
As of version `1.2.1` this gem only supports Sonarqube 7.9.
|
13
14
|
|
14
15
|
## Installation
|
15
16
|
|
@@ -88,28 +89,6 @@ project.to_hash
|
|
88
89
|
# => {"project"=>{"key"=>"new_project", "name"=>"new_project", "qualifier"=>"TRK", "visibility"=>"public"}}
|
89
90
|
```
|
90
91
|
|
91
|
-
#### Delete Project
|
92
|
-
```ruby
|
93
|
-
project = Sonarqube.project_delete('test')
|
94
|
-
# => #<Sonarqube::ObjectifiedHash:46220 {hash: {}}
|
95
|
-
project.to_hash.empty?
|
96
|
-
# => true
|
97
|
-
```
|
98
|
-
|
99
|
-
#### Search Project
|
100
|
-
```ruby
|
101
|
-
projects = Sonarqube.project_search()
|
102
|
-
# => #<Sonarqube::ObjectifiedHash:46240 {hash: {"paging"=>{"pageIndex"=>1, "pageSize"=>100, "total"=>2}, "components"=>[{"organization"=>"default-organization", "key"=>"old_key", "name"=>"new_proyect", "qualifier"=>"TRK", "visibility"=>"private"}, {"organization"=>"default-organization", "key"=>"test", "name"=>"test", "qualifier"=>"TRK", "visibility"=>"public"}]}}
|
103
|
-
projects.components.each do | project |
|
104
|
-
puts "name: #{project.name}"
|
105
|
-
puts "key: #{project.key}"
|
106
|
-
end
|
107
|
-
# name: new_proyect
|
108
|
-
# key: old_key
|
109
|
-
# name: test
|
110
|
-
# key: test
|
111
|
-
```
|
112
|
-
|
113
92
|
### Users
|
114
93
|
|
115
94
|
#### Create User
|
@@ -122,56 +101,9 @@ user.user.name
|
|
122
101
|
# name_user
|
123
102
|
```
|
124
103
|
|
125
|
-
#### Delete User
|
126
|
-
```ruby
|
127
|
-
user = Sonarqube.user_delete('test')
|
128
|
-
# => #<Sonarqube::ObjectifiedHash:46220 {hash: {}}
|
129
|
-
user.to_hash.empty?
|
130
|
-
# => true
|
131
|
-
```
|
132
|
-
|
133
|
-
#### Search User
|
134
|
-
```ruby
|
135
|
-
users = Sonarqube.users_search()
|
136
|
-
# => #<Sonarqube::ObjectifiedHash:46340 {hash: {"paging"=>{"pageIndex"=>1, "pageSize"=>50, "total"=>5}, "users"=>[{"login"=>"admin", "name"=>"Administrator", "active"=>true, "groups"=>["sonar-administrators", "sonar-users"], "tokensCount"=>1, "local"=>true, "externalIdentity"=>"admin", "externalProvider"=>"sonarqube", "lastConnectionDate"=>"2020-08-22T23:09:14+0000"}, {"login"=>"new_user", "name"=>"key_new_user", "active"=>true, "groups"=>["sonar-users"], "tokensCount"=>0, "local"=>true, "externalIdentity"=>"new_user", "externalProvider"=>"sonarqube"}, {"login"=>"login_name", "name"=>"name_user", "active"=>true, "groups"=>["sonar-users"], "tokensCount"=>0, "local"=>true, "externalIdentity"=>"login_name", "externalProvider"=>"sonarqube"}, {"login"=>"test3", "name"=>"test QA", "active"=>true, "groups"=>["sonar-users"], "tokensCount"=>0, "local"=>true, "externalIdentity"=>"test3", "externalProvider"=>"sonarqube"}, {"login"=>"newlogin", "name"=>"test QA", "active"=>true, "groups"=>["sonar-users"], "tokensCount"=>0, "local"=>true, "externalIdentity"=>"newlogin", "externalProvider"=>"sonarqube"}]}}
|
137
|
-
users.users.each do | user |
|
138
|
-
puts "name: #{user.name}"
|
139
|
-
puts "login: #{user.login}"
|
140
|
-
puts "lastConection: #{user.lastConnectionDate}" if defined? user.lastConnectionDate
|
141
|
-
end
|
142
|
-
# name: Administrator
|
143
|
-
# login: admin
|
144
|
-
# lastConection: 2020-08-22T23:09:14+0000
|
145
|
-
# name: key_new_user
|
146
|
-
# login: new_user
|
147
|
-
# name: name_user
|
148
|
-
# login: login_name
|
149
|
-
# name: test QA
|
150
|
-
# login: test3
|
151
|
-
# name: test QA
|
152
|
-
# login: newlogin
|
153
|
-
```
|
154
104
|
|
155
105
|
### Groups
|
156
106
|
|
157
|
-
#### Create Group
|
158
|
-
```ruby
|
159
|
-
group = Sonarqube.create_group('New-Group', {description: 'Sonarqube group users'})
|
160
|
-
# => #<Sonarqube::ObjectifiedHash:46500 {hash: {"group"=>{"uuid"=>"AXQYrrgCsrvdoo0YodNM", "organization"=>"default-organization", "name"=>"New-Group", "description"=>"Sonarqube group users", "membersCount"=>0, "default"=>false}}}
|
161
|
-
group.group.uuid
|
162
|
-
# AXQYrrgCsrvdoo0YodNM
|
163
|
-
group.group.description
|
164
|
-
# Sonarqube group users
|
165
|
-
```
|
166
|
-
|
167
|
-
#### Delete Group
|
168
|
-
```ruby
|
169
|
-
group = Sonarqube.group_delete('New-Group')
|
170
|
-
# => #<Sonarqube::ObjectifiedHash:46220 {hash: {}}
|
171
|
-
group.to_hash.empty?
|
172
|
-
# => true
|
173
|
-
```
|
174
|
-
|
175
107
|
#### Search Group
|
176
108
|
```ruby
|
177
109
|
groups = Sonarqube.search_groups({ q: 'sonar-users' })
|
@@ -79,7 +79,7 @@ class Sonarqube::Client
|
|
79
79
|
# @option options [String] :name Optional name of group.
|
80
80
|
# @return [Sonarqube::ObjectifiedHash]
|
81
81
|
def add_member(id = nil, login = nil, options = {})
|
82
|
-
raise ArgumentError, 'Missing required parameters' if id.nil?
|
82
|
+
raise ArgumentError, 'Missing required parameters' if id.nil? && login.nil?
|
83
83
|
|
84
84
|
post('/api/user_groups/add_user', body: { id: id, login: login }.merge!(options))
|
85
85
|
end
|
@@ -97,7 +97,7 @@ class Sonarqube::Client
|
|
97
97
|
# @option options [String] :name Optional name of group.
|
98
98
|
# @return [Sonarqube::ObjectifiedHash]
|
99
99
|
def remove_member(id = nil, login = nil, options = {})
|
100
|
-
raise ArgumentError, 'Missing required parameters' if id.nil?
|
100
|
+
raise ArgumentError, 'Missing required parameters' if id.nil? && login.nil?
|
101
101
|
|
102
102
|
post('/api/user_groups/remove_user', body: { id: id, login: login }.merge!(options))
|
103
103
|
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Sonarqube::Client
|
4
|
+
# Defines methods related to permissions.
|
5
|
+
# @see https://SONAR_URL/web_api/api/permissions
|
6
|
+
module Permissions
|
7
|
+
# Add permission to a group.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# Sonarqube.permissions_add_group({ groupName: 'New-Group', permission: 'user', projectKey: 'test' })
|
11
|
+
#
|
12
|
+
# @param [Hash] options A customizable set of options.
|
13
|
+
# @option options [String] :groupId Id of group.
|
14
|
+
# @option options [String] :groupName Name of group.
|
15
|
+
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
16
|
+
# @option options [String] :projectId Id of project, only apply for project permissions.
|
17
|
+
# @option options [String] :projectKey Key of project, only apply for project permissions.
|
18
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_group}
|
19
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
20
|
+
def permission_add_group(options = {})
|
21
|
+
options.transform_keys(&:to_sym)
|
22
|
+
raise ArgumentError, 'Missing required parameters' if options[:groupId].nil? && options[:groupName].nil?
|
23
|
+
|
24
|
+
post('/api/permissions/add_group', body: options)
|
25
|
+
end
|
26
|
+
alias add_group_permission permission_add_group
|
27
|
+
|
28
|
+
# Add group to template.
|
29
|
+
#
|
30
|
+
# @example
|
31
|
+
# Sonarqube.add_group_to_template({ groupName: 'New-Group', permission: 'user', templateName: 'test' })
|
32
|
+
#
|
33
|
+
# @param [Hash] options A customizable set of options.
|
34
|
+
# @option options [String] :groupId Id of group.
|
35
|
+
# @option options [String] :groupName Name of group.
|
36
|
+
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
37
|
+
# @option options [String] :templateId Id of template.
|
38
|
+
# @option options [String] :templateName Name of template.
|
39
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_group_to_template}
|
40
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
41
|
+
def add_group_to_template(options = {})
|
42
|
+
options.transform_keys(&:to_sym)
|
43
|
+
raise ArgumentError, 'Missing required parameters' if options[:groupId].nil? && options[:groupName].nil?
|
44
|
+
|
45
|
+
post('/api/permissions/add_group_to_template', body: options)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Add project creator to template.
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# Sonarqube.add_project_creator_to_template('issueadmin', { templateName: 'test' })
|
52
|
+
#
|
53
|
+
# @param [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
54
|
+
# @param [Hash] options A customizable set of options.
|
55
|
+
# @option options [String] :templateId Id of template.
|
56
|
+
# @option options [String] :templateName Name of template.
|
57
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_project_creator_to_template}
|
58
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
59
|
+
def add_project_creator_to_template(permission, options = {})
|
60
|
+
raise ArgumentError, 'Missing required parameters' if permission.nil?
|
61
|
+
|
62
|
+
post('/api/permissions/add_project_creator_to_template', body: { permission: permission }.merge!(options))
|
63
|
+
end
|
64
|
+
|
65
|
+
# Add permissions to user.
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
# Sonarqube.permission_add_user('new_user', 'issueadmin', { projectKey: 'test' })
|
69
|
+
#
|
70
|
+
# @param [String] :login Name of login user.
|
71
|
+
# @param [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
72
|
+
# @param [Hash] options A customizable set of options.
|
73
|
+
# @option options [String] :projectId Id of project, only apply for project permissions.
|
74
|
+
# @option options [String] :projectKey Key of project, only apply for project permissions.
|
75
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_user}
|
76
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
77
|
+
def permission_add_user(login, permission, options = {})
|
78
|
+
options.transform_keys(&:to_sym)
|
79
|
+
raise ArgumentError, 'Missing required parameters' if login.nil? && permission.nil?
|
80
|
+
|
81
|
+
body = { login: login, permission: permission }.merge!(options)
|
82
|
+
post('/api/permissions/add_user', body: body)
|
83
|
+
end
|
84
|
+
alias add_user_permission permission_add_user
|
85
|
+
|
86
|
+
# Add user to template.
|
87
|
+
#
|
88
|
+
# @example
|
89
|
+
# Sonarqube.add_user_to_template({ 'new_user', 'issueadmin', { templateName: 'test' })
|
90
|
+
#
|
91
|
+
# @param [String] :login Name of login user.
|
92
|
+
# @param [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user.
|
93
|
+
# @param [Hash] options A customizable set of options.
|
94
|
+
# @option options [String] :templateId Id of template.
|
95
|
+
# @option options [String] :templateName Name of template.
|
96
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/add_user_to_template}
|
97
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
98
|
+
def add_user_to_template(login, permission, options = {})
|
99
|
+
options.transform_keys(&:to_sym)
|
100
|
+
raise ArgumentError, 'Missing required parameters' if login.nil? && permission.nil?
|
101
|
+
|
102
|
+
body = { login: login, permission: permission }.merge!(options)
|
103
|
+
post('/api/permissions/add_user_to_template', body: body)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Apply template.
|
107
|
+
#
|
108
|
+
# @example
|
109
|
+
# Sonarqube.apply_template({ projectName: 'New-Group', templateName: 'test' })
|
110
|
+
#
|
111
|
+
# @param [Hash] options A customizable set of options.
|
112
|
+
# @option options [String] :projectId Id of group.
|
113
|
+
# @option options [String] :projectName Name of group.
|
114
|
+
# @option options [String] :templateId Id of template.
|
115
|
+
# @option options [String] :templateName Name of template.
|
116
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/apply_template}
|
117
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
118
|
+
def apply_template(options = {})
|
119
|
+
options.transform_keys(&:to_sym)
|
120
|
+
|
121
|
+
post('/api/permissions/apply_template', body: options)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Bulk apply template.
|
125
|
+
#
|
126
|
+
# @example
|
127
|
+
# Sonarqube.bulk_apply_template({ templateName: 'test', projects: 'my_project,another_project' })
|
128
|
+
#
|
129
|
+
# @param [Hash] options A customizable set of options.
|
130
|
+
# @option options [String] :analyzedBefore Filter the projects for which last analysis is older than the given date .
|
131
|
+
# @option options [String] :onProvisionedOnly Filter the projects that are provisioned.
|
132
|
+
# @option options [String] :projects Comma-separated list of project keys maximum 1000
|
133
|
+
# @option options [String] :q serach project names that contain the supplied string and project keys that are exactly the same as the supplied string
|
134
|
+
# @option options [String] :qualifiers Comma-separated list of component qualifiers. Filter the results with the specified qualifiers.
|
135
|
+
# @option options [String] :templateId Id of template.
|
136
|
+
# @option options [String] :templateName Name of template.
|
137
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/bulk_apply_template}
|
138
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
139
|
+
def bulk_apply_template(options = {})
|
140
|
+
options.transform_keys(&:to_sym)
|
141
|
+
|
142
|
+
post('/api/permissions/bulk_apply_template', body: options)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Create template.
|
146
|
+
#
|
147
|
+
# @example
|
148
|
+
# Sonarqube.create_template('template_name', 'description', '.*\.finance\..*')
|
149
|
+
#
|
150
|
+
# @param [String] :name Name of template.
|
151
|
+
# @param [String] :project_key_pattern Project key pattern. Must be a valid Java regular expression.
|
152
|
+
# @param [String] :description Description of template.
|
153
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/create_template}
|
154
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
155
|
+
def create_template(name, description, project_key_pattern)
|
156
|
+
body = { name: name, description: description, projectKeyPattern: project_key_pattern }
|
157
|
+
post('/api/permissions/create_template', body: body)
|
158
|
+
end
|
159
|
+
|
160
|
+
# Delete template.
|
161
|
+
#
|
162
|
+
# @example
|
163
|
+
# Sonarqube.create_template({ templateName: 'template_name' })
|
164
|
+
#
|
165
|
+
# @param [Hash] options A customizable set of options.
|
166
|
+
# @option options [String] :templateId Id of template.
|
167
|
+
# @option options [String] :templateName Name of template.
|
168
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/delete_template}
|
169
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
170
|
+
def delete_template(options = {})
|
171
|
+
options.transform_keys(&:to_sym)
|
172
|
+
raise ArgumentError, 'Missing required parameters' if options[:templateName].nil? && options[:templateId].nil?
|
173
|
+
|
174
|
+
post('/api/permissions/delete_template', body: options)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Remove permission to a group.
|
178
|
+
#
|
179
|
+
# @example
|
180
|
+
# Sonarqube.permissions_add_group({ groupName: 'New-Group', permission: permission, projectKey: 'test' })
|
181
|
+
#
|
182
|
+
# @param [Hash] options A customizable set of options.
|
183
|
+
# @option options [String] :groupId Id of group.
|
184
|
+
# @option options [String] :groupName Name of group.
|
185
|
+
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
186
|
+
# @option options [String] :projectId Id of project, only apply for project permissions.
|
187
|
+
# @option options [String] :projectKey Key of project, only apply for project permissions.
|
188
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/remove_group}
|
189
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
190
|
+
def permission_remove_group(options = {})
|
191
|
+
options.transform_keys(&:to_sym)
|
192
|
+
raise ArgumentError, 'Missing required parameters' if options[:groupId].nil? && options[:groupName].nil?
|
193
|
+
|
194
|
+
post('/api/permissions/remove_group', body: options)
|
195
|
+
end
|
196
|
+
alias remove_group_permission permission_remove_group
|
197
|
+
|
198
|
+
# Remove group from template.
|
199
|
+
#
|
200
|
+
# @example
|
201
|
+
# Sonarqube.remove_group_from_template({ groupName: 'New-Group', permission: 'permission', templateId: 'test' })
|
202
|
+
#
|
203
|
+
# @param [Hash] options A customizable set of options.
|
204
|
+
# @option options [String] :groupId Id of group.
|
205
|
+
# @option options [String] :groupName Name of group.
|
206
|
+
# @option options [String] :permission Permission to asing to group. global permissions: admin, profileadmin, gateadmin, scan, provisioning | project permissions: admin, codeviewer, issueadmin, securityhotspotadmin, scan, user
|
207
|
+
# @option options [String] :TemplateId Id of template.
|
208
|
+
# @option options [String] :TemplateName Name of template.
|
209
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/remove_group_from_template}
|
210
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
211
|
+
def remove_group_from_template(options = {})
|
212
|
+
post('/api/permissions/remove_group_from_template', body: options)
|
213
|
+
end
|
214
|
+
|
215
|
+
# Lists the groups with their permissions
|
216
|
+
#
|
217
|
+
# @example
|
218
|
+
# Sonarqube.permission_list_group({ q: 'test', projectsKey: 'project' })
|
219
|
+
#
|
220
|
+
# @param [Hash] options A customizable set of options.
|
221
|
+
# @option options [String] :organization Key of organization, used when group name is set
|
222
|
+
# @option options [String] :p 1-based page number.
|
223
|
+
# @option options [String] :permission Possible values for global permissions or values for project permissions.
|
224
|
+
# @option options [String] :q Limit search to group names that contain the supplied string.
|
225
|
+
# @option options [String] :ps Page size. Must be greater than 0 and less or equal than 100
|
226
|
+
# @option options [String] :projectId Id of project.
|
227
|
+
# @option options [String] :projectKey Key of project.
|
228
|
+
# (Any provided options will be passed to Sonarqube. See {https://SONAR_URL/web_api/api/permissions/groups?internal=true}
|
229
|
+
# @return [<Sonarqube::ObjectifiedHash>]
|
230
|
+
def permission_list_group(options = {})
|
231
|
+
options.transform_keys(&:to_sym)
|
232
|
+
|
233
|
+
get('/api/permissions/groups', quey: options)
|
234
|
+
end
|
235
|
+
alias list_group_permission permission_list_group
|
236
|
+
end
|
237
|
+
end
|
@@ -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
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Sonarqube::Client
|
4
|
+
# Defines methods related to tokens.
|
5
|
+
# @see https://SONAR_URL/web_api/api/user_tokens
|
6
|
+
module Tokens
|
7
|
+
# Create token for user.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# Sonarqube.create_token('name_token')
|
11
|
+
# Sonarqube.create_token('name_token', 'login_name')
|
12
|
+
#
|
13
|
+
# @param [String] name (required) Token name.
|
14
|
+
# @param [String] login (optional) Login user name.
|
15
|
+
# @return [Sonarqube::ObjectifiedHash]
|
16
|
+
def create_token(name, login = nil)
|
17
|
+
raise ArgumentError, 'Missing required parameters' if name.nil?
|
18
|
+
|
19
|
+
body = { name: name }
|
20
|
+
body = { login: login }.merge!(body) unless login.nil?
|
21
|
+
post('/api/user_tokens/generate', body: body)
|
22
|
+
end
|
23
|
+
alias token_create create_token
|
24
|
+
|
25
|
+
# Revoke a token.
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# Sonarqube.revoke_token('new-group')
|
29
|
+
# Sonarqube.revoke_token('sonarqube', { description: 'New Sonarqube project' })
|
30
|
+
#
|
31
|
+
# @param [String] name (required) Token name.
|
32
|
+
# @param [String] login (optional) Login user name.
|
33
|
+
# @return [Sonarqube::ObjectifiedHash] Empty hash response.
|
34
|
+
def revoke_token(name, login = nil)
|
35
|
+
raise ArgumentError, 'Missing required parameters' if name.nil?
|
36
|
+
|
37
|
+
body = { name: name }
|
38
|
+
body = { login: login }.merge!(body) unless login.nil?
|
39
|
+
post('/api/user_tokens/revoke', body: body)
|
40
|
+
end
|
41
|
+
alias token_revoke revoke_token
|
42
|
+
|
43
|
+
# List token for user.
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
# Sonarqube.list_token('login')
|
47
|
+
#
|
48
|
+
# @param [String] login (required) The login name of user
|
49
|
+
# @return [Sonarqube::ObjectifiedHash].
|
50
|
+
def list_tokens(login)
|
51
|
+
raise ArgumentError, 'Missing required parameters' if login.nil?
|
52
|
+
|
53
|
+
get('/api/user_tokens/search', query: { login: login })
|
54
|
+
end
|
55
|
+
alias tokens_list list_tokens
|
56
|
+
end
|
57
|
+
end
|
data/lib/sonarqube/client.rb
CHANGED
data/lib/sonarqube/version.rb
CHANGED
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.0
|
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:
|
11
|
+
date: 2021-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -106,7 +106,10 @@ files:
|
|
106
106
|
- lib/sonarqube/api.rb
|
107
107
|
- lib/sonarqube/client.rb
|
108
108
|
- lib/sonarqube/client/groups.rb
|
109
|
+
- lib/sonarqube/client/permissions.rb
|
109
110
|
- lib/sonarqube/client/projects.rb
|
111
|
+
- lib/sonarqube/client/quality_gates.rb
|
112
|
+
- lib/sonarqube/client/tokens.rb
|
110
113
|
- lib/sonarqube/client/users.rb
|
111
114
|
- lib/sonarqube/configuration.rb
|
112
115
|
- lib/sonarqube/error.rb
|
@@ -132,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
135
|
- !ruby/object:Gem::Version
|
133
136
|
version: '0'
|
134
137
|
requirements: []
|
135
|
-
rubygems_version: 3.1.
|
138
|
+
rubygems_version: 3.1.6
|
136
139
|
signing_key:
|
137
140
|
specification_version: 4
|
138
141
|
summary: A Ruby wrapper for the Sonarqube API
|