gitearb 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d09aacbbd7cbe3fe90fe4c799eef4354569a61296bfcc9617cb6d006b9e66f29
4
- data.tar.gz: 3ac9fb06ee56ced9d0570c2ceb2681cca204d5cfaa03f14583bef9089961bc32
3
+ metadata.gz: b9d322ad7cea3712f32a04f5d2d4402d61e8b43f6aad0ca470566f6c4f34d851
4
+ data.tar.gz: 273c36d0ccc26ae602a1a9cc6ea80d57171185633cf72d1d72a489ea0c982937
5
5
  SHA512:
6
- metadata.gz: 215c6241bf98977c093769522368af10539b18a917e4da3ffa28b44d8f7ee063586a5b03f81f5559e6fe33d04d6f3d32cfd80bd08ce668dcad2c0a3f8ba41076
7
- data.tar.gz: 0d8f12f039ad28ca772f3c0a41959dcffcc4e9cbcedc2c20ad22efaa4033ffc08c58ce2bbaebee2c163f6a3ed2eebd290a48574029b3e7303fc93ce4b8b42dc3
6
+ metadata.gz: cc9afeaf15ba7cfdd058b801ffe8666c2805ef516f058723c032df695e21c7b858e02552d65a59872667d8eeea1c776ce3f683afbaf894e889891117c5183e06
7
+ data.tar.gz: 21f78ef489bddeaff89a2d280e8abc27ef8f120fd73e7d822c912953e878334f497af724828ff0887f7366bea862f906ff64996da0eb504468c11c2298aa9ef5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitearb (0.1.0)
4
+ gitearb (0.1.2)
5
5
  faraday (~> 2.0)
6
6
 
7
7
  GEM
data/lib/gitea/client.rb CHANGED
@@ -17,6 +17,30 @@ module Gitea
17
17
  UserResource.new(self)
18
18
  end
19
19
 
20
+ def user_repos
21
+ UserReposResource.new(self)
22
+ end
23
+
24
+ def orgs
25
+ OrgsResource.new(self)
26
+ end
27
+
28
+ def org_hooks
29
+ OrgHooksResource.new(self)
30
+ end
31
+
32
+ def repos
33
+ ReposResource.new(self)
34
+ end
35
+
36
+ def repo_hooks
37
+ RepoHooksResource.new(self)
38
+ end
39
+
40
+ def commit_statuses
41
+ CommitStatusesResource.new(self)
42
+ end
43
+
20
44
  def connection
21
45
  full_url = [url, "api/v1"].join("/")
22
46
 
@@ -2,9 +2,13 @@ module Gitea
2
2
  class Collection
3
3
  attr_reader :data, :total
4
4
 
5
- def self.from_response(response, type:)
5
+ def self.from_response(response, type:, kind: nil)
6
6
  body = response.body
7
7
 
8
+ if kind
9
+ body = body[kind]
10
+ end
11
+
8
12
  new(
9
13
  data: body.map { |attrs| type.new(attrs) },
10
14
  total: body.count
@@ -0,0 +1,4 @@
1
+ module Gitea
2
+ class CommitStatus < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Gitea
2
+ class Hook < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Gitea
2
+ class Org < Object
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Gitea
2
+ class Repo < Object
3
+ end
4
+ end
@@ -33,21 +33,21 @@ module Gitea
33
33
  when 400
34
34
  raise Error, "Error 400: Your request was malformed. '#{response.body["message"]}'"
35
35
  when 401
36
- raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["error"]}'"
36
+ raise Error, "Error 401: You did not supply valid authentication credentials. '#{response.body["message"]}'"
37
37
  when 403
38
- raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["error"]}'"
38
+ raise Error, "Error 403: You are not allowed to perform that action. '#{response.body["message"]}'"
39
39
  when 404
40
- raise Error, "Error 404: No results were found for your request. '#{response.body["error"]}'"
40
+ raise Error, "Error 404: No results were found for your request. '#{response.body["message"]}'"
41
41
  when 409
42
42
  raise Error, "Error 409: Your request was a conflict. '#{response.body["message"]}'"
43
43
  when 422
44
44
  raise Error, "Error 422: Unprocessable Entity. '#{response.body["message"]}"
45
45
  when 429
46
- raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["error"]}'"
46
+ raise Error, "Error 429: Your request exceeded the API rate limit. '#{response.body["message"]}'"
47
47
  when 500
48
- raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["error"]}'"
48
+ raise Error, "Error 500: We were unable to perform the request due to server-side problems. '#{response.body["message"]}'"
49
49
  when 503
50
- raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["error"]}'"
50
+ raise Error, "Error 503: You have been rate limited for sending more than 20 requests per second. '#{response.body["message"]}'"
51
51
  when 204
52
52
  # 204 is a response for success on Twitch's API
53
53
  return true
@@ -0,0 +1,14 @@
1
+ module Gitea
2
+ class CommitStatusesResource < Resource
3
+
4
+ def list(owner:, repo:, sha:, **params)
5
+ response = get_request("repos/#{owner}/#{repo}/statuses/#{sha}", params: params)
6
+ Collection.from_response(response, type: CommitStatus)
7
+ end
8
+
9
+ def create(owner:, repo:, sha:, **args)
10
+ CommitStatus.new post_request("repos/#{owner}/#{repo}/statuses/#{sha}", body: args).body
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ module Gitea
2
+ class OrgHooksResource < Resource
3
+
4
+ def list(org:, **params)
5
+ response = get_request("orgs/#{org}/hooks", params: params)
6
+ Collection.from_response(response, type: Hook)
7
+ end
8
+
9
+ def get(org:, id:)
10
+ Hook.new get_request("orgs/#{org}/hooks/#{id}").body
11
+ end
12
+
13
+ def create(org:, url:, type:, **args)
14
+ data = {config: {content_type: "json", url: url}, type: type}
15
+ Hook.new post_request("orgs/#{org}/hooks", body: args.merge(data)).body
16
+ end
17
+
18
+ def update(org:, id:, **args)
19
+ Hook.new patch_request("orgs/#{org}/hooks/#{id}", body: args).body
20
+ end
21
+
22
+ def delete(org:, id:)
23
+ delete_request("orgs/#{org}/hooks/#{id}")
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ module Gitea
2
+ class OrgsResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("orgs", params: params)
6
+ Collection.from_response(response, type: Org)
7
+ end
8
+
9
+ def get(name:)
10
+ Org.new get_request("orgs/#{name}").body
11
+ end
12
+
13
+ def create(name:, **args)
14
+ Org.new post_request("orgs", body: args.merge({username: name})).body
15
+ end
16
+
17
+ def update(name:, **args)
18
+ Org.new patch_request("orgs/#{name}", body: args).body
19
+ end
20
+
21
+ def delete(name:)
22
+ delete_request("orgs/#{name}")
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ module Gitea
2
+ class RepoHooksResource < Resource
3
+
4
+ def list(owner:, repo:, **params)
5
+ response = get_request("repos/#{owner}/#{repo}/hooks", params: params)
6
+ Collection.from_response(response, type: Hook)
7
+ end
8
+
9
+ def get(owner:, repo:, id:)
10
+ Hook.new get_request("repos/#{owner}/#{repo}/hooks/#{id}").body
11
+ end
12
+
13
+ def create(owner:, repo:, url:, type:, **args)
14
+ data = {config: {content_type: "json", url: url}, type: type}
15
+ Hook.new post_request("repos/#{owner}/#{repo}/hooks", body: args.merge(data)).body
16
+ end
17
+
18
+ def test(owner:, repo:, id:)
19
+ post_request("repos/#{owner}/#{repo}/hooks/#{id}/tests", body: {})
20
+ end
21
+
22
+ def update(owner:, repo:, id:, **args)
23
+ Hook.new patch_request("repos/#{owner}/#{repo}/hooks/#{id}", body: args).body
24
+ end
25
+
26
+ def delete(owner:, repo:, id:)
27
+ delete_request("repos/#{owner}/#{repo}/hooks/#{id}")
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ module Gitea
2
+ class ReposResource < Resource
3
+
4
+ def search(**params)
5
+ response = get_request("repos/search", params: params)
6
+ Collection.from_response(response, type: Repo, kind: "data")
7
+ end
8
+
9
+ def get(owner:, repo:)
10
+ Repo.new get_request("repos/#{owner}/#{repo}").body
11
+ end
12
+
13
+ def update(owner:, repo:, **args)
14
+ Repo.new patch_request("repos/#{owner}/#{repo}", body: args).body
15
+ end
16
+
17
+ def delete(owner:, repo:)
18
+ delete_request("repos/#{owner}/#{repo}")
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module Gitea
2
+ class UserReposResource < Resource
3
+
4
+ def list(**params)
5
+ response = get_request("user/repos", params: params)
6
+ Collection.from_response(response, type: Repo)
7
+ end
8
+
9
+ def create(name:, **args)
10
+ Repo.new post_request("user/repos", body: args.merge({name: name})).body
11
+ end
12
+
13
+ end
14
+ end
data/lib/gitea/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gitea
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/gitea.rb CHANGED
@@ -12,8 +12,18 @@ module Gitea
12
12
 
13
13
 
14
14
  autoload :UserResource, "gitea/resources/user"
15
+ autoload :OrgsResource, "gitea/resources/orgs"
16
+ autoload :OrgHooksResource, "gitea/resources/org_hooks"
17
+ autoload :UserReposResource, "gitea/resources/user_repos"
18
+ autoload :ReposResource, "gitea/resources/repos"
19
+ autoload :RepoHooksResource, "gitea/resources/repo_hooks"
20
+ autoload :CommitStatusesResource, "gitea/resources/commit_statuses"
15
21
 
16
22
  autoload :User, "gitea/objects/user"
17
23
  autoload :Email, "gitea/objects/email"
24
+ autoload :Org, "gitea/objects/org"
25
+ autoload :Hook, "gitea/objects/hook"
26
+ autoload :Repo, "gitea/objects/repo"
27
+ autoload :CommitStatus, "gitea/objects/commit_status"
18
28
 
19
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitearb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Perry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-06 00:00:00.000000000 Z
11
+ date: 2023-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -48,10 +48,20 @@ files:
48
48
  - lib/gitea/collection.rb
49
49
  - lib/gitea/error.rb
50
50
  - lib/gitea/object.rb
51
+ - lib/gitea/objects/commit_status.rb
51
52
  - lib/gitea/objects/email.rb
53
+ - lib/gitea/objects/hook.rb
54
+ - lib/gitea/objects/org.rb
55
+ - lib/gitea/objects/repo.rb
52
56
  - lib/gitea/objects/user.rb
53
57
  - lib/gitea/resource.rb
58
+ - lib/gitea/resources/commit_statuses.rb
59
+ - lib/gitea/resources/org_hooks.rb
60
+ - lib/gitea/resources/orgs.rb
61
+ - lib/gitea/resources/repo_hooks.rb
62
+ - lib/gitea/resources/repos.rb
54
63
  - lib/gitea/resources/user.rb
64
+ - lib/gitea/resources/user_repos.rb
55
65
  - lib/gitea/version.rb
56
66
  - lib/gitearb.rb
57
67
  homepage: https://deanpcmad.com