sonarqube-client 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e5c848304338dee76e0a4b1b08c46efdc7c3061
4
+ data.tar.gz: ce4957d40b5a6eaaf651d3c9edf0deefc2d4df71
5
+ SHA512:
6
+ metadata.gz: 66ae5d99b34c55cdb05c6e70bf74601268de8cdd570ad9adb8c933bbddc72b53cf9f890ca2080b681b40abfcaf73f88f91b16091c62489d5caf676dc6c2dc545
7
+ data.tar.gz: 8662428d509991e30ca8bb1c7a262866674c4caa26cf67146f7323e93b5f8c4fc0fe185a7875f9ec390ed8f68be36a8cbc00dbcd4197b544228eb4ca7eccc04e
@@ -0,0 +1,84 @@
1
+ # Copyright (C) 2016 Dimitrios Dimas <dimitrios.work@outlook.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU General Public License
5
+ # as published by the Free Software Foundation; either version 2
6
+ # of the License, or (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
+
17
+
18
+ require 'rest-client'
19
+ require 'nokogiri'
20
+ require 'json'
21
+ require 'logger'
22
+
23
+ require File.dirname(__FILE__) + '/sonarqube/client.rb'
24
+ require File.dirname(__FILE__) + '/sonarqube/issues.rb'
25
+ require File.dirname(__FILE__) + '/sonarqube/logger.rb'
26
+ require File.dirname(__FILE__) + '/sonarqube/projects.rb'
27
+ require File.dirname(__FILE__) + '/sonarqube/timemachine.rb'
28
+ require File.dirname(__FILE__) + '/sonarqube/version.rb'
29
+
30
+
31
+
32
+
33
+
34
+ module SonarQube
35
+
36
+ #@@logger=SonarQube::Logger::Logger.new
37
+
38
+
39
+ class SonarQube
40
+ def initialize server_url, username='', password=''
41
+ if [username, password].reduce(:+) == ''
42
+ @connector=RestClient::Resource.new(server_url)
43
+ else
44
+ @connector=RestClient::Resource.new(server_url, username, password)
45
+ end
46
+ end
47
+
48
+ #Returns a timemachine object, can also be used to invoke timemachine methods without having to explicitly initialize/store an object
49
+ # @example my_tm = SonarQube.timemachine
50
+ # or if we don't want a persistent object:
51
+ # @example puts \"coverage for my project is: \#\\{SonarQube.timemachine.get(my_awesome_project, coverage)\}\"
52
+ # @return [TimeMachine::TimeMachine]
53
+ def timemachine
54
+ TimeMachine::TimeMachine.new(@connector)
55
+ end
56
+
57
+ #Returns a projects object, can also be used to invoke projects methods without having to explicitly initialize/store an object
58
+ # @example my_proj = SonarQube.projects
59
+ # or if we don't want a persistent object:
60
+ # @example puts \"available projects are: \#\\{SonarQube.projects.list\}\"
61
+ # @return [TimeMachine::TimeMachine]
62
+ def projects
63
+ Projects::Projects.new(@connector)
64
+ end
65
+
66
+ #Returns an issues object, can also be used to invoke issues methods without having to explicitly initialize/store an object
67
+ # @example issues = SonarQube.issues
68
+ # or if we don't want a persistent object:
69
+ # @example puts \"the list with all the issues is: \#\\{SonarQube.issues.get\}\"
70
+ # @return [TimeMachine::TimeMachine]
71
+ def issues
72
+ Issues::Issues.new(@connector)
73
+ end
74
+ end
75
+
76
+ def sonarqube(server_url, username='', password='')
77
+ if [username, password].reduce(:+) == ''
78
+ proc {|endpoint| RestClient::Resource.new server_url + endpoint}.curry
79
+ else
80
+ proc {|endpoint| RestClient::Resource.new server_url + endpoint, a, b}.curry
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,32 @@
1
+ # Copyright (C) 2016 Dimitrios Dimas <dimitrios.work@outlook.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU General Public License
5
+ # as published by the Free Software Foundation; either version 2
6
+ # of the License, or (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
+
17
+ module SonarQube
18
+ module Client
19
+
20
+ def connect(server_url, username='', password='')
21
+ RestClient::Resource.new(server_url, username, password)
22
+ end
23
+
24
+ def initialize(server_url, username='', password='')
25
+ if username + password == ''
26
+ proc {|endpoint| RestClient::Resource.new server_url+endpoint}.curry
27
+ else
28
+ proc {|endpoint| RestClient::Resource.new server_url+endpoint, a, b}.curry
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,113 @@
1
+ # Copyright (C) 2016 Dimitrios Dimas <dimitrios.work@outlook.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU General Public License
5
+ # as published by the Free Software Foundation; either version 2
6
+ # of the License, or (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
+
17
+ module SonarQube
18
+ module Issues
19
+
20
+ class Issues
21
+ @@endpoint='api/issues/'
22
+
23
+ #Constructor
24
+ #
25
+ # @param [RestClient::Resource] connector The rest-client resource object
26
+ #
27
+ def initialize connector
28
+ @connector=connector
29
+ end
30
+
31
+ #Search for issues by name
32
+ #
33
+ # @param names The key or keys (comma-separated list) to be used in the search
34
+ # @return A JSON object, containing all the issues found.
35
+ #
36
+ def search_by_name names
37
+ JSON.parse(@connector[@@endpoint + "search?componentKeys=#{names}"].get)
38
+ end
39
+
40
+ #Search for issues older than a date/datetime
41
+ #
42
+ # @param [String] date A string representation of a date or datetime in ISO
43
+ # format (example: 2015-01-01 or 2015-01-01T11:01:01+0100)
44
+ # @return A JSON object, containing all the issues created after the given date.
45
+ #
46
+ def older_than date
47
+ JSON.parse(@connector[@@endpoint + "search?createdBefore=#{date}"].get)
48
+ end
49
+
50
+ #Returns all issues created between the current date/time and the amount of days/time provided
51
+ #
52
+ # @param [String] date A string representation of a date or datetime in ISO
53
+ # format, that specifies how far back from the current date/time we want
54
+ # to look for new issues (example: 2015-01-01 or 2015-01-01T11:01:01+0100)
55
+ # @return [JSON] A JSON object, containing all the issues created in the previous time/days specified.
56
+ #
57
+ def in_past date
58
+ JSON.parse(@connector[@@endpoint + "search?createdInLast=#{date}"].get)
59
+ end
60
+
61
+ #Add a comment to an issue
62
+ #
63
+ # @param [String] key The issue key
64
+ # @param [String] comment (optional, the default value is an empty string) The comment we want to add.
65
+ # @return [JSON] A JSON object, containing all the issues.
66
+ #
67
+ def add_comment key, comment=''
68
+ JSON.parse(@connector[@@endpoint + "add_comment?format=json,issue=#{key},text=#{comment}"].get)
69
+ end
70
+
71
+ #Assigns an issue to a user
72
+ #
73
+ # @param [String] issue The issue key
74
+ # @param [String] username The username (login) of the assignee
75
+ # @return [A JSON object, containing all the issues.
76
+ #
77
+ def assign issue, username=''
78
+ JSON.parse(@connector[@@endpoint + "assign?issue=#{issue},assignee=#{username}"].get)
79
+ end
80
+
81
+ #Returns scm users (usernames or emails) that have authored code with issues
82
+ #
83
+ # @param [String] search_string A string that will be used to search (regex match equivalent to /.\*search_string.\*/) for
84
+ # authors usernames or emails (e.g. for git it'll be used to search for what's configured in user.name or user.email).
85
+ # @return [JSON] A JSON object, containing all the authors.
86
+ #
87
+ def get_committers search_string
88
+ JSON.parse(@connector[@@endpoint + "authors?ps=2147483647&q=#{search_string}"].get)
89
+ end
90
+
91
+ #Returns the changelog of an issue
92
+ #
93
+ # @param [String] key The issue key.
94
+ # @return [JSON] A JSON object, containing all the changelog.
95
+ #
96
+ def changelog key
97
+ JSON.parse(@connector[@@endpoint + "changelog?format=json,issue=#{key}"].get)
98
+ end
99
+
100
+ #Returns all issues
101
+ #
102
+ # @return [JSON] A JSON object, containing all the issues.
103
+ #
104
+ def get
105
+ JSON.parse(@connector[@@endpoint + 'search'].get)
106
+ end
107
+
108
+ def search_by_name names
109
+
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (C) 2016 Dimitrios Dimas <dimitrios.work@outlook.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU General Public License
5
+ # as published by the Free Software Foundation; either version 2
6
+ # of the License, or (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
+
17
+ module SonarQube
18
+ class Logger
19
+
20
+ def self.log(*args, level)
21
+ @@logger=Logger.new *args
22
+ @@logger.level loglevel level
23
+ end
24
+
25
+ def loglevel(level)
26
+ case level
27
+ when 'debug'
28
+ return 0
29
+ when 'info'
30
+ return 1
31
+ when 'warn'
32
+ return 2
33
+ when 'error'
34
+ return 3
35
+ when 'fatal'
36
+ return 4
37
+ else
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,121 @@
1
+ # Copyright (C) 2016 Dimitrios Dimas <dimitrios.work@outlook.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU General Public License
5
+ # as published by the Free Software Foundation; either version 2
6
+ # of the License, or (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
+
17
+ module SonarQube
18
+ module Projects
19
+ class Projects
20
+ @@endpoint='/api/projects/'
21
+
22
+ #Constructor
23
+ #
24
+ # @param [RestClient::Resource] connector The rest-client resource object
25
+ #
26
+ def initialize connector
27
+ @connector=connector
28
+ end
29
+
30
+ #Returns all projects
31
+ #
32
+ # @return [JSON] A JSON object, containing all the projects.
33
+ #
34
+ def get
35
+ JSON.parse(@connector["#{@@endpoint}index?format=json"].get)
36
+ end
37
+
38
+ #Search for a project using the project index number (id)
39
+ #
40
+ # @param [String] index project index number to use in the search
41
+ # @example puts \"this will return all the projects that their id is 47: #\\{search_by_key 47\}\"
42
+ # @return [JSON] A JSON object containing the project details (what details?).
43
+ def search_by_index index
44
+ JSON.parse(@connector["#{@@endpoint}index?key=#{index}"].get)
45
+ end
46
+
47
+ #Search for a project using the project key
48
+ #
49
+ # @param [String] key project key to use in the search
50
+ # @example puts \"this will return all the projects that their key is \'my:awesome:project\': #\\{search_by_key 'my:awesome:project'\}\"
51
+ # @return [JSON] A JSON object containing the project details (what details?).
52
+ def search_by_key key
53
+ JSON.parse(@connector["#{@@endpoint}index?key=#{key}"].get)
54
+ end
55
+
56
+ #Return all projects that their name contains the provided string
57
+ #
58
+ # @param [String] search_string search string to search with
59
+ # @return [JSON] A JSON object, containing all the project details (what details?).
60
+ # @example puts \"this will return all the projects that their name contains the string \'java\': #\\{name_contains 'java'\}\"
61
+ def name_contains search_string
62
+ JSON.parse(@connector["#{@@endpoint}index?search=#{search_string}"].get)
63
+ end
64
+
65
+ #Delete a project with the specified id
66
+ #
67
+ # @param [String] id id of the project to be deleted
68
+ # @return [JSON] A JSON object, containing all the project details (what details?).
69
+ # @example puts \"this will delete the project with id 47: #\\{delete_id 47\}\"
70
+ def delete_id id
71
+ JSON.parse(@connector["#{@@endpoint}delete?id=#{id}"].get)
72
+ end
73
+
74
+ #Delete a project with the specified key
75
+ #
76
+ # @param [String] key key of the project to be deleted
77
+ # @return [JSON] A JSON object, containing all the project details (what details?).
78
+ # @example puts \"this will delete the project with the key \'my:awesome:project\': #\\{delete_key 'my:awesome:project'\}\"
79
+ def delete_key key
80
+ JSON.parse(@connector["#{@@endpoint}delete?key=#{key}"].get)
81
+ end
82
+ end
83
+
84
+ #Returns all projects (functional interface)
85
+ #
86
+ # @return A JSON object, containing all the projects.
87
+ #
88
+ def get
89
+ JSON.parse(@connector["#{@@endpoint}api/projects/index"].get)
90
+ end
91
+
92
+ #Search for a project by key (functional interface)
93
+ #
94
+ # == Parameters:
95
+ # Project key
96
+ #
97
+ # == Returns:
98
+ # A JSON object containing the project details (what details?).
99
+ #
100
+ # == Example endpoints:
101
+ #http://localhost:9000/api/projects/index?key=35
102
+ #http://localhost:9000/api/projects/index?key=java-sonar-runner-simple
103
+ def search_by_key key
104
+ 'api/projects/index?key=' + key
105
+ end
106
+
107
+ #Search for a project by name
108
+ #
109
+ # == Parameters:
110
+ # Project name
111
+ #
112
+ # == Returns:
113
+ # A JSON object, containing all the project details (what details?).
114
+ #
115
+ # == Example endpoints:
116
+ #http://localhost:9000/api/projects/index?search=java
117
+ def search_by_name name
118
+ 'api/projects/index?search=' + name
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,45 @@
1
+ # Copyright (C) 2016 Dimitrios Dimas <dimitrios.work@outlook.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU General Public License
5
+ # as published by the Free Software Foundation; either version 2
6
+ # of the License, or (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
+
17
+ module SonarQube
18
+ module TimeMachine
19
+
20
+
21
+
22
+ class TimeMachine
23
+ @@endpoint='api/timemachine/'
24
+
25
+ def initialize connector
26
+ @connector=connector
27
+ end
28
+
29
+ #Returns the specified metrics of a project
30
+ #@param [String] project_name The name of the project
31
+ #@param [String] metrics A string that contains comma separated project metric keys/id's (can be found in: http://docs.sonarqube.org/display/SONAR/Metric+definitions)
32
+ #@return [JSON] A JSON object with the project metrics
33
+ def get project_name, metrics
34
+ JSON.parse(@connector["#{@@endpoint}index?format=json&resource=#{project_name}&metrics=#{metrics}&toDateTime=&fromDateTime="].get)
35
+ end
36
+ end
37
+
38
+ #example url:
39
+ #http://localhost:9000/api/timemachine/index?resource=java-sonar-runner-simple&metrics=lines,toDateTime=,fromDateTime=
40
+ def get(project, metrics)
41
+ 'api/timemachine/index?resource=' + project +'&metrics=' + metrics
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ # Copyright (C) 2016 Dimitrios Dimas <dimitrios.work@outlook.com>
2
+ #
3
+ # This program is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU General Public License
5
+ # as published by the Free Software Foundation; either version 2
6
+ # of the License, or (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
+
17
+ module SonarQube
18
+ VERSION_INFO = [0, 0, 0, 'develop'] unless defined?(self::VERSION_INFO)
19
+ VERSION = VERSION_INFO.map(&:to_s).join('.') unless defined?(self::VERSION)
20
+
21
+ def self.version
22
+ VERSION
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sonarqube-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dimitrios Dimas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.6.8
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.8
55
+ - !ruby/object:Gem::Dependency
56
+ name: logger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.8
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.8
69
+ description: This gem can be used to interact with a SonarQube server using the REST
70
+ API. This is an initial version and likely to be buggy and badly written. Testing/development
71
+ is done against a sonarqube 5.2 server.
72
+ email: dimitrios.work@outlook.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - lib/sonarqube-client.rb
78
+ - lib/sonarqube/client.rb
79
+ - lib/sonarqube/issues.rb
80
+ - lib/sonarqube/logger.rb
81
+ - lib/sonarqube/projects.rb
82
+ - lib/sonarqube/timemachine.rb
83
+ - lib/sonarqube/version.rb
84
+ homepage: http://rubygems.org/gems/sonarqube-client
85
+ licenses:
86
+ - GPL-2.0
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.5.1
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: SonarQube client
108
+ test_files: []
109
+ has_rdoc: