gitlab_client 0.1.0.pre.alpha → 0.1.0.pre.alpha.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +13 -1
- data/README.md +18 -1
- data/Rakefile +5 -1
- data/gitlab_client.gemspec +2 -2
- data/lib/gitlab_client/graphql.rb +18 -22
- data/lib/gitlab_client/rest.rb +26 -21
- data/lib/gitlab_client/version.rb +1 -1
- data/sig/gitlab_client/graphql.rbs +7 -7
- data/sig/gitlab_client/rest.rbs +7 -7
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fece9d5bf2fd375427e82ffecdfa89b05b0c008bbcdfcf148a372954fd00354a
|
4
|
+
data.tar.gz: e806ef4f11d95a3a35ad9844c677e24a64d1d30713a6bae22f51aac97b7ac93c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 165e199b2b3b3aa2c6c73c61e881e3c7dfdedeb8e27945e933f3508d3626dc275f50666d2006bb598b9f6b5106a8ebf7950fce48ee5d96e9d52b6e1fe335db96
|
7
|
+
data.tar.gz: 2d34961949191650d58d6644885c8361af62f838a0f9fda4a4c670963c65ead5f32726c02c5658589fbd5674e858dd0bb671343201422768ca5e786ed42eb2a2
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
gitlab_client (0.1.0.pre.alpha)
|
4
|
+
gitlab_client (0.1.0.pre.alpha.pre.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -11,11 +11,16 @@ GEM
|
|
11
11
|
i18n (>= 1.6, < 2)
|
12
12
|
minitest (>= 5.1)
|
13
13
|
tzinfo (~> 2.0)
|
14
|
+
addressable (2.8.1)
|
15
|
+
public_suffix (>= 2.0.2, < 6.0)
|
14
16
|
ast (2.4.2)
|
15
17
|
concurrent-ruby (1.1.10)
|
18
|
+
crack (0.4.5)
|
19
|
+
rexml
|
16
20
|
csv (3.2.6)
|
17
21
|
ffi (1.15.5)
|
18
22
|
fileutils (1.7.0)
|
23
|
+
hashdiff (1.0.1)
|
19
24
|
i18n (1.12.0)
|
20
25
|
concurrent-ruby (~> 1.0)
|
21
26
|
json (2.6.2)
|
@@ -28,6 +33,7 @@ GEM
|
|
28
33
|
parallel (1.22.1)
|
29
34
|
parser (3.1.2.1)
|
30
35
|
ast (~> 2.4.1)
|
36
|
+
public_suffix (5.0.1)
|
31
37
|
rainbow (3.1.1)
|
32
38
|
rake (13.0.6)
|
33
39
|
rb-fsevent (0.11.2)
|
@@ -71,9 +77,14 @@ GEM
|
|
71
77
|
tzinfo (2.0.5)
|
72
78
|
concurrent-ruby (~> 1.0)
|
73
79
|
unicode-display_width (2.3.0)
|
80
|
+
webmock (3.18.1)
|
81
|
+
addressable (>= 2.8.0)
|
82
|
+
crack (>= 0.3.2)
|
83
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
74
84
|
|
75
85
|
PLATFORMS
|
76
86
|
arm64-darwin-21
|
87
|
+
arm64-darwin-22
|
77
88
|
|
78
89
|
DEPENDENCIES
|
79
90
|
gitlab_client!
|
@@ -81,6 +92,7 @@ DEPENDENCIES
|
|
81
92
|
rake (~> 13.0)
|
82
93
|
rubocop (~> 1.21)
|
83
94
|
steep
|
95
|
+
webmock
|
84
96
|
|
85
97
|
BUNDLED WITH
|
86
98
|
2.2.33
|
data/README.md
CHANGED
@@ -26,6 +26,23 @@ Or install it yourself as:
|
|
26
26
|
```ruby
|
27
27
|
GitlabClient::Rest.new(private_token: '<TOKEN>').call( path: 'api/v4/version')
|
28
28
|
```
|
29
|
+
|
30
|
+
### Graphql API
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
query = '{ projects { edges { node { id name description } } } }'
|
34
|
+
GitlabClient::Graphql.new(private_token: '<TOKEN>').call(query: query)
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
### Difference between Gitlab gem and GitlabClient gem
|
39
|
+
|
40
|
+
- Gitlab client gem is thin, it does not include helper methods per endpoint, nor CLI
|
41
|
+
- Gitlab client gem also supports Graphql WIP
|
42
|
+
- Gitlab client gem have built in mechanism for pagination TODO
|
43
|
+
- Gitlab client gem does not have global state, you can connect to more than one Gitlab instances from same code safely
|
44
|
+
- Gitlab client gem does not depend on other gems, ie no worry about dependency updates
|
45
|
+
|
29
46
|
## Development
|
30
47
|
|
31
48
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -34,7 +51,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
34
51
|
|
35
52
|
## Contributing
|
36
53
|
|
37
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tachyons/gitlab_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tachyons/gitlab_client/blob/master/CODE_OF_CONDUCT.md).
|
38
55
|
|
39
56
|
## License
|
40
57
|
|
data/Rakefile
CHANGED
data/gitlab_client.gemspec
CHANGED
@@ -10,9 +10,9 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = "Gitlab Client"
|
12
12
|
spec.description = "Gitlab API client"
|
13
|
-
spec.homepage = "https://gitlab.com/tachyons/
|
13
|
+
spec.homepage = "https://gitlab.com/tachyons-gitlab/gitlab_client"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">=
|
15
|
+
spec.required_ruby_version = ">= 3.0.0"
|
16
16
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
18
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
@@ -9,7 +9,7 @@ module GitlabClient
|
|
9
9
|
|
10
10
|
# Gitlab client
|
11
11
|
class Graphql
|
12
|
-
DEFAULT_HEADERS = { "Accept" => "application/json" }.freeze
|
12
|
+
DEFAULT_HEADERS = { "Accept" => "application/json", "Content-Type" => "application/json" }.freeze
|
13
13
|
GRAPHQL_ENDPOINT = "api/graphql"
|
14
14
|
MAXIMUM_REDIRECTS = 5
|
15
15
|
attr_reader :access_token, :refresh_token, :private_token
|
@@ -21,12 +21,26 @@ module GitlabClient
|
|
21
21
|
@private_token = private_token
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
|
24
|
+
def call(query:, variables: {})
|
25
|
+
response = Net::HTTP.post(uri, { query: query, variables: variables }.to_json, headers)
|
26
|
+
|
27
|
+
response
|
28
|
+
.then { |res| handle_error(res) }
|
29
|
+
.then { |res| JSON.parse(res.body) }
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def handle_error(response)
|
35
|
+
case response
|
36
|
+
when Net::HTTPClientError
|
37
|
+
raise Error, JSON.parse(response.body)
|
38
|
+
end
|
39
|
+
response
|
26
40
|
end
|
27
41
|
|
28
42
|
def valid?
|
29
|
-
!(access_token ||
|
43
|
+
!(access_token || private_token).nil?
|
30
44
|
end
|
31
45
|
|
32
46
|
def headers
|
@@ -39,23 +53,5 @@ module GitlabClient
|
|
39
53
|
def uri
|
40
54
|
URI.join(@host, GRAPHQL_ENDPOINT)
|
41
55
|
end
|
42
|
-
|
43
|
-
def call(query:)
|
44
|
-
response = Net::HTTP.post(uri, query)
|
45
|
-
|
46
|
-
response
|
47
|
-
.then { |res| handle_error(res) }
|
48
|
-
.then { |res| JSON.parse(res) }
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def handle_error(response)
|
54
|
-
case response
|
55
|
-
when Net::HTTPClientError
|
56
|
-
raise Error, JSON.parse(response.body)
|
57
|
-
end
|
58
|
-
response
|
59
|
-
end
|
60
56
|
end
|
61
57
|
end
|
data/lib/gitlab_client/rest.rb
CHANGED
@@ -9,7 +9,8 @@ module GitlabClient
|
|
9
9
|
|
10
10
|
# Gitlab client
|
11
11
|
class Rest
|
12
|
-
DEFAULT_HEADERS = { "Accept" => "application/json"
|
12
|
+
DEFAULT_HEADERS = { "Accept" => "application/json",
|
13
|
+
"User-Agent" => "gitlab_client #{GitlabClient::VERSION}" }.freeze
|
13
14
|
MAXIMUM_REDIRECTS = 5
|
14
15
|
attr_reader :access_token, :refresh_token, :private_token
|
15
16
|
|
@@ -20,39 +21,28 @@ module GitlabClient
|
|
20
21
|
@private_token = private_token
|
21
22
|
end
|
22
23
|
|
23
|
-
def access_token?
|
24
|
-
!access_token.nil?
|
25
|
-
end
|
26
|
-
|
27
|
-
def valid?
|
28
|
-
!(access_token || refresh_token).nil?
|
29
|
-
end
|
30
|
-
|
31
|
-
def headers
|
32
|
-
return DEFAULT_HEADERS.merge({ "PRIVATE-TOKEN" => private_token }) if private_token
|
33
|
-
return DEFAULT_HEADERS.merge({ "Authorization" => "Bearer #{access_token}" }) if access_token
|
34
|
-
|
35
|
-
{}
|
36
|
-
end
|
37
|
-
|
38
24
|
# rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
39
25
|
def call(path:, method: "GET", custom_headers: {}, data: {})
|
40
|
-
|
26
|
+
raise ArgumentError, "Provide access token or private token to call API" unless valid?
|
27
|
+
|
28
|
+
req_headers = headers.merge(custom_headers)
|
29
|
+
uri = URI.join(@host, path)
|
41
30
|
case method
|
42
31
|
when "GET"
|
43
|
-
response = Net::HTTP.get_response(uri,
|
32
|
+
response = Net::HTTP.get_response(uri, req_headers)
|
44
33
|
when "POST"
|
45
|
-
response = Net::HTTP.post(uri, data.to_json, headers
|
34
|
+
response = Net::HTTP.post(uri, data.to_json, headers)
|
46
35
|
when "PATCH"
|
47
|
-
response = Net::HTTP.patch(uri, data, headers
|
36
|
+
response = Net::HTTP.patch(uri, data, headers)
|
48
37
|
when "DELETE"
|
49
|
-
response = Net::HTTP.patch(uri, data, headers
|
38
|
+
response = Net::HTTP.patch(uri, data, headers)
|
50
39
|
|
51
40
|
end
|
52
41
|
|
53
42
|
response
|
54
43
|
.then { |res| handle_redirect(res) }
|
55
44
|
.then { |res| handle_error(res) }
|
45
|
+
.then { |res| handle_pagination(res) }
|
56
46
|
.then { |res| JSON.parse(res.body) }
|
57
47
|
end
|
58
48
|
# rubocop:enable Metrics/MethodLength,Metrics/AbcSize
|
@@ -86,5 +76,20 @@ module GitlabClient
|
|
86
76
|
end
|
87
77
|
response
|
88
78
|
end
|
79
|
+
|
80
|
+
def handle_pagination(response)
|
81
|
+
response
|
82
|
+
end
|
83
|
+
|
84
|
+
def valid?
|
85
|
+
!(access_token || private_token).nil?
|
86
|
+
end
|
87
|
+
|
88
|
+
def headers
|
89
|
+
return DEFAULT_HEADERS.merge({ "PRIVATE-TOKEN" => private_token }) if private_token
|
90
|
+
return DEFAULT_HEADERS.merge({ "Authorization" => "Bearer #{access_token}" }) if access_token
|
91
|
+
|
92
|
+
{}
|
93
|
+
end
|
89
94
|
end
|
90
95
|
end
|
@@ -8,17 +8,17 @@ module GitlabClient
|
|
8
8
|
MAXIMUM_REDIRECTS: Integer
|
9
9
|
@host: String
|
10
10
|
|
11
|
-
attr_reader access_token:
|
12
|
-
attr_reader refresh_token:
|
13
|
-
attr_reader private_token:
|
14
|
-
def initialize: (?access_token:
|
15
|
-
def access_token?: ->
|
11
|
+
attr_reader access_token: String?
|
12
|
+
attr_reader refresh_token: String?
|
13
|
+
attr_reader private_token: String?
|
14
|
+
def initialize: (?access_token: String?, ?refresh_token: String?, ?private_token: String?, ?host: String) -> void
|
15
|
+
def access_token?: -> bool
|
16
16
|
def valid?: -> bool
|
17
17
|
def headers: -> Hash[String, String?]
|
18
18
|
def uri: -> URI::Generic
|
19
|
-
def call: (query:
|
19
|
+
def call: (query: String, ?variables: Hash[String, String?]) -> JSON
|
20
20
|
|
21
21
|
private
|
22
|
-
def handle_error: (
|
22
|
+
def handle_error: (Net::HTTP| Net::HTTPResponse response) -> (Net::HTTP | Net::HTTPResponse)
|
23
23
|
end
|
24
24
|
end
|
data/sig/gitlab_client/rest.rbs
CHANGED
@@ -7,14 +7,14 @@ module GitlabClient
|
|
7
7
|
MAXIMUM_REDIRECTS: Integer
|
8
8
|
@host: String
|
9
9
|
|
10
|
-
attr_reader access_token:
|
11
|
-
attr_reader refresh_token:
|
12
|
-
attr_reader private_token:
|
13
|
-
def initialize: (?access_token:
|
14
|
-
def access_token?: ->
|
15
|
-
def valid?: ->
|
10
|
+
attr_reader access_token: String?
|
11
|
+
attr_reader refresh_token: String?
|
12
|
+
attr_reader private_token: String?
|
13
|
+
def initialize: (?access_token: String?, ?refresh_token: String?, ?private_token: String?, ?host: String) -> void
|
14
|
+
def access_token?: -> bool
|
15
|
+
def valid?: -> bool
|
16
16
|
def headers: -> Hash[String, String?]
|
17
|
-
def call: (path:
|
17
|
+
def call: (path: String, ?method: String, ?custom_headers: Hash[String, String?], ?data: Hash[String, String?]) -> JSON
|
18
18
|
|
19
19
|
private
|
20
20
|
def handle_redirect: (Net::HTTP | ::Net::HTTPResponse response, ?Integer limit) -> (Net::HTTP | Net::HTTPSuccess| ::Net::HTTPResponse| nil)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.alpha
|
4
|
+
version: 0.1.0.pre.alpha.pre.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aboobacker MK
|
@@ -36,13 +36,13 @@ files:
|
|
36
36
|
- sig/gitlab_client.rbs
|
37
37
|
- sig/gitlab_client/graphql.rbs
|
38
38
|
- sig/gitlab_client/rest.rbs
|
39
|
-
homepage: https://gitlab.com/tachyons/
|
39
|
+
homepage: https://gitlab.com/tachyons-gitlab/gitlab_client
|
40
40
|
licenses:
|
41
41
|
- MIT
|
42
42
|
metadata:
|
43
|
-
homepage_uri: https://gitlab.com/tachyons/
|
44
|
-
source_code_uri: https://gitlab.com/tachyons/
|
45
|
-
changelog_uri: https://gitlab.com/tachyons/
|
43
|
+
homepage_uri: https://gitlab.com/tachyons-gitlab/gitlab_client
|
44
|
+
source_code_uri: https://gitlab.com/tachyons-gitlab/gitlab_client
|
45
|
+
changelog_uri: https://gitlab.com/tachyons-gitlab/gitlab_client
|
46
46
|
post_install_message:
|
47
47
|
rdoc_options: []
|
48
48
|
require_paths:
|
@@ -51,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.0.0
|
55
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - ">"
|