trav3 0.3.0 → 0.3.1

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: df20e3328d17a3337d9a09631285a18d5aa3d59381651c09db938f0e95edd324
4
- data.tar.gz: 583fc08a041c80d8ebee2bc0684b7cea15a8888defdb6bd3bc5d17165406c1ae
3
+ metadata.gz: 97c7a3e7bbfb1ec5effd12bf275cf1e0bff1e39ed6676531648fb77c8ea329b4
4
+ data.tar.gz: '0683ce386cf9c469fb9f404321cb9de550141106a70dd4f12454d51f5ace73ed'
5
5
  SHA512:
6
- metadata.gz: 4c08c5042a02094911029e1ddfab0cfb3e2f960f2fcc54222ddc5c020a9dff19f973f8b6593a893dd95e27c5fc389546115b4bf732ba9861c2dfa947f800b55d
7
- data.tar.gz: d7cf95030b983f865874cfc033954597222af945b3c11a00e907fea4463caf6b5187c50059e17e94e4f893897cb221b2cb4bf9cafe10413c21a3d40c177d68d4
6
+ metadata.gz: 4c0c20dead40f8acff9ba0002e0e87b11fea7f8451ef425b4fff3d27a29cc5896484c6fc0297a757ab525cf1964d625492fdc85cc11162dcb3ef069b7675e7ba
7
+ data.tar.gz: 4dab80633ae6036f7574e92fc599db46e669627b9812fea3464f4689909c1872a230770f14c4acef3d606ed79c604bb86902d97253327578d2485ee6e02f8a92
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/trav3.svg)](http://badge.fury.io/rb/trav3)
2
2
  [![Build Status](https://travis-ci.org/danielpclark/trav3.svg?branch=master)](https://travis-ci.org/danielpclark/trav3)
3
- [![Commits Since Release](https://img.shields.io/github/commits-since/danielpclark/trav3/v0.2.5.svg)](https://github.com/danielpclark/trav3/graphs/commit-activity)
3
+ [![Commits Since Release](https://img.shields.io/github/commits-since/danielpclark/trav3/v0.3.1.svg)](https://github.com/danielpclark/trav3/graphs/commit-activity)
4
4
  [![Maintainability](https://api.codeclimate.com/v1/badges/1ed07a4baea3832b6207/maintainability)](https://codeclimate.com/github/danielpclark/trav3/maintainability)
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/1ed07a4baea3832b6207/test_coverage)](https://codeclimate.com/github/danielpclark/trav3/test_coverage)
6
6
  [![Red The Docs](https://img.shields.io/badge/Read-the%20docs-blue.svg)](http://danielpclark.github.io/trav3/Trav3/Travis.html)
@@ -31,17 +31,16 @@ module Trav3
31
31
  # conform to valid repository identifier format
32
32
  # @return [Travis]
33
33
  def initialize(repo)
34
- validate_repo_format repo
35
-
36
34
  @api_endpoint = 'https://api.travis-ci.org'
37
- @repo = sanitize_repo_name repo
35
+
36
+ self.repository = repo
38
37
 
39
38
  initial_defaults
40
39
  end
41
40
 
42
- # @overload api_endpoint=(endpoint)
43
- # Set as the API endpoint
44
- # @param endpoint [String] name for value to set
41
+ # Set as the API endpoint
42
+ #
43
+ # @param endpoint [String] name for value to set
45
44
  # @return [self]
46
45
  # rubocop:disable Lint/Void
47
46
  def api_endpoint=(endpoint)
@@ -53,9 +52,10 @@ module Trav3
53
52
  end
54
53
  # rubocop:enable Lint/Void
55
54
 
55
+ # Set as many options as you'd like for collections queried via an API request
56
+ #
56
57
  # @overload defaults(key: value, ...)
57
- # Set as many options as you'd like for collections queried via an API request
58
- # @param key [Symbol, String] name for value to set
58
+ # @param key [Symbol] name for value to set
59
59
  # @param value [Symbol, String, Integer] value for key
60
60
  # @return [self]
61
61
  def defaults(**args)
@@ -68,7 +68,7 @@ module Trav3
68
68
  # h("Authorization": "token xxxxxxxxxxxxxxxxxxxxxx")
69
69
  #
70
70
  # @overload h(key: value, ...)
71
- # @param key [Symbol, String] name for value to set
71
+ # @param key [Symbol] name for value to set
72
72
  # @param value [Symbol, String, Integer] value for key
73
73
  # @return [self]
74
74
  def h(**args)
@@ -76,6 +76,14 @@ module Trav3
76
76
  self
77
77
  end
78
78
 
79
+ # Change the repository this instance of `Trav3::Travis` uses.
80
+ #
81
+ # @param repo_name [String] github_username/repository_name
82
+ def repository=(repo_name)
83
+ validate_repo_format repo_name
84
+ @repo = sanitize_repo_name repo_name
85
+ end
86
+
79
87
  # Please Note that the naming of this endpoint may be changed. Our naming convention for this information is in flux. If you have suggestions for how this information should be presented please leave us feedback by commenting in this issue here or emailing support support@travis-ci.com.
80
88
  #
81
89
  # A list of all the builds in an "active" state, either created or started.
@@ -746,6 +754,234 @@ module Trav3
746
754
  end
747
755
  end
748
756
 
757
+ # Users may add a public/private RSA key pair to a repository.
758
+ # This can be used within builds, for example to access third-party services or deploy code to production.
759
+ # Please note this feature is only available on the travis-ci.com domain.
760
+ #
761
+ # ## Attributes
762
+ #
763
+ # **Standard Representation**
764
+ #
765
+ # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
766
+ #
767
+ # Name Type Description
768
+ # description String A text description.
769
+ # public_key String The public key.
770
+ # fingerprint String The fingerprint.
771
+ #
772
+ # **Minimal Representation**
773
+ #
774
+ # Included when the resource is returned as part of another resource.
775
+ #
776
+ # Name Type Description
777
+ # description String A text description.
778
+ # public_key String The public key.
779
+ # fingerprint String The fingerprint.
780
+ #
781
+ # ## Actions
782
+ #
783
+ # **Find**
784
+ #
785
+ # Return the current key pair, if it exists.
786
+ #
787
+ # GET <code>/repo/{repository.id}/key_pair</code>
788
+ #
789
+ # Template Variable Type Description
790
+ # repository.id Integer Value uniquely identifying the repository.
791
+ # Query Parameter Type Description
792
+ # include [String] List of attributes to eager load.
793
+ #
794
+ # Example: GET /repo/891/key_pair
795
+ #
796
+ # GET <code>/repo/{repository.slug}/key_pair</code>
797
+ #
798
+ # Template Variable Type Description
799
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
800
+ # Query Parameter Type Description
801
+ # include [String] List of attributes to eager load.
802
+ #
803
+ # Example: GET /repo/rails%2Frails/key_pair
804
+ #
805
+ # **Create**
806
+ #
807
+ # Creates a new key pair.
808
+ #
809
+ # ```bash
810
+ # curl -X POST \
811
+ # -H "Content-Type: application/json" \
812
+ # -H "Travis-API-Version: 3" \
813
+ # -H "Authorization: token xxxxxxxxxxxx" \
814
+ # -d '{ "key_pair.description": "FooBar", "key_pair.value": "xxxxx"}' \
815
+ # https://api.travis-ci.com/repo/1234/key_pair
816
+ # ```
817
+ #
818
+ # POST <code>/repo/{repository.id}/key_pair</code>
819
+ #
820
+ # Template Variable Type Description
821
+ # repository.id Integer Value uniquely identifying the repository.
822
+ # Accepted Parameter Type Description
823
+ # key_pair.description String A text description.
824
+ # key_pair.value String The private key.
825
+ #
826
+ # Example: POST /repo/891/key_pair
827
+ #
828
+ # POST <code>/repo/{repository.slug}/key_pair</code>
829
+ #
830
+ # Template Variable Type Description
831
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
832
+ # Accepted Parameter Type Description
833
+ # key_pair.description String A text description.
834
+ # key_pair.value String The private key.
835
+ #
836
+ # Example: POST /repo/rails%2Frails/key_pair
837
+ #
838
+ # **Update**
839
+ #
840
+ # Update the key pair.
841
+ #
842
+ # ```bash
843
+ # curl -X PATCH \
844
+ # -H "Content-Type: application/json" \
845
+ # -H "Travis-API-Version: 3" \
846
+ # -H "Authorization: token xxxxxxxxxxxx" \
847
+ # -d '{ "key_pair.description": "FooBarBaz" }' \
848
+ # https://api.travis-ci.com/repo/1234/key_pair
849
+ # ```
850
+ #
851
+ # PATCH <code>/repo/{repository.id}/key_pair</code>
852
+ #
853
+ # Template Variable Type Description
854
+ # repository.id Integer Value uniquely identifying the repository.
855
+ # Accepted Parameter Type Description
856
+ # key_pair.description String A text description.
857
+ # key_pair.value String The private key.
858
+ #
859
+ # Example: PATCH /repo/891/key_pair
860
+ #
861
+ # PATCH <code>/repo/{repository.slug}/key_pair</code>
862
+ #
863
+ # Template Variable Type Description
864
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
865
+ # Accepted Parameter Type Description
866
+ # key_pair.description String A text description.
867
+ # key_pair.value String The private key.
868
+ #
869
+ # Example: PATCH /repo/rails%2Frails/key_pair
870
+ #
871
+ # **Delete**
872
+ #
873
+ # Delete the key pair.
874
+ #
875
+ # DELETE <code>/repo/{repository.id}/key_pair</code>
876
+ #
877
+ # Template Variable Type Description
878
+ # repository.id Integer Value uniquely identifying the repository.
879
+ #
880
+ # Example: DELETE /repo/891/key_pair
881
+ #
882
+ # DELETE <code>/repo/{repository.slug}/key_pair</code>
883
+ #
884
+ # Template Variable Type Description
885
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
886
+ #
887
+ # Example: DELETE /repo/rails%2Frails/key_pair
888
+ #
889
+ # @note requests require an authorization token set in the headers. See: {h}
890
+ # @note API enpoint needs to be set to `https://api.travis-ci.com` See: {api_endpoint=}
891
+ #
892
+ # @overload key_par()
893
+ # Gets current key_pair if any
894
+ # @overload key_pair(action: params)
895
+ # Performs action per specific key word argument
896
+ # @param create [Hash] Create a new key pair from provided private key { description: "name", value: "private key" }
897
+ # @param update [Hash] Update key pair with hash { description: "new name" }
898
+ # @param delete [Boolean] Use truthy value to delete current key pair
899
+ # @return [Success, RequestError]
900
+ def key_pair(create: nil, update: nil, delete: nil)
901
+ raise 'Too many options specified' unless [create, update, delete].compact.count < 2
902
+
903
+ create and return create("#{with_repo}/key_pair", key_pair_keys(create))
904
+ update and return patch("#{with_repo}/key_pair", key_pair_keys(update))
905
+ delete and return delete("#{with_repo}/key_pair")
906
+ get("#{with_repo}/key_pair")
907
+ end
908
+
909
+ # Every repository has an auto-generated RSA key pair. This is used when cloning the repository from GitHub and when encrypting/decrypting secure data for use in builds, e.g. via the Travis CI command line client.
910
+ #
911
+ # Users may read the public key and fingerprint via GET request, or generate a new key pair via POST, but otherwise this key pair cannot be edited or removed.
912
+ #
913
+ # ## Attributes
914
+ #
915
+ # **Standard Representation**
916
+ #
917
+ # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
918
+ #
919
+ # Name Type Description
920
+ # description String A text description.
921
+ # public_key String The public key.
922
+ # fingerprint String The fingerprint.
923
+ #
924
+ # **Minimal Representation**
925
+ #
926
+ # Included when the resource is returned as part of another resource.
927
+ #
928
+ # Name Type Description
929
+ # description String A text description.
930
+ # public_key String The public key.
931
+ # fingerprint String The fingerprint.
932
+ #
933
+ # ## Actions
934
+ #
935
+ # **Find**
936
+ #
937
+ # Return the current key pair.
938
+ #
939
+ # GET <code>/repo/{repository.id}/key_pair/generated</code>
940
+ #
941
+ # Template Variable Type Description
942
+ # repository.id Integer Value uniquely identifying the repository.
943
+ # Query Parameter Type Description
944
+ # include [String] List of attributes to eager load.
945
+ #
946
+ # Example: GET /repo/891/key_pair/generated
947
+ #
948
+ # GET <code>/repo/{repository.slug}/key_pair/generated</code>
949
+ #
950
+ # Template Variable Type Description
951
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
952
+ # Query Parameter Type Description
953
+ # include [String] List of attributes to eager load.
954
+ #
955
+ # Example: GET /repo/rails%2Frails/key_pair/generated
956
+ #
957
+ # **Create**
958
+ #
959
+ # Generate a new key pair, replacing the previous one.
960
+ #
961
+ # POST <code>/repo/{repository.id}/key_pair/generated</code>
962
+ #
963
+ # Template Variable Type Description
964
+ # repository.id Integer Value uniquely identifying the repository.
965
+ #
966
+ # Example: POST /repo/891/key_pair/generated
967
+ #
968
+ # POST <code>/repo/{repository.slug}/key_pair/generated</code>
969
+ #
970
+ # Template Variable Type Description
971
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
972
+ #
973
+ # Example: POST /repo/rails%2Frails/key_pair/generated
974
+ #
975
+ # @note requests require an authorization token set in the headers. See: {h}
976
+ #
977
+ # @param action [String, Symbol] defaults to getting current key pair, use `:create` if you would like to generate a new key pair
978
+ # @return [Success, RequestError]
979
+ def key_pair_generated(action = :get)
980
+ return post("#{with_repo}/key_pair/generated") if action.match?(/create/i)
981
+
982
+ get("#{with_repo}/key_pair/generated")
983
+ end
984
+
749
985
  # This validates the `.travis.yml` file and returns any warnings.
750
986
  #
751
987
  # The request body can contain the content of the .travis.yml file directly as a string, eg "foo: bar".
@@ -863,6 +1099,58 @@ module Trav3
863
1099
  end
864
1100
  end
865
1101
 
1102
+ # A list of messages. Messages belong to resource types.
1103
+ #
1104
+ # ## Attributes
1105
+ #
1106
+ # Name Type Description
1107
+ # messages [Message] List of messages.
1108
+ #
1109
+ # **Collection Items**
1110
+ #
1111
+ # Each entry in the messages array has the following attributes:
1112
+ #
1113
+ # Name Type Description
1114
+ # id Integer The message's id.
1115
+ # level String The message's level.
1116
+ # key String The message's key.
1117
+ # code String The message's code.
1118
+ # args Json The message's args.
1119
+ #
1120
+ # ## Actions
1121
+ #
1122
+ # **For Request**
1123
+ #
1124
+ # This will return a list of messages created by `travis-yml` for a request, if any exist.
1125
+ #
1126
+ # GET <code>/repo/{repository.id}/request/{request.id}/messages</code>
1127
+ #
1128
+ # Template Variable Type Description
1129
+ # repository.id Integer Value uniquely identifying the repository.
1130
+ # request.id Integer Value uniquely identifying the request.
1131
+ # Query Parameter Type Description
1132
+ # include [String] List of attributes to eager load.
1133
+ # limit Integer How many messages to include in the response. Used for pagination.
1134
+ # offset Integer How many messages to skip before the first entry in the response. Used for pagination.
1135
+ #
1136
+ # GET <code>/repo/{repository.slug}/request/{request.id}/messages</code>
1137
+ #
1138
+ # Template Variable Type Description
1139
+ # repository.slug String Same as {repository.owner.name}/{repository.name}.
1140
+ # request.id Integer Value uniquely identifying the request.
1141
+ # Query Parameter Type Description
1142
+ # include [String] List of attributes to eager load.
1143
+ # limit Integer How many messages to include in the response. Used for pagination.
1144
+ # offset Integer How many messages to skip before the first entry in the response. Used for pagination.
1145
+ #
1146
+ # @param request_id [String, Integer] the request id
1147
+ # @return [Success, RequestError]
1148
+ def messages(request_id)
1149
+ validate_number request_id
1150
+
1151
+ get("#{with_repo}/request/#{request_id}/messages")
1152
+ end
1153
+
866
1154
  # An individual organization.
867
1155
  #
868
1156
  # ## Attributes
@@ -1113,6 +1401,8 @@ module Trav3
1113
1401
  # Query Parameter Type Description
1114
1402
  # include [String] List of attributes to eager load.
1115
1403
  #
1404
+ # @note requests require an authorization token set in the headers. See: {h}
1405
+ #
1116
1406
  # @param key [String] preference name to get or set
1117
1407
  # @param value [String] optional value to set preference
1118
1408
  # @param org_id [String, Integer] optional keyword argument for an organization id
@@ -1163,6 +1453,8 @@ module Trav3
1163
1453
  #
1164
1454
  # Example: GET /preferences
1165
1455
  #
1456
+ # @note requests require an authorization token set in the headers. See: {h}
1457
+ #
1166
1458
  # @param org_id [String, Integer] optional organization id
1167
1459
  # @return [Success, RequestError]
1168
1460
  def preferences(org_id = nil)
@@ -1950,8 +2242,8 @@ module Trav3
1950
2242
 
1951
2243
  private # @private
1952
2244
 
1953
- def create(url, **data)
1954
- Trav3::REST.create(self, url, **data)
2245
+ def create(url, data = {})
2246
+ Trav3::REST.create(self, url, data)
1955
2247
  end
1956
2248
 
1957
2249
  def delete(url)
@@ -1981,6 +2273,10 @@ module Trav3
1981
2273
  h('Travis-API-Version': 3)
1982
2274
  end
1983
2275
 
2276
+ def key_pair_keys(hash)
2277
+ hash.map { |k, v| ["key_pair.#{k}", v] }.to_h unless hash.keys.first.match?(/key_pair\.\w+/)
2278
+ end
2279
+
1984
2280
  def number?(input)
1985
2281
  /^\d+$/.match? input.to_s
1986
2282
  end
@@ -2014,7 +2310,7 @@ module Trav3
2014
2310
  end
2015
2311
 
2016
2312
  def repo_slug_or_id?(input)
2017
- Regexp.new(/(^\d+$)|(^\w+(?:\/|%2F){1}\w+$)/).match? input
2313
+ Regexp.new(/(^\d+$)|(^[A-Za-z0-9_.-]+(?:\/|%2F){1}[A-Za-z0-9_.-]+$)/i).match? input
2018
2314
  end
2019
2315
 
2020
2316
  def repository_name
@@ -16,7 +16,7 @@ module Trav3
16
16
  @travis = travis
17
17
  @response = response
18
18
  @collection = begin
19
- result = JSON.parse(response.body)
19
+ result = JSON.parse(response&.body || '{}')
20
20
  ResponseCollection.new(travis, result)
21
21
  rescue JSON::ParserError
22
22
  response.error!
@@ -3,7 +3,7 @@
3
3
  module Trav3
4
4
  class ResponseCollection
5
5
  extend Forwardable
6
- def_delegators :@collection, :count, :keys, :values, :has_key?, :key?
6
+ def_delegators :@collection, :count, :keys, :values, :has_key?, :key?, :empty?
7
7
  def initialize(travis, collection)
8
8
  @travis = travis
9
9
  @collection = collection
@@ -6,8 +6,9 @@ require 'json'
6
6
 
7
7
  module Trav3
8
8
  module REST
9
+ extend Net
9
10
  class << self
10
- def create(travis, url, **data)
11
+ def create(travis, url, data)
11
12
  uri = as_uri url
12
13
  req = request_post uri
13
14
  set_headers travis, req
@@ -64,13 +65,13 @@ module Trav3
64
65
  end
65
66
 
66
67
  def get_response(uri, request)
67
- http = Net::HTTP.new(uri.host, uri.port)
68
+ http = HTTP.new(uri.host, uri.port)
68
69
  http.use_ssl = (uri.scheme == 'https')
69
70
  http.request(request)
70
71
  end
71
72
 
72
73
  def output(travis, response)
73
- if [Net::HTTPAccepted, Net::HTTPOK].include? response.code_type
74
+ if [HTTPAccepted, HTTPOK, HTTPCreated, HTTPNoContent].include? response.code_type
74
75
  Success.new(travis, response)
75
76
  else
76
77
  RequestError.new(travis, response)
@@ -78,19 +79,19 @@ module Trav3
78
79
  end
79
80
 
80
81
  def request_delete(uri)
81
- Net::HTTP::Delete.new(uri.request_uri)
82
+ HTTP::Delete.new(uri.request_uri)
82
83
  end
83
84
 
84
85
  def request_get(uri)
85
- Net::HTTP::Get.new(uri.request_uri)
86
+ HTTP::Get.new(uri.request_uri)
86
87
  end
87
88
 
88
89
  def request_patch(uri)
89
- Net::HTTP::Patch.new(uri.request_uri)
90
+ HTTP::Patch.new(uri.request_uri)
90
91
  end
91
92
 
92
93
  def request_post(uri)
93
- Net::HTTP::Post.new(uri.request_uri)
94
+ HTTP::Post.new(uri.request_uri)
94
95
  end
95
96
 
96
97
  def set_headers(travis, request)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Trav3
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trav3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel P. Clark
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-24 00:00:00.000000000 Z
11
+ date: 2019-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler