gitlab_client 0.1.0.pre.alpha → 0.1.0.pre.alpha.pre.1

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: 5e2071d6c7fc92d058cff4d793ffc24b8fac2990464aee08525f8cfa15e81a4c
4
- data.tar.gz: 3e68ca1275c5ce5d80b900b2af8d738c9d97510feb5e94914e1ccd87af734f6c
3
+ metadata.gz: fece9d5bf2fd375427e82ffecdfa89b05b0c008bbcdfcf148a372954fd00354a
4
+ data.tar.gz: e806ef4f11d95a3a35ad9844c677e24a64d1d30713a6bae22f51aac97b7ac93c
5
5
  SHA512:
6
- metadata.gz: c670045a8ab2b663f19626cd33f6b6bfd095d8dfd506fd08e360f2d1a8388a4fbc9c38242a807e8d8b160b1b9a7830a08fe3a64ce7419be9f32b11982907880b
7
- data.tar.gz: e1b9dba06c5546a531f76e743a0109eb14195cac1bdaec8cdcc13b2163786f9615b3c2ffae2a504cb73069d3d556825a4ddbce43d3d98ec927859996557294cd
6
+ metadata.gz: 165e199b2b3b3aa2c6c73c61e881e3c7dfdedeb8e27945e933f3508d3626dc275f50666d2006bb598b9f6b5106a8ebf7950fce48ee5d96e9d52b6e1fe335db96
7
+ data.tar.gz: 2d34961949191650d58d6644885c8361af62f838a0f9fda4a4c670963c65ead5f32726c02c5658589fbd5674e858dd0bb671343201422768ca5e786ed42eb2a2
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  AllCops:
3
- TargetRubyVersion: 2.7
3
+ TargetRubyVersion: 3.0
4
4
 
5
5
  Style/StringLiterals:
6
6
  Enabled: true
data/Gemfile CHANGED
@@ -12,3 +12,5 @@ gem "minitest", "~> 5.0"
12
12
  gem "rubocop", "~> 1.21"
13
13
 
14
14
  gem "steep"
15
+
16
+ gem "webmock"
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/[USERNAME]/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).
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
@@ -13,4 +13,8 @@ require "rubocop/rake_task"
13
13
 
14
14
  RuboCop::RakeTask.new
15
15
 
16
- task default: %i[test rubocop]
16
+ task :steep do
17
+ system "bundle exec steep check"
18
+ end
19
+
20
+ task default: %i[test rubocop steep]
@@ -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/oauth2"
13
+ spec.homepage = "https://gitlab.com/tachyons-gitlab/gitlab_client"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.7.0"
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 access_token?
25
- !access_token.nil?
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 || refresh_token).nil?
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
@@ -9,7 +9,8 @@ module GitlabClient
9
9
 
10
10
  # Gitlab client
11
11
  class Rest
12
- DEFAULT_HEADERS = { "Accept" => "application/json" }.freeze
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
- uri = URI(@host + path)
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, headers.merge(custom_headers))
32
+ response = Net::HTTP.get_response(uri, req_headers)
44
33
  when "POST"
45
- response = Net::HTTP.post(uri, data.to_json, headers.merge(custom_headers))
34
+ response = Net::HTTP.post(uri, data.to_json, headers)
46
35
  when "PATCH"
47
- response = Net::HTTP.patch(uri, data, headers.merge(custom_headers))
36
+ response = Net::HTTP.patch(uri, data, headers)
48
37
  when "DELETE"
49
- response = Net::HTTP.patch(uri, data, headers.merge(custom_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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitlabClient
4
- VERSION = "0.1.0-alpha"
4
+ VERSION = "0.1.0-alpha-1"
5
5
  end
@@ -8,17 +8,17 @@ module GitlabClient
8
8
  MAXIMUM_REDIRECTS: Integer
9
9
  @host: String
10
10
 
11
- attr_reader access_token: nil
12
- attr_reader refresh_token: nil
13
- attr_reader private_token: nil
14
- def initialize: (?access_token: nil, ?refresh_token: nil, ?private_token: nil, ?host: String) -> void
15
- def access_token?: -> false
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: untyped) -> untyped
19
+ def call: (query: String, ?variables: Hash[String, String?]) -> JSON
20
20
 
21
21
  private
22
- def handle_error: (untyped response) -> untyped
22
+ def handle_error: (Net::HTTP| Net::HTTPResponse response) -> (Net::HTTP | Net::HTTPResponse)
23
23
  end
24
24
  end
@@ -7,14 +7,14 @@ module GitlabClient
7
7
  MAXIMUM_REDIRECTS: Integer
8
8
  @host: String
9
9
 
10
- attr_reader access_token: nil
11
- attr_reader refresh_token: nil
12
- attr_reader private_token: nil
13
- def initialize: (?access_token: nil, ?refresh_token: nil, ?private_token: nil, ?host: String) -> void
14
- def access_token?: -> false
15
- def valid?: -> false
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: untyped, ?method: String, ?custom_headers: Hash[untyped, untyped], ?data: Hash[untyped, untyped]) -> untyped
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/oauth2
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/oauth2
44
- source_code_uri: https://gitlab.com/tachyons/oauth2
45
- changelog_uri: https://gitlab.com/tachyons/oauth2
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: 2.7.0
54
+ version: 3.0.0
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">"