Class: Trav3::Travis

Inherits:
Object
  • Object
show all
Defined in:
lib/trav3.rb

Overview

An abstraction for the Travis CI v3 API

rubocop:disable Metrics/ClassLength

Author:

Constant Summary collapse

API_ENDPOINT =
API_ROOT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Travis

Parameters:

  • repo (String)

    github_username/repository_name

Raises:

  • (InvalidRepository)

    if given input does not conform to valid repository identifier format


35
36
37
38
39
40
41
42
# File 'lib/trav3.rb', line 35

def initialize(repo)
  raise InvalidRepository unless repo_slug_or_id? repo

  @api_endpoint = API_ENDPOINT
  @repo = sanitize_repo_name repo

  initial_defaults
end

Instance Attribute Details

#api_endpointString

Returns API endpoint

Returns:

  • (String)

    API endpoint


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
# File 'lib/trav3.rb', line 25

class Travis
  API_ENDPOINT = API_ROOT
  attr_reader :api_endpoint
  attr_reader :options
  attr_reader :headers

  # @param repo [String] github_username/repository_name
  # @raise [InvalidRepository] if given input does not
  #   conform to valid repository identifier format
  # @return [Travis]
  def initialize(repo)
    raise InvalidRepository unless repo_slug_or_id? repo

    @api_endpoint = API_ENDPOINT
    @repo = sanitize_repo_name repo

    initial_defaults
  end

  # @overload api_endpoint=(endpoint)
  #   Set as the API endpoint
  #   @param endpoint [String] name for value to set
  # @return [self]
  # rubocop:disable Lint/Void
  def api_endpoint=(endpoint)
    raise InvalidAPIEndpoint unless /^https:\/\/api\.travis-ci\.(?:org|com)$/.match? endpoint

    @api_endpoint = endpoint

    self
  end
  # rubocop:enable Lint/Void

  # @overload defaults(key: value, ...)
  #   Set as many options as you'd like for collections queried via an API request
  #   @param key [Symbol, String] name for value to set
  #   @param value [Symbol, String, Integer] value for key
  # @return [self]
  def defaults(**args)
    (@options ||= Options.new).build(**args)
    self
  end

  # Set as many headers as you'd like for API requests
  #
  #     h("Authorization": "token xxxxxxxxxxxxxxxxxxxxxx")
  #
  # @overload h(key: value, ...)
  #   @param key [Symbol, String] name for value to set
  #   @param value [Symbol, String, Integer] value for key
  # @return [self]
  def h(**args)
    (@headers ||= Headers.new).build(**args)
    self
  end

  # The branch of a GitHub repository. Useful for obtaining information about the last build on a given branch.
  #
  # **If querying using the repository slug, it must be formatted using {http://www.w3schools.com/tags/ref_urlencode.asp standard URL encoding}, including any special characters.**
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type    Description
  #     name  String  Name of the git branch.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
  #
  #     Name              Type        Description
  #     name              String      Name of the git branch.
  #     repository        Repository  GitHub user or organization the branch belongs to.
  #     default_branch    Boolean     Whether or not this is the resposiotry's default branch.
  #     exists_on_github  Boolean     Whether or not the branch still exists on GitHub.
  #     last_build        Build       Last build on the branch.
  #
  # **Additional Attributes**
  #
  #     Name           Type     Description
  #     recent_builds  [Build]  Last 10 builds on the branch (when `include=branch.recent_builds` is used).
  #
  # ## Actions
  #
  # **Find**
  #
  # This will return information about an individual branch. The request can include either the repository id or slug.
  #
  # GET <code>/repo/{repository.id}/branch/{branch.name}</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #     branch.name        String   Name of the git branch.
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /repo/891/branch/master
  #
  # GET <code>/repo/{repository.slug}/branch/{branch.name}</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #     branch.name        String  Name of the git branch.
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /repo/rails%2Frails/branch/master
  #
  # @param id [String] the branch name for the current repository
  # @return [Success, RequestError]
  def branch(name)
    get("#{with_repo}/branch/#{name}#{opts}")
  end

  # A list of branches.
  #
  # **If querying using the repository slug, it must be formatted using {http://www.w3schools.com/tags/ref_urlencode.asp standard URL encoding}, including any special characters.**
  #
  # ##Attributes
  #
  #     Name      Type      Description
  #     branches  [Branch]  List of branches.
  #
  # **Collection Items**
  #
  # Each entry in the **branches** array has the following attributes:
  #
  #     Name              Type        Description
  #     name              String      Name of the git branch.
  #     repository        Repository  GitHub user or organization the branch belongs to.
  #     default_branch    Boolean     Whether or not this is the resposiotry's default branch.
  #     exists_on_github  Boolean     Whether or not the branch still exists on GitHub.
  #     last_build        Build       Last build on the branch.
  #     recent_builds    [Build]      Last 10 builds on the branch (when `include=branch.recent_builds` is used).
  #
  # ## Actions
  #
  # **Find**
  #
  # This will return a list of branches a repository has on GitHub.
  #
  # GET <code>/repo/{repository.id}/branches</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #     Query Parameter          Type       Description
  #     branch.exists_on_github  [Boolean]  Filters branches by whether or not the branch still exists on GitHub.
  #     exists_on_github         [Boolean]  Alias for branch.exists_on_github.
  #     include                  [String]   List of attributes to eager load.
  #     limit                    Integer    How many branches to include in the response. Used for pagination.
  #     offset                   Integer    How many branches to skip before the first entry in the response. Used for pagination.
  #     sort_by                  [String]   Attributes to sort branches by. Used for pagination.
  #
  #     Example:GET /repo/891/branches?limit=5&exists_on_github=true
  #
  # **Sortable by:** <code>name</code>, <code>last_build</code>, <code>exists_on_github</code>, <code>default_branch</code>, append <code>:desc</code> to any attribute to reverse order.
  # The default value is <code>default_branch</code>,<code>exists_on_github</code>,<code>last_build:desc</code>.
  #
  # GET <code>/repo/{repository.slug}/branches</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #     Query Parameter          Type       Description
  #     branch.exists_on_github  [Boolean]  Filters branches by whether or not the branch still exists on GitHub.
  #     exists_on_github         [Boolean]  Alias for branch.exists_on_github.
  #     include                  [String]   List of attributes to eager load.
  #     limit                    Integer    How many branches to include in the response. Used for pagination.
  #     offset                   Integer    How many branches to skip before the first entry in the response. Used for pagination.
  #     sort_by                  [String]   Attributes to sort branches by. Used for pagination.
  #
  #     Example:GET /repo/rails%2Frails/branches?limit=5&exists_on_github=true
  #
  # **Sortable by:** <code>name</code>, <code>last_build</code>, <code>exists_on_github</code>, <code>default_branch</code>, append <code>:desc</code> to any attribute to reverse order.
  # The default value is <code>default_branch</code>,<code>exists_on_github</code>,<code>last_build:desc</code>.
  #
  # @return [Success, RequestError]
  def branches
    get("#{with_repo}/branches#{opts}")
  end

  # An individual build.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name                 Type     Description
  #     id                   Integer  Value uniquely identifying the build.
  #     number               String   Incremental number for a repository's builds.
  #     state                String   Current state of the build.
  #     duration             Integer  Wall clock time in seconds.
  #     event_type           String   Event that triggered the build.
  #     previous_state       String   State of the previous build (useful to see if state changed).
  #     pull_request_title   String   Title of the build's pull request.
  #     pull_request_number  Integer  Number of the build's pull request.
  #     started_at           String   When the build started.
  #     finished_at          String   When the build finished.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name                 Type        Description
  #     id                   Integer     Value uniquely identifying the build.
  #     number               String      Incremental number for a repository's builds.
  #     state                String      Current state of the build.
  #     duration             Integer     Wall clock time in seconds.
  #     event_type           String      Event that triggered the build.
  #     previous_state       String      State of the previous build (useful to see if state changed).
  #     pull_request_title   String      Title of the build's pull request.
  #     pull_request_number  Integer     Number of the build's pull request.
  #     started_at           String      When the build started.
  #     finished_at          String      When the build finished.
  #     repository           Repository  GitHub user or organization the build belongs to.
  #     branch               Branch      The branch the build is associated with.
  #     tag                  Unknown     The build's tag.
  #     commit               Commit      The commit the build is associated with.
  #     jobs                 Jobs        List of jobs that are part of the build's matrix.
  #     stages               [Stage]     The stages of a build.
  #     created_by           Owner       The User or Organization that created the build.
  #     updated_at           Unknown     The build's updated_at.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a single build.
  #
  # GET <code>/build/{build.id}</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /build/86601346
  #
  # **Cancel**
  #
  # This cancels a currently running build. It will set the build and associated jobs to "state": "canceled".
  #
  # POST <code>/build/{build.id}/cancel</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Example: POST /build/86601346/cancel
  #
  # **Restart**
  #
  # This restarts a build that has completed or been canceled.
  #
  # POST <code>/build/{build.id}/restart</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Example: POST /build/86601346/restart
  #
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param id [String, Integer] the build id number
  # @return [Success, RequestError]
  def build(id)
    get("#{without_repo}/build/#{id}")
  end

  # A list of builds.
  #
  # ## Attributes
  #
  #     Name    Type     Description
  #     builds  [Build]  List of builds.
  #
  # **Collection Items**
  #
  # Each entry in the builds array has the following attributes:
  #
  #     Name                 Type        Description
  #     id                   Integer     Value uniquely identifying the build.
  #     number               String      Incremental number for a repository's builds.
  #     state                String      Current state of the build.
  #     duration             Integer     Wall clock time in seconds.
  #     event_type           String      Event that triggered the build.
  #     previous_state       String      State of the previous build (useful to see if state changed).
  #     pull_request_title   String      Title of the build's pull request.
  #     pull_request_number  Integer     Number of the build's pull request.
  #     started_at           String      When the build started.
  #     finished_at          String      When the build finished.
  #     repository           Repository  GitHub user or organization the build belongs to.
  #     branch               Branch      The branch the build is associated with.
  #     tag                  Unknown     The build's tag.
  #     commit               Commit      The commit the build is associated with.
  #     jobs                 Jobs        List of jobs that are part of the build's matrix.
  #     stages               [Stage]     The stages of a build.
  #     created_by           Owner       The User or Organization that created the build.
  #     updated_at           Unknown     The build's updated_at.
  #     request              Unknown     The build's request.
  #
  # ## Actions
  #
  # **For Current User**
  #
  # This returns a list of builds for the current user. The result is paginated.
  #
  # GET <code>/builds</code>
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #     limit            Integer   How many builds to include in the response. Used for pagination.
  #     limit            Integer   How many builds to include in the response. Used for pagination.
  #     offset           Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     offset           Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     sort_by          [String]  Attributes to sort builds by. Used for pagination.
  #     sort_by          [String]  Attributes to sort builds by. Used for pagination.
  #
  #     Example: GET /builds?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>started_at</code>, <code>finished_at</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # **Find**
  #
  # This returns a list of builds for an individual repository. It is possible to use the repository id or slug in the request. The result is paginated. Each request will return 25 results.
  #
  # GET <code>/repo/{repository.id}/builds</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Query Parameter       Type      Description
  #     branch.name           [String]  Filters builds by name of the git branch.
  #     build.created_by      [Owner]   Filters builds by the User or Organization that created the build.
  #     build.event_type      [String]  Filters builds by event that triggered the build.
  #     build.previous_state  [String]  Filters builds by state of the previous build (useful to see if state changed).
  #     build.state           [String]  Filters builds by current state of the build.
  #     created_by            [Owner]   Alias for build.created_by.
  #     event_type            [String]  Alias for build.event_type.
  #     include               [String]  List of attributes to eager load.
  #     limit                 Integer   How many builds to include in the response. Used for pagination.
  #     offset                Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     previous_state        [String]  Alias for build.previous_state.
  #     sort_by               [String]  Attributes to sort builds by. Used for pagination.
  #     state                 [String]  Alias for build.state.
  #
  #     Example: GET /repo/891/builds?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>started_at</code>, <code>finished_at</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/repo/{repository.slug}/builds</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Query Parameter       Type      Description
  #     branch.name           [String]  Filters builds by name of the git branch.
  #     build.created_by      [Owner]   Filters builds by the User or Organization that created the build.
  #     build.event_type      [String]  Filters builds by event that triggered the build.
  #     build.previous_state  [String]  Filters builds by state of the previous build (useful to see if state changed).
  #     build.state           [String]  Filters builds by current state of the build.
  #     created_by            [Owner]   Alias for build.created_by.
  #     event_type            [String]  Alias for build.event_type.
  #     include               [String]  List of attributes to eager load.
  #     limit                 Integer   How many builds to include in the response. Used for pagination.
  #     offset                Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     previous_state        [String]  Alias for build.previous_state.
  #     sort_by               [String]  Attributes to sort builds by. Used for pagination.
  #     state                 [String]  Alias for build.state.
  #
  #     Example: GET /repo/rails%2Frails/builds?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>started_at</code>, <code>finished_at</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # @return [Success, RequestError]
  def builds
    get("#{with_repo}/builds#{opts}")
  end

  # A list of jobs.
  #
  # ## Attributes
  #
  #     Name  Type  Description
  #     jobs  [Job]  List of jobs.
  #
  # **Collection Items**
  #
  # Each entry in the jobs array has the following attributes:
  #
  #     Name           Type        Description
  #     id             Integer     Value uniquely identifying the job.
  #     allow_failure  Unknown     The job's allow_failure.
  #     number         String      Incremental number for a repository's builds.
  #     state          String      Current state of the job.
  #     started_at     String      When the job started.
  #     finished_at    String      When the job finished.
  #     build          Build       The build the job is associated with.
  #     queue          String      Worker queue this job is/was scheduled on.
  #     repository     Repository  GitHub user or organization the job belongs to.
  #     commit         Commit      The commit the job is associated with.
  #     owner          Owner       GitHub user or organization the job belongs to.
  #     stage          [Stage]     The stages of a job.
  #     created_at     String      When the job was created.
  #     updated_at     String      When the job was updated.
  #     config         Object      The job's config.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a list of jobs belonging to an individual build.
  #
  # GET <code>/build/{build.id}/jobs</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /build/86601346/jobs
  #
  # **For Current User**
  #
  # This returns a list of jobs a current user has access to.
  #
  # GET <code>/jobs</code>
  #
  #     Query Parameter  Type      Description
  #     active           Unknown   Alias for job.active.
  #     created_by       Unknown   Alias for job.created_by.
  #     include          [String]  List of attributes to eager load.
  #     job.active       Unknown   Documentation missing.
  #     job.created_by   Unknown   Documentation missing.
  #     job.state        [String]  Filters jobs by current state of the job.
  #     limit            Integer   How many jobs to include in the response. Used for pagination.
  #     offset           Integer   How many jobs to skip before the first entry in the response. Used for pagination.
  #     sort_by          [String]  Attributes to sort jobs by. Used for pagination.
  #     state            [String]  Alias for job.state.
  #
  #     Example: GET /jobs?limit=5
  #
  # **Sortable by:** <code>id</code>, append <code>:desc</code> to any attribute to reverse order.
  # The default value is id:desc.
  #
  # @param id [String, Integer] the build id number
  # @return [Success, RequestError]
  def build_jobs(id)
    get("#{without_repo}/build/#{id}/jobs")
  end

  # An individual job.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type     Description
  #     id    Integer  Value uniquely identifying the job.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name           Type        Description
  #     id             Integer     Value uniquely identifying the job.
  #     allow_failure  Unknown     The job's allow_failure.
  #     number         String      Incremental number for a repository's builds.
  #     state          String      Current state of the job.
  #     started_at     String      When the job started.
  #     finished_at    String      When the job finished.
  #     build          Build       The build the job is associated with.
  #     queue          String      Worker queue this job is/was scheduled on.
  #     repository     Repository  GitHub user or organization the job belongs to.
  #     commit         Commit      The commit the job is associated with.
  #     owner          Owner       GitHub user or organization the job belongs to.
  #     stage          [Stage]     The stages of a job.
  #     created_at     String      When the job was created.
  #     updated_at     String      When the job was updated.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a single job.
  #
  # GET <code>/job/{job.id}</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /job/86601347
  #
  # **Cancel**
  #
  # This cancels a currently running job.
  #
  # POST <code>/job/{job.id}/cancel</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: POST /job/86601347/cancel
  #
  # **Restart**
  #
  # This restarts a job that has completed or been canceled.
  #
  # POST <code>/job/{job.id}/restart</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: POST /job/86601347/restart
  #
  # **Debug**
  #
  # This restarts a job in debug mode, enabling the logged-in user to ssh into the build VM. Please note this feature is only available on the travis-ci.com domain, and those repositories on the travis-ci.org domain for which the debug feature is enabled. See this document for more details.
  #
  # POST <code>/job/{job.id}/debug</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: POST /job/86601347/debug
  #
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param id [String, Integer] the job id number
  # @param option [Symbol] options for :cancel, :restart, or :debug
  # @return [Success, RequestError]
  def job(id, option = nil)
    case option
    when :cancel
      post("#{without_repo}/job/#{id}/cancel")
    when :restart
      post("#{without_repo}/job/#{id}/restart")
    when :debug
      post("#{without_repo}/job/#{id}/debug")
    else
      get("#{without_repo}/job/#{id}")
    end
  end

  # This validates the `.travis.yml` file and returns any warnings.
  #
  # The request body can contain the content of the .travis.yml file directly as a string, eg "foo: bar".
  #
  # ## Attributes
  #
  #     Name      Type   Description
  #     warnings  Array  An array of hashes with keys and warnings.
  #
  # ## Actions
  #
  # **Lint**
  #
  # POST <code>/lint</code>
  #
  #     Example:POST /lint
  #
  # @param yaml_content [String] the contents for the file `.travis.yml`
  # @return [Success, RequestError]
  def lint(yaml_content)
    raise TypeError, "String expected, #{yaml_content.class} given" unless \
      yaml_content.is_a? String

    ct = headers.remove(:'Content-Type')
    result = post("#{without_repo}/lint", body: yaml_content)
    h('Content-Type': ct) if ct
    result
  end

  # An individual log.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type     Description
  #     id    Unknown  The log's id.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name       Type     Description
  #     id         Unknown  The log's id.
  #     content    Unknown  The log's content.
  #     log_parts  Unknown  The log's log_parts.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a single log.
  #
  # It's possible to specify the accept format of the request as text/plain if required. This will return the content of the log as a single blob of text.
  #
  #     curl -H "Travis-API-Version: 3" \
  #       -H "Accept: text/plain" \
  #       -H "Authorization: token xxxxxxxxxxxx" \
  #       https://api.travis-ci.org/job/{job.id}/log
  #
  # The default response type is application/json, and will include additional meta data such as @type, @representation etc. (see [https://developer.travis-ci.org/format](https://developer.travis-ci.org/format)).
  #
  # GET <code>/job/{job.id}/log</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #     log.token        Unknown   Documentation missing.
  #
  #     Example: GET /job/86601347/log
  #
  # GET <code>/job/{job.id}/log.txt</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #     log.token        Unknown   Documentation missing.
  #
  #     Example:GET /job/86601347/log.txt
  #
  # **Delete**
  #
  # This removes the contents of a log. It gets replace with the message: Log removed by XXX at 2017-02-13 16:00:00 UTC.
  #
  #     curl -X DELETE \
  #       -H "Travis-API-Version: 3" \
  #       -H "Authorization: token xxxxxxxxxxxx" \
  #       https://api.travis-ci.org/job/{job.id}/log
  #
  # DELETE <code>/job/{job.id}/log</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: DELETE /job/86601347/log
  #
  # @note DELETE is unimplemented
  #
  # @param id [String, Integer] the job id number
  # @param option [Symbol] options for :text or :delete
  # @return [Success, String, RequestError]
  def log(id, option = nil)
    case option
    when :text
      get("#{without_repo}/job/#{id}/log.txt", true)
    when :delete
      raise Unimplemented
    else
      get("#{without_repo}/job/#{id}/log")
    end
  end

  # An individual organization.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name   Type     Description
  #     id     Integer  Value uniquely identifying the organization.
  #     login  String   Login set on GitHub.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
  #
  #     Name             Type     Description
  #     id               Integer  Value uniquely identifying the organization.
  #     login            String   Login set on GitHub.
  #     name             String   Name set on GitHub.
  #     github_id        Integer  Id set on GitHub.
  #     avatar_url       String   Avatar_url set on GitHub.
  #     education        Boolean  Whether or not the organization has an education account.
  #     allow_migration  Unknown  The organization's allow_migration.
  #
  # **Additional Attributes**
  #
  #     Name          Type          Description
  #     repositories  [Repository]  Repositories belonging to this organization.
  #     installation  Installation  Installation belonging to the organization.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns an individual organization.
  #
  # GET <code>/org/{organization.id}</code>
  #
  #     Template Variable  Type      Description
  #     organization.id    Integer   Value uniquely identifying the organization.
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #
  #     Example:GET /org/87
  #
  # @param org_id [String, Integer] the organization id
  # @raise [TypeError] if given organization id is not a number
  # @return [Success, RequestError]
  def organization(org_id)
    raise TypeError, 'Integer expected for organization id' unless /^\d+$/.match? org_id.to_s

    get("#{without_repo}/org/#{org_id}")
  end

  # A list of organizations for the current user.
  #
  # ## Attributes
  #
  #     Name           Type            Description
  #     organizations  [Organization]  List of organizations.
  #
  # **Collection Items**
  #
  # Each entry in the **organizations** array has the following attributes:
  #
  #     Name             Type          Description
  #     id               Integer       Value uniquely identifying the organization.
  #     login            String        Login set on GitHub.
  #     name             String        Name set on GitHub.
  #     github_id        Integer       Id set on GitHub.
  #     avatar_url       String        Avatar_url set on GitHub.
  #     education        Boolean       Whether or not the organization has an education account.
  #     allow_migration  Unknown       The organization's allow_migration.
  #     repositories     [Repository]  Repositories belonging to this organization.
  #     installation     Installation  Installation belonging to the organization.
  #
  # ## Actions
  #
  # **For Current User**
  #
  # This returns a list of organizations the current user is a member of.
  #
  # GET <code>/orgs</code>
  #
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #     limit              Integer   How many organizations to include in the response. Used for pagination.
  #     offset             Integer   How many organizations to skip before the first entry in the response. Used for pagination.
  #     organization.role  Unknown   Documentation missing.
  #     role               Unknown   Alias for organization.role.
  #     sort_by            [String]  Attributes to sort organizations by. Used for pagination.
  #
  #     Example:GET /orgs?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>login</code>, <code>name</code>, <code>github_id</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # @return [Success, RequestError]
  def organizations
    get("#{without_repo}/orgs")
  end

  # This will be either a user or organization.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name    Type     Description
  #     id      Integer  Value uniquely identifying the owner.
  #     login   String   User or organization login set on GitHub.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name        Type     Description
  #     id          Integer  Value uniquely identifying the owner.
  #     login       String   User or organization login set on GitHub.
  #     name        String   User or organization name set on GitHub.
  #     github_id   Integer  User or organization id set on GitHub.
  #     avatar_url  String   Link to user or organization avatar (image) set on GitHub.
  #
  # **Additional Attributes**
  #
  #     Name           Type           Description
  #     repositories   [Repository]   Repositories belonging to this account.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns an individual owner. It is possible to use the GitHub login or github_id in the request.
  #
  # GET <code>/owner/{owner.login}</code>
  #
  #     Template Variable  Type      Description
  #     owner.login        String    User or organization login set on GitHub.
  #
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/danielpclark
  #
  # GET <code>/owner/{user.login}</code>
  #
  #     Template Variable  Type      Description
  #     user.login         String    Login set on Github.
  #
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/danielpclark
  #
  # GET <code>/owner/{organization.login}</code>
  #
  #     Template Variable   Type      Description
  #     organization.login  String    Login set on GitHub.
  #
  #     Query Parameter     Type      Description
  #     include             [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/travis-ci
  #
  # GET <code>/owner/github_id/{owner.github_id}</code>
  #
  #     Template Variable   Type      Description
  #     owner.github_id     Integer   User or organization id set on GitHub.
  #
  #     Query Parameter     Type      Description
  #     include             [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/github_id/639823
  #
  # @param owner [String] username or github ID
  # @return [Success, RequestError]
  def owner(owner = username)
    if /^\d+$/.match? owner.to_s
      get("#{without_repo}/owner/github_id/#{owner}")
    else
      get("#{without_repo}/owner/#{owner}")
    end
  end

  # A list of repositories for the current user.
  #
  # ## Attributes
  #
  #     Name           Type           Description
  #     repositories   [Repository]   List of repositories.
  #
  # **Collection Items**
  #
  # Each entry in the repositories array has the following attributes:
  #
  #     Name                Type     Description
  #     id                  Integer  Value uniquely identifying the repository.
  #     name                String   The repository's name on GitHub.
  #     slug                String   Same as {repository.owner.name}/{repository.name}.
  #     description         String   The repository's description from GitHub.
  #     github_language     String   The main programming language used according to GitHub.
  #     active              Boolean  Whether or not this repository is currently enabled on Travis CI.
  #     private             Boolean  Whether or not this repository is private.
  #     owner               Owner    GitHub user or organization the repository belongs to.
  #     default_branch      Branch   The default branch on GitHub.
  #     starred             Boolean  Whether or not this repository is starred.
  #     current_build       Build    The most recently started build (this excludes builds that have been created but have not yet started).
  #     last_started_build  Build    Alias for current_build.
  #
  # ## Actions
  #
  # **For Owner**
  #
  # This returns a list of repositories an owner has access to.
  #
  # GET <code>/owner/{owner.login}/repos</code>
  #
  #     Template Variable  Type    Description
  #     owner.login        String  User or organization login set on GitHub.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/owner/{user.login}/repos</code>
  #
  #     Template Variable  Type    Description
  #     user.login         String  Login set on Github.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/owner/{organization.login}/repos</code>
  #
  #     Template Variable   Type    Description
  #     organization.login  String  Login set on GitHub.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/travis-ci/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/owner/github_id/{owner.github_id}/repos</code>
  #
  #     Template Variable  Type     Description
  #     owner.github_id    Integer  User or organization id set on GitHub.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/github_id/639823/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # **For Current User**<br />
  # This returns a list of repositories the current user has access to.
  #
  # GET <code>/repos</code>
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # @param owner [String] username or github ID
  # @return [Success, RequestError]
  def repositories(owner = username)
    if /^\d+$/.match? owner.to_s
      get("#{without_repo}/owner/github_id/#{owner}/repos#{opts}")
    else
      get("#{without_repo}/owner/#{owner}/repos#{opts}")
    end
  end

  # An individual repository.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name   Type     Description
  #     id     Integer  Value uniquely identifying the repository.
  #     name   String   The repository's name on GitHub.
  #     slug   String   Same as {repository.owner.name}/{repository.name}.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name             Type     Description
  #     id               Integer  Value uniquely identifying the repository.
  #     name             String   The repository's name on GitHub.
  #     slug             String   Same as {repository.owner.name}/{repository.name}.
  #     description      String   The repository's description from GitHub.
  #     github_language  String   The main programming language used according to GitHub.
  #     active           Boolean  Whether or not this repository is currently enabled on Travis CI.
  #     private          Boolean  Whether or not this repository is private.
  #     owner            Owner    GitHub user or organization the repository belongs to.
  #     default_branch   Branch   The default branch on GitHub.
  #     starred          Boolean  Whether or not this repository is starred.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns an individual repository.
  #
  # GET <code>/repo/{repository.id}</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /repo/891
  #
  # GET <code>/repo/{repository.slug}</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /repo/rails%2Frails
  #
  # **Activate**
  #
  # This will activate a repository, allowing its tests to be run on Travis CI.
  #
  # POST <code>/repo/{repository.id}/activate</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/activate
  #
  # POST <code>/repo/{repository.slug}/activate</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/activate
  #
  # **Deactivate**
  #
  # This will deactivate a repository, preventing any tests from running on Travis CI.
  #
  # POST <code>/repo/{repository.id}/deactivate</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/deactivate
  #
  # POST <code>/repo/{repository.slug}/deactivate</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/deactivate
  #
  # **Star**
  #
  # This will star a repository based on the currently logged in user.
  #
  # POST <code>/repo/{repository.id}/star</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/star
  #
  # POST <code>/repo/{repository.slug}/star</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/star
  #
  # **Unstar**
  #
  # This will unstar a repository based on the currently logged in user.
  #
  # POST <code>/repo/{repository.id}/unstar</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/unstar
  #
  # POST <code>/repo/{repository.slug}/unstar</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/unstar
  #
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param repo [String] github_username/repository_name
  # @param action [String, Symbol] Optional argument for star/unstar/activate/deactivate
  # @raise [InvalidRepository] if given input does not
  #   conform to valid repository identifier format
  # @return [Success, RequestError]
  def repository(repo = repository_name, action = nil)
    raise InvalidRepository unless repo_slug_or_id? repo

    repo = sanitize_repo_name repo
    action = '' unless %w[star unstar activate deavtivate].include? action.to_s

    if action.empty?
      get("#{without_repo}/repo/#{repo}")
    else
      post("#{without_repo}/repo/#{repo}/#{action}")
    end
  end

  # An individual user.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type     Description
  #     id    Integer  Value uniquely identifying the user.
  #     login String   Login set on Github.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
  #
  #     Name              Type     Description
  #     id                Integer  Value uniquely identifying the user.
  #     login             String   Login set on Github.
  #     name              String   Name set on GitHub.
  #     github_id         Integer  Id set on GitHub.
  #     avatar_url        String   Avatar URL set on GitHub.
  #     education         Boolean  Whether or not the user has an education account.
  #     allow_migration   Unknown  The user's allow_migration.
  #     is_syncing        Boolean  Whether or not the user is currently being synced with Github.
  #     synced_at         String   The last time the user was synced with GitHub.
  #
  # **Additional Attributes**
  #
  #     Name          Type          Description
  #     repositories  [Repository]  Repositories belonging to this user.
  #     installation  Installation  Installation belonging to the user.
  #     emails        Unknown       The user's emails.
  #
  # ## Actions
  #
  # **Find**
  #
  # This will return information about an individual user.
  #
  # GET <code>/user/{user.id}</code>
  #
  #     Template Variable  Type     Description
  #     user.id            Integer  Value uniquely identifying the user.
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /user/119240
  #
  # **Sync**
  #
  # This triggers a sync on a user's account with their GitHub account.
  #
  # POST <code>/user/{user.id}/sync</code>
  #
  #     Template Variable  Type     Description
  #     user.id            Integer  Value uniquely identifying the user.
  #
  #     Example:POST /user/119240/sync
  #
  # **Current**
  #
  # This will return information about the current user.
  #
  # GET <code>/user</code>
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /user
  #
  # @note sync feature may not be permitted
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param user_id [String, Integer] optional user id
  # @param sync [Boolean] optional argument for syncing your Travis CI account with Github
  # @raise [TypeError] if given user id is not a number
  # @return [Success, RequestError]
  def user(user_id = nil, sync = false)
    return get("#{without_repo}/user") if !user_id && !sync
    raise TypeError, 'Integer expected for user id' unless /^\d+$/.match? user_id.to_s

    if sync
      get("#{without_repo}/user/#{user_id}/sync")
    else
      get("#{without_repo}/user/#{user_id}")
    end
  end

  private # @private

  def get(url, raw_reply = false)
    Trav3::GET.call(self, url, raw_reply)
  end

  def initial_defaults
    defaults(limit: 25)
    h('Content-Type': 'application/json')
    h('Accept': 'application/json')
    h('Travis-API-Version': 3)
  end

  def opts
    @options
  end

  def post(url, fields = {})
    Trav3::POST.call(self, url, fields)
  end

  def repo_slug_or_id?(repo)
    Regexp.new(/(^\d+$)|(^\w+(?:\/|%2F){1}\w+$)/).match? repo
  end

  def repository_name
    @repo
  end

  def sanitize_repo_name(repo)
    repo.to_s.gsub(/\//, '%2F')
  end

  def username
    @repo[/.*?(?=(?:\/|%2F)|$)/]
  end

  def with_repo
    "#{api_endpoint}/repo/#{@repo}"
  end

  def without_repo
    api_endpoint
  end
end

#headersHeaders (readonly)

Returns Request headers object

Returns:

  • (Headers)

    Request headers object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
# File 'lib/trav3.rb', line 25

class Travis
  API_ENDPOINT = API_ROOT
  attr_reader :api_endpoint
  attr_reader :options
  attr_reader :headers

  # @param repo [String] github_username/repository_name
  # @raise [InvalidRepository] if given input does not
  #   conform to valid repository identifier format
  # @return [Travis]
  def initialize(repo)
    raise InvalidRepository unless repo_slug_or_id? repo

    @api_endpoint = API_ENDPOINT
    @repo = sanitize_repo_name repo

    initial_defaults
  end

  # @overload api_endpoint=(endpoint)
  #   Set as the API endpoint
  #   @param endpoint [String] name for value to set
  # @return [self]
  # rubocop:disable Lint/Void
  def api_endpoint=(endpoint)
    raise InvalidAPIEndpoint unless /^https:\/\/api\.travis-ci\.(?:org|com)$/.match? endpoint

    @api_endpoint = endpoint

    self
  end
  # rubocop:enable Lint/Void

  # @overload defaults(key: value, ...)
  #   Set as many options as you'd like for collections queried via an API request
  #   @param key [Symbol, String] name for value to set
  #   @param value [Symbol, String, Integer] value for key
  # @return [self]
  def defaults(**args)
    (@options ||= Options.new).build(**args)
    self
  end

  # Set as many headers as you'd like for API requests
  #
  #     h("Authorization": "token xxxxxxxxxxxxxxxxxxxxxx")
  #
  # @overload h(key: value, ...)
  #   @param key [Symbol, String] name for value to set
  #   @param value [Symbol, String, Integer] value for key
  # @return [self]
  def h(**args)
    (@headers ||= Headers.new).build(**args)
    self
  end

  # The branch of a GitHub repository. Useful for obtaining information about the last build on a given branch.
  #
  # **If querying using the repository slug, it must be formatted using {http://www.w3schools.com/tags/ref_urlencode.asp standard URL encoding}, including any special characters.**
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type    Description
  #     name  String  Name of the git branch.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
  #
  #     Name              Type        Description
  #     name              String      Name of the git branch.
  #     repository        Repository  GitHub user or organization the branch belongs to.
  #     default_branch    Boolean     Whether or not this is the resposiotry's default branch.
  #     exists_on_github  Boolean     Whether or not the branch still exists on GitHub.
  #     last_build        Build       Last build on the branch.
  #
  # **Additional Attributes**
  #
  #     Name           Type     Description
  #     recent_builds  [Build]  Last 10 builds on the branch (when `include=branch.recent_builds` is used).
  #
  # ## Actions
  #
  # **Find**
  #
  # This will return information about an individual branch. The request can include either the repository id or slug.
  #
  # GET <code>/repo/{repository.id}/branch/{branch.name}</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #     branch.name        String   Name of the git branch.
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /repo/891/branch/master
  #
  # GET <code>/repo/{repository.slug}/branch/{branch.name}</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #     branch.name        String  Name of the git branch.
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /repo/rails%2Frails/branch/master
  #
  # @param id [String] the branch name for the current repository
  # @return [Success, RequestError]
  def branch(name)
    get("#{with_repo}/branch/#{name}#{opts}")
  end

  # A list of branches.
  #
  # **If querying using the repository slug, it must be formatted using {http://www.w3schools.com/tags/ref_urlencode.asp standard URL encoding}, including any special characters.**
  #
  # ##Attributes
  #
  #     Name      Type      Description
  #     branches  [Branch]  List of branches.
  #
  # **Collection Items**
  #
  # Each entry in the **branches** array has the following attributes:
  #
  #     Name              Type        Description
  #     name              String      Name of the git branch.
  #     repository        Repository  GitHub user or organization the branch belongs to.
  #     default_branch    Boolean     Whether or not this is the resposiotry's default branch.
  #     exists_on_github  Boolean     Whether or not the branch still exists on GitHub.
  #     last_build        Build       Last build on the branch.
  #     recent_builds    [Build]      Last 10 builds on the branch (when `include=branch.recent_builds` is used).
  #
  # ## Actions
  #
  # **Find**
  #
  # This will return a list of branches a repository has on GitHub.
  #
  # GET <code>/repo/{repository.id}/branches</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #     Query Parameter          Type       Description
  #     branch.exists_on_github  [Boolean]  Filters branches by whether or not the branch still exists on GitHub.
  #     exists_on_github         [Boolean]  Alias for branch.exists_on_github.
  #     include                  [String]   List of attributes to eager load.
  #     limit                    Integer    How many branches to include in the response. Used for pagination.
  #     offset                   Integer    How many branches to skip before the first entry in the response. Used for pagination.
  #     sort_by                  [String]   Attributes to sort branches by. Used for pagination.
  #
  #     Example:GET /repo/891/branches?limit=5&exists_on_github=true
  #
  # **Sortable by:** <code>name</code>, <code>last_build</code>, <code>exists_on_github</code>, <code>default_branch</code>, append <code>:desc</code> to any attribute to reverse order.
  # The default value is <code>default_branch</code>,<code>exists_on_github</code>,<code>last_build:desc</code>.
  #
  # GET <code>/repo/{repository.slug}/branches</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #     Query Parameter          Type       Description
  #     branch.exists_on_github  [Boolean]  Filters branches by whether or not the branch still exists on GitHub.
  #     exists_on_github         [Boolean]  Alias for branch.exists_on_github.
  #     include                  [String]   List of attributes to eager load.
  #     limit                    Integer    How many branches to include in the response. Used for pagination.
  #     offset                   Integer    How many branches to skip before the first entry in the response. Used for pagination.
  #     sort_by                  [String]   Attributes to sort branches by. Used for pagination.
  #
  #     Example:GET /repo/rails%2Frails/branches?limit=5&exists_on_github=true
  #
  # **Sortable by:** <code>name</code>, <code>last_build</code>, <code>exists_on_github</code>, <code>default_branch</code>, append <code>:desc</code> to any attribute to reverse order.
  # The default value is <code>default_branch</code>,<code>exists_on_github</code>,<code>last_build:desc</code>.
  #
  # @return [Success, RequestError]
  def branches
    get("#{with_repo}/branches#{opts}")
  end

  # An individual build.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name                 Type     Description
  #     id                   Integer  Value uniquely identifying the build.
  #     number               String   Incremental number for a repository's builds.
  #     state                String   Current state of the build.
  #     duration             Integer  Wall clock time in seconds.
  #     event_type           String   Event that triggered the build.
  #     previous_state       String   State of the previous build (useful to see if state changed).
  #     pull_request_title   String   Title of the build's pull request.
  #     pull_request_number  Integer  Number of the build's pull request.
  #     started_at           String   When the build started.
  #     finished_at          String   When the build finished.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name                 Type        Description
  #     id                   Integer     Value uniquely identifying the build.
  #     number               String      Incremental number for a repository's builds.
  #     state                String      Current state of the build.
  #     duration             Integer     Wall clock time in seconds.
  #     event_type           String      Event that triggered the build.
  #     previous_state       String      State of the previous build (useful to see if state changed).
  #     pull_request_title   String      Title of the build's pull request.
  #     pull_request_number  Integer     Number of the build's pull request.
  #     started_at           String      When the build started.
  #     finished_at          String      When the build finished.
  #     repository           Repository  GitHub user or organization the build belongs to.
  #     branch               Branch      The branch the build is associated with.
  #     tag                  Unknown     The build's tag.
  #     commit               Commit      The commit the build is associated with.
  #     jobs                 Jobs        List of jobs that are part of the build's matrix.
  #     stages               [Stage]     The stages of a build.
  #     created_by           Owner       The User or Organization that created the build.
  #     updated_at           Unknown     The build's updated_at.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a single build.
  #
  # GET <code>/build/{build.id}</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /build/86601346
  #
  # **Cancel**
  #
  # This cancels a currently running build. It will set the build and associated jobs to "state": "canceled".
  #
  # POST <code>/build/{build.id}/cancel</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Example: POST /build/86601346/cancel
  #
  # **Restart**
  #
  # This restarts a build that has completed or been canceled.
  #
  # POST <code>/build/{build.id}/restart</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Example: POST /build/86601346/restart
  #
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param id [String, Integer] the build id number
  # @return [Success, RequestError]
  def build(id)
    get("#{without_repo}/build/#{id}")
  end

  # A list of builds.
  #
  # ## Attributes
  #
  #     Name    Type     Description
  #     builds  [Build]  List of builds.
  #
  # **Collection Items**
  #
  # Each entry in the builds array has the following attributes:
  #
  #     Name                 Type        Description
  #     id                   Integer     Value uniquely identifying the build.
  #     number               String      Incremental number for a repository's builds.
  #     state                String      Current state of the build.
  #     duration             Integer     Wall clock time in seconds.
  #     event_type           String      Event that triggered the build.
  #     previous_state       String      State of the previous build (useful to see if state changed).
  #     pull_request_title   String      Title of the build's pull request.
  #     pull_request_number  Integer     Number of the build's pull request.
  #     started_at           String      When the build started.
  #     finished_at          String      When the build finished.
  #     repository           Repository  GitHub user or organization the build belongs to.
  #     branch               Branch      The branch the build is associated with.
  #     tag                  Unknown     The build's tag.
  #     commit               Commit      The commit the build is associated with.
  #     jobs                 Jobs        List of jobs that are part of the build's matrix.
  #     stages               [Stage]     The stages of a build.
  #     created_by           Owner       The User or Organization that created the build.
  #     updated_at           Unknown     The build's updated_at.
  #     request              Unknown     The build's request.
  #
  # ## Actions
  #
  # **For Current User**
  #
  # This returns a list of builds for the current user. The result is paginated.
  #
  # GET <code>/builds</code>
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #     limit            Integer   How many builds to include in the response. Used for pagination.
  #     limit            Integer   How many builds to include in the response. Used for pagination.
  #     offset           Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     offset           Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     sort_by          [String]  Attributes to sort builds by. Used for pagination.
  #     sort_by          [String]  Attributes to sort builds by. Used for pagination.
  #
  #     Example: GET /builds?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>started_at</code>, <code>finished_at</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # **Find**
  #
  # This returns a list of builds for an individual repository. It is possible to use the repository id or slug in the request. The result is paginated. Each request will return 25 results.
  #
  # GET <code>/repo/{repository.id}/builds</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Query Parameter       Type      Description
  #     branch.name           [String]  Filters builds by name of the git branch.
  #     build.created_by      [Owner]   Filters builds by the User or Organization that created the build.
  #     build.event_type      [String]  Filters builds by event that triggered the build.
  #     build.previous_state  [String]  Filters builds by state of the previous build (useful to see if state changed).
  #     build.state           [String]  Filters builds by current state of the build.
  #     created_by            [Owner]   Alias for build.created_by.
  #     event_type            [String]  Alias for build.event_type.
  #     include               [String]  List of attributes to eager load.
  #     limit                 Integer   How many builds to include in the response. Used for pagination.
  #     offset                Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     previous_state        [String]  Alias for build.previous_state.
  #     sort_by               [String]  Attributes to sort builds by. Used for pagination.
  #     state                 [String]  Alias for build.state.
  #
  #     Example: GET /repo/891/builds?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>started_at</code>, <code>finished_at</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/repo/{repository.slug}/builds</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Query Parameter       Type      Description
  #     branch.name           [String]  Filters builds by name of the git branch.
  #     build.created_by      [Owner]   Filters builds by the User or Organization that created the build.
  #     build.event_type      [String]  Filters builds by event that triggered the build.
  #     build.previous_state  [String]  Filters builds by state of the previous build (useful to see if state changed).
  #     build.state           [String]  Filters builds by current state of the build.
  #     created_by            [Owner]   Alias for build.created_by.
  #     event_type            [String]  Alias for build.event_type.
  #     include               [String]  List of attributes to eager load.
  #     limit                 Integer   How many builds to include in the response. Used for pagination.
  #     offset                Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     previous_state        [String]  Alias for build.previous_state.
  #     sort_by               [String]  Attributes to sort builds by. Used for pagination.
  #     state                 [String]  Alias for build.state.
  #
  #     Example: GET /repo/rails%2Frails/builds?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>started_at</code>, <code>finished_at</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # @return [Success, RequestError]
  def builds
    get("#{with_repo}/builds#{opts}")
  end

  # A list of jobs.
  #
  # ## Attributes
  #
  #     Name  Type  Description
  #     jobs  [Job]  List of jobs.
  #
  # **Collection Items**
  #
  # Each entry in the jobs array has the following attributes:
  #
  #     Name           Type        Description
  #     id             Integer     Value uniquely identifying the job.
  #     allow_failure  Unknown     The job's allow_failure.
  #     number         String      Incremental number for a repository's builds.
  #     state          String      Current state of the job.
  #     started_at     String      When the job started.
  #     finished_at    String      When the job finished.
  #     build          Build       The build the job is associated with.
  #     queue          String      Worker queue this job is/was scheduled on.
  #     repository     Repository  GitHub user or organization the job belongs to.
  #     commit         Commit      The commit the job is associated with.
  #     owner          Owner       GitHub user or organization the job belongs to.
  #     stage          [Stage]     The stages of a job.
  #     created_at     String      When the job was created.
  #     updated_at     String      When the job was updated.
  #     config         Object      The job's config.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a list of jobs belonging to an individual build.
  #
  # GET <code>/build/{build.id}/jobs</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /build/86601346/jobs
  #
  # **For Current User**
  #
  # This returns a list of jobs a current user has access to.
  #
  # GET <code>/jobs</code>
  #
  #     Query Parameter  Type      Description
  #     active           Unknown   Alias for job.active.
  #     created_by       Unknown   Alias for job.created_by.
  #     include          [String]  List of attributes to eager load.
  #     job.active       Unknown   Documentation missing.
  #     job.created_by   Unknown   Documentation missing.
  #     job.state        [String]  Filters jobs by current state of the job.
  #     limit            Integer   How many jobs to include in the response. Used for pagination.
  #     offset           Integer   How many jobs to skip before the first entry in the response. Used for pagination.
  #     sort_by          [String]  Attributes to sort jobs by. Used for pagination.
  #     state            [String]  Alias for job.state.
  #
  #     Example: GET /jobs?limit=5
  #
  # **Sortable by:** <code>id</code>, append <code>:desc</code> to any attribute to reverse order.
  # The default value is id:desc.
  #
  # @param id [String, Integer] the build id number
  # @return [Success, RequestError]
  def build_jobs(id)
    get("#{without_repo}/build/#{id}/jobs")
  end

  # An individual job.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type     Description
  #     id    Integer  Value uniquely identifying the job.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name           Type        Description
  #     id             Integer     Value uniquely identifying the job.
  #     allow_failure  Unknown     The job's allow_failure.
  #     number         String      Incremental number for a repository's builds.
  #     state          String      Current state of the job.
  #     started_at     String      When the job started.
  #     finished_at    String      When the job finished.
  #     build          Build       The build the job is associated with.
  #     queue          String      Worker queue this job is/was scheduled on.
  #     repository     Repository  GitHub user or organization the job belongs to.
  #     commit         Commit      The commit the job is associated with.
  #     owner          Owner       GitHub user or organization the job belongs to.
  #     stage          [Stage]     The stages of a job.
  #     created_at     String      When the job was created.
  #     updated_at     String      When the job was updated.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a single job.
  #
  # GET <code>/job/{job.id}</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /job/86601347
  #
  # **Cancel**
  #
  # This cancels a currently running job.
  #
  # POST <code>/job/{job.id}/cancel</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: POST /job/86601347/cancel
  #
  # **Restart**
  #
  # This restarts a job that has completed or been canceled.
  #
  # POST <code>/job/{job.id}/restart</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: POST /job/86601347/restart
  #
  # **Debug**
  #
  # This restarts a job in debug mode, enabling the logged-in user to ssh into the build VM. Please note this feature is only available on the travis-ci.com domain, and those repositories on the travis-ci.org domain for which the debug feature is enabled. See this document for more details.
  #
  # POST <code>/job/{job.id}/debug</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: POST /job/86601347/debug
  #
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param id [String, Integer] the job id number
  # @param option [Symbol] options for :cancel, :restart, or :debug
  # @return [Success, RequestError]
  def job(id, option = nil)
    case option
    when :cancel
      post("#{without_repo}/job/#{id}/cancel")
    when :restart
      post("#{without_repo}/job/#{id}/restart")
    when :debug
      post("#{without_repo}/job/#{id}/debug")
    else
      get("#{without_repo}/job/#{id}")
    end
  end

  # This validates the `.travis.yml` file and returns any warnings.
  #
  # The request body can contain the content of the .travis.yml file directly as a string, eg "foo: bar".
  #
  # ## Attributes
  #
  #     Name      Type   Description
  #     warnings  Array  An array of hashes with keys and warnings.
  #
  # ## Actions
  #
  # **Lint**
  #
  # POST <code>/lint</code>
  #
  #     Example:POST /lint
  #
  # @param yaml_content [String] the contents for the file `.travis.yml`
  # @return [Success, RequestError]
  def lint(yaml_content)
    raise TypeError, "String expected, #{yaml_content.class} given" unless \
      yaml_content.is_a? String

    ct = headers.remove(:'Content-Type')
    result = post("#{without_repo}/lint", body: yaml_content)
    h('Content-Type': ct) if ct
    result
  end

  # An individual log.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type     Description
  #     id    Unknown  The log's id.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name       Type     Description
  #     id         Unknown  The log's id.
  #     content    Unknown  The log's content.
  #     log_parts  Unknown  The log's log_parts.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a single log.
  #
  # It's possible to specify the accept format of the request as text/plain if required. This will return the content of the log as a single blob of text.
  #
  #     curl -H "Travis-API-Version: 3" \
  #       -H "Accept: text/plain" \
  #       -H "Authorization: token xxxxxxxxxxxx" \
  #       https://api.travis-ci.org/job/{job.id}/log
  #
  # The default response type is application/json, and will include additional meta data such as @type, @representation etc. (see [https://developer.travis-ci.org/format](https://developer.travis-ci.org/format)).
  #
  # GET <code>/job/{job.id}/log</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #     log.token        Unknown   Documentation missing.
  #
  #     Example: GET /job/86601347/log
  #
  # GET <code>/job/{job.id}/log.txt</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #     log.token        Unknown   Documentation missing.
  #
  #     Example:GET /job/86601347/log.txt
  #
  # **Delete**
  #
  # This removes the contents of a log. It gets replace with the message: Log removed by XXX at 2017-02-13 16:00:00 UTC.
  #
  #     curl -X DELETE \
  #       -H "Travis-API-Version: 3" \
  #       -H "Authorization: token xxxxxxxxxxxx" \
  #       https://api.travis-ci.org/job/{job.id}/log
  #
  # DELETE <code>/job/{job.id}/log</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: DELETE /job/86601347/log
  #
  # @note DELETE is unimplemented
  #
  # @param id [String, Integer] the job id number
  # @param option [Symbol] options for :text or :delete
  # @return [Success, String, RequestError]
  def log(id, option = nil)
    case option
    when :text
      get("#{without_repo}/job/#{id}/log.txt", true)
    when :delete
      raise Unimplemented
    else
      get("#{without_repo}/job/#{id}/log")
    end
  end

  # An individual organization.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name   Type     Description
  #     id     Integer  Value uniquely identifying the organization.
  #     login  String   Login set on GitHub.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
  #
  #     Name             Type     Description
  #     id               Integer  Value uniquely identifying the organization.
  #     login            String   Login set on GitHub.
  #     name             String   Name set on GitHub.
  #     github_id        Integer  Id set on GitHub.
  #     avatar_url       String   Avatar_url set on GitHub.
  #     education        Boolean  Whether or not the organization has an education account.
  #     allow_migration  Unknown  The organization's allow_migration.
  #
  # **Additional Attributes**
  #
  #     Name          Type          Description
  #     repositories  [Repository]  Repositories belonging to this organization.
  #     installation  Installation  Installation belonging to the organization.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns an individual organization.
  #
  # GET <code>/org/{organization.id}</code>
  #
  #     Template Variable  Type      Description
  #     organization.id    Integer   Value uniquely identifying the organization.
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #
  #     Example:GET /org/87
  #
  # @param org_id [String, Integer] the organization id
  # @raise [TypeError] if given organization id is not a number
  # @return [Success, RequestError]
  def organization(org_id)
    raise TypeError, 'Integer expected for organization id' unless /^\d+$/.match? org_id.to_s

    get("#{without_repo}/org/#{org_id}")
  end

  # A list of organizations for the current user.
  #
  # ## Attributes
  #
  #     Name           Type            Description
  #     organizations  [Organization]  List of organizations.
  #
  # **Collection Items**
  #
  # Each entry in the **organizations** array has the following attributes:
  #
  #     Name             Type          Description
  #     id               Integer       Value uniquely identifying the organization.
  #     login            String        Login set on GitHub.
  #     name             String        Name set on GitHub.
  #     github_id        Integer       Id set on GitHub.
  #     avatar_url       String        Avatar_url set on GitHub.
  #     education        Boolean       Whether or not the organization has an education account.
  #     allow_migration  Unknown       The organization's allow_migration.
  #     repositories     [Repository]  Repositories belonging to this organization.
  #     installation     Installation  Installation belonging to the organization.
  #
  # ## Actions
  #
  # **For Current User**
  #
  # This returns a list of organizations the current user is a member of.
  #
  # GET <code>/orgs</code>
  #
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #     limit              Integer   How many organizations to include in the response. Used for pagination.
  #     offset             Integer   How many organizations to skip before the first entry in the response. Used for pagination.
  #     organization.role  Unknown   Documentation missing.
  #     role               Unknown   Alias for organization.role.
  #     sort_by            [String]  Attributes to sort organizations by. Used for pagination.
  #
  #     Example:GET /orgs?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>login</code>, <code>name</code>, <code>github_id</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # @return [Success, RequestError]
  def organizations
    get("#{without_repo}/orgs")
  end

  # This will be either a user or organization.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name    Type     Description
  #     id      Integer  Value uniquely identifying the owner.
  #     login   String   User or organization login set on GitHub.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name        Type     Description
  #     id          Integer  Value uniquely identifying the owner.
  #     login       String   User or organization login set on GitHub.
  #     name        String   User or organization name set on GitHub.
  #     github_id   Integer  User or organization id set on GitHub.
  #     avatar_url  String   Link to user or organization avatar (image) set on GitHub.
  #
  # **Additional Attributes**
  #
  #     Name           Type           Description
  #     repositories   [Repository]   Repositories belonging to this account.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns an individual owner. It is possible to use the GitHub login or github_id in the request.
  #
  # GET <code>/owner/{owner.login}</code>
  #
  #     Template Variable  Type      Description
  #     owner.login        String    User or organization login set on GitHub.
  #
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/danielpclark
  #
  # GET <code>/owner/{user.login}</code>
  #
  #     Template Variable  Type      Description
  #     user.login         String    Login set on Github.
  #
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/danielpclark
  #
  # GET <code>/owner/{organization.login}</code>
  #
  #     Template Variable   Type      Description
  #     organization.login  String    Login set on GitHub.
  #
  #     Query Parameter     Type      Description
  #     include             [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/travis-ci
  #
  # GET <code>/owner/github_id/{owner.github_id}</code>
  #
  #     Template Variable   Type      Description
  #     owner.github_id     Integer   User or organization id set on GitHub.
  #
  #     Query Parameter     Type      Description
  #     include             [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/github_id/639823
  #
  # @param owner [String] username or github ID
  # @return [Success, RequestError]
  def owner(owner = username)
    if /^\d+$/.match? owner.to_s
      get("#{without_repo}/owner/github_id/#{owner}")
    else
      get("#{without_repo}/owner/#{owner}")
    end
  end

  # A list of repositories for the current user.
  #
  # ## Attributes
  #
  #     Name           Type           Description
  #     repositories   [Repository]   List of repositories.
  #
  # **Collection Items**
  #
  # Each entry in the repositories array has the following attributes:
  #
  #     Name                Type     Description
  #     id                  Integer  Value uniquely identifying the repository.
  #     name                String   The repository's name on GitHub.
  #     slug                String   Same as {repository.owner.name}/{repository.name}.
  #     description         String   The repository's description from GitHub.
  #     github_language     String   The main programming language used according to GitHub.
  #     active              Boolean  Whether or not this repository is currently enabled on Travis CI.
  #     private             Boolean  Whether or not this repository is private.
  #     owner               Owner    GitHub user or organization the repository belongs to.
  #     default_branch      Branch   The default branch on GitHub.
  #     starred             Boolean  Whether or not this repository is starred.
  #     current_build       Build    The most recently started build (this excludes builds that have been created but have not yet started).
  #     last_started_build  Build    Alias for current_build.
  #
  # ## Actions
  #
  # **For Owner**
  #
  # This returns a list of repositories an owner has access to.
  #
  # GET <code>/owner/{owner.login}/repos</code>
  #
  #     Template Variable  Type    Description
  #     owner.login        String  User or organization login set on GitHub.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/owner/{user.login}/repos</code>
  #
  #     Template Variable  Type    Description
  #     user.login         String  Login set on Github.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/owner/{organization.login}/repos</code>
  #
  #     Template Variable   Type    Description
  #     organization.login  String  Login set on GitHub.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/travis-ci/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/owner/github_id/{owner.github_id}/repos</code>
  #
  #     Template Variable  Type     Description
  #     owner.github_id    Integer  User or organization id set on GitHub.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/github_id/639823/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # **For Current User**<br />
  # This returns a list of repositories the current user has access to.
  #
  # GET <code>/repos</code>
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # @param owner [String] username or github ID
  # @return [Success, RequestError]
  def repositories(owner = username)
    if /^\d+$/.match? owner.to_s
      get("#{without_repo}/owner/github_id/#{owner}/repos#{opts}")
    else
      get("#{without_repo}/owner/#{owner}/repos#{opts}")
    end
  end

  # An individual repository.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name   Type     Description
  #     id     Integer  Value uniquely identifying the repository.
  #     name   String   The repository's name on GitHub.
  #     slug   String   Same as {repository.owner.name}/{repository.name}.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name             Type     Description
  #     id               Integer  Value uniquely identifying the repository.
  #     name             String   The repository's name on GitHub.
  #     slug             String   Same as {repository.owner.name}/{repository.name}.
  #     description      String   The repository's description from GitHub.
  #     github_language  String   The main programming language used according to GitHub.
  #     active           Boolean  Whether or not this repository is currently enabled on Travis CI.
  #     private          Boolean  Whether or not this repository is private.
  #     owner            Owner    GitHub user or organization the repository belongs to.
  #     default_branch   Branch   The default branch on GitHub.
  #     starred          Boolean  Whether or not this repository is starred.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns an individual repository.
  #
  # GET <code>/repo/{repository.id}</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /repo/891
  #
  # GET <code>/repo/{repository.slug}</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /repo/rails%2Frails
  #
  # **Activate**
  #
  # This will activate a repository, allowing its tests to be run on Travis CI.
  #
  # POST <code>/repo/{repository.id}/activate</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/activate
  #
  # POST <code>/repo/{repository.slug}/activate</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/activate
  #
  # **Deactivate**
  #
  # This will deactivate a repository, preventing any tests from running on Travis CI.
  #
  # POST <code>/repo/{repository.id}/deactivate</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/deactivate
  #
  # POST <code>/repo/{repository.slug}/deactivate</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/deactivate
  #
  # **Star**
  #
  # This will star a repository based on the currently logged in user.
  #
  # POST <code>/repo/{repository.id}/star</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/star
  #
  # POST <code>/repo/{repository.slug}/star</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/star
  #
  # **Unstar**
  #
  # This will unstar a repository based on the currently logged in user.
  #
  # POST <code>/repo/{repository.id}/unstar</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/unstar
  #
  # POST <code>/repo/{repository.slug}/unstar</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/unstar
  #
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param repo [String] github_username/repository_name
  # @param action [String, Symbol] Optional argument for star/unstar/activate/deactivate
  # @raise [InvalidRepository] if given input does not
  #   conform to valid repository identifier format
  # @return [Success, RequestError]
  def repository(repo = repository_name, action = nil)
    raise InvalidRepository unless repo_slug_or_id? repo

    repo = sanitize_repo_name repo
    action = '' unless %w[star unstar activate deavtivate].include? action.to_s

    if action.empty?
      get("#{without_repo}/repo/#{repo}")
    else
      post("#{without_repo}/repo/#{repo}/#{action}")
    end
  end

  # An individual user.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type     Description
  #     id    Integer  Value uniquely identifying the user.
  #     login String   Login set on Github.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
  #
  #     Name              Type     Description
  #     id                Integer  Value uniquely identifying the user.
  #     login             String   Login set on Github.
  #     name              String   Name set on GitHub.
  #     github_id         Integer  Id set on GitHub.
  #     avatar_url        String   Avatar URL set on GitHub.
  #     education         Boolean  Whether or not the user has an education account.
  #     allow_migration   Unknown  The user's allow_migration.
  #     is_syncing        Boolean  Whether or not the user is currently being synced with Github.
  #     synced_at         String   The last time the user was synced with GitHub.
  #
  # **Additional Attributes**
  #
  #     Name          Type          Description
  #     repositories  [Repository]  Repositories belonging to this user.
  #     installation  Installation  Installation belonging to the user.
  #     emails        Unknown       The user's emails.
  #
  # ## Actions
  #
  # **Find**
  #
  # This will return information about an individual user.
  #
  # GET <code>/user/{user.id}</code>
  #
  #     Template Variable  Type     Description
  #     user.id            Integer  Value uniquely identifying the user.
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /user/119240
  #
  # **Sync**
  #
  # This triggers a sync on a user's account with their GitHub account.
  #
  # POST <code>/user/{user.id}/sync</code>
  #
  #     Template Variable  Type     Description
  #     user.id            Integer  Value uniquely identifying the user.
  #
  #     Example:POST /user/119240/sync
  #
  # **Current**
  #
  # This will return information about the current user.
  #
  # GET <code>/user</code>
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /user
  #
  # @note sync feature may not be permitted
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param user_id [String, Integer] optional user id
  # @param sync [Boolean] optional argument for syncing your Travis CI account with Github
  # @raise [TypeError] if given user id is not a number
  # @return [Success, RequestError]
  def user(user_id = nil, sync = false)
    return get("#{without_repo}/user") if !user_id && !sync
    raise TypeError, 'Integer expected for user id' unless /^\d+$/.match? user_id.to_s

    if sync
      get("#{without_repo}/user/#{user_id}/sync")
    else
      get("#{without_repo}/user/#{user_id}")
    end
  end

  private # @private

  def get(url, raw_reply = false)
    Trav3::GET.call(self, url, raw_reply)
  end

  def initial_defaults
    defaults(limit: 25)
    h('Content-Type': 'application/json')
    h('Accept': 'application/json')
    h('Travis-API-Version': 3)
  end

  def opts
    @options
  end

  def post(url, fields = {})
    Trav3::POST.call(self, url, fields)
  end

  def repo_slug_or_id?(repo)
    Regexp.new(/(^\d+$)|(^\w+(?:\/|%2F){1}\w+$)/).match? repo
  end

  def repository_name
    @repo
  end

  def sanitize_repo_name(repo)
    repo.to_s.gsub(/\//, '%2F')
  end

  def username
    @repo[/.*?(?=(?:\/|%2F)|$)/]
  end

  def with_repo
    "#{api_endpoint}/repo/#{@repo}"
  end

  def without_repo
    api_endpoint
  end
end

#optionsOptions (readonly)

Returns Request options object

Returns:

  • (Options)

    Request options object


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
# File 'lib/trav3.rb', line 25

class Travis
  API_ENDPOINT = API_ROOT
  attr_reader :api_endpoint
  attr_reader :options
  attr_reader :headers

  # @param repo [String] github_username/repository_name
  # @raise [InvalidRepository] if given input does not
  #   conform to valid repository identifier format
  # @return [Travis]
  def initialize(repo)
    raise InvalidRepository unless repo_slug_or_id? repo

    @api_endpoint = API_ENDPOINT
    @repo = sanitize_repo_name repo

    initial_defaults
  end

  # @overload api_endpoint=(endpoint)
  #   Set as the API endpoint
  #   @param endpoint [String] name for value to set
  # @return [self]
  # rubocop:disable Lint/Void
  def api_endpoint=(endpoint)
    raise InvalidAPIEndpoint unless /^https:\/\/api\.travis-ci\.(?:org|com)$/.match? endpoint

    @api_endpoint = endpoint

    self
  end
  # rubocop:enable Lint/Void

  # @overload defaults(key: value, ...)
  #   Set as many options as you'd like for collections queried via an API request
  #   @param key [Symbol, String] name for value to set
  #   @param value [Symbol, String, Integer] value for key
  # @return [self]
  def defaults(**args)
    (@options ||= Options.new).build(**args)
    self
  end

  # Set as many headers as you'd like for API requests
  #
  #     h("Authorization": "token xxxxxxxxxxxxxxxxxxxxxx")
  #
  # @overload h(key: value, ...)
  #   @param key [Symbol, String] name for value to set
  #   @param value [Symbol, String, Integer] value for key
  # @return [self]
  def h(**args)
    (@headers ||= Headers.new).build(**args)
    self
  end

  # The branch of a GitHub repository. Useful for obtaining information about the last build on a given branch.
  #
  # **If querying using the repository slug, it must be formatted using {http://www.w3schools.com/tags/ref_urlencode.asp standard URL encoding}, including any special characters.**
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type    Description
  #     name  String  Name of the git branch.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
  #
  #     Name              Type        Description
  #     name              String      Name of the git branch.
  #     repository        Repository  GitHub user or organization the branch belongs to.
  #     default_branch    Boolean     Whether or not this is the resposiotry's default branch.
  #     exists_on_github  Boolean     Whether or not the branch still exists on GitHub.
  #     last_build        Build       Last build on the branch.
  #
  # **Additional Attributes**
  #
  #     Name           Type     Description
  #     recent_builds  [Build]  Last 10 builds on the branch (when `include=branch.recent_builds` is used).
  #
  # ## Actions
  #
  # **Find**
  #
  # This will return information about an individual branch. The request can include either the repository id or slug.
  #
  # GET <code>/repo/{repository.id}/branch/{branch.name}</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #     branch.name        String   Name of the git branch.
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /repo/891/branch/master
  #
  # GET <code>/repo/{repository.slug}/branch/{branch.name}</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #     branch.name        String  Name of the git branch.
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /repo/rails%2Frails/branch/master
  #
  # @param id [String] the branch name for the current repository
  # @return [Success, RequestError]
  def branch(name)
    get("#{with_repo}/branch/#{name}#{opts}")
  end

  # A list of branches.
  #
  # **If querying using the repository slug, it must be formatted using {http://www.w3schools.com/tags/ref_urlencode.asp standard URL encoding}, including any special characters.**
  #
  # ##Attributes
  #
  #     Name      Type      Description
  #     branches  [Branch]  List of branches.
  #
  # **Collection Items**
  #
  # Each entry in the **branches** array has the following attributes:
  #
  #     Name              Type        Description
  #     name              String      Name of the git branch.
  #     repository        Repository  GitHub user or organization the branch belongs to.
  #     default_branch    Boolean     Whether or not this is the resposiotry's default branch.
  #     exists_on_github  Boolean     Whether or not the branch still exists on GitHub.
  #     last_build        Build       Last build on the branch.
  #     recent_builds    [Build]      Last 10 builds on the branch (when `include=branch.recent_builds` is used).
  #
  # ## Actions
  #
  # **Find**
  #
  # This will return a list of branches a repository has on GitHub.
  #
  # GET <code>/repo/{repository.id}/branches</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #     Query Parameter          Type       Description
  #     branch.exists_on_github  [Boolean]  Filters branches by whether or not the branch still exists on GitHub.
  #     exists_on_github         [Boolean]  Alias for branch.exists_on_github.
  #     include                  [String]   List of attributes to eager load.
  #     limit                    Integer    How many branches to include in the response. Used for pagination.
  #     offset                   Integer    How many branches to skip before the first entry in the response. Used for pagination.
  #     sort_by                  [String]   Attributes to sort branches by. Used for pagination.
  #
  #     Example:GET /repo/891/branches?limit=5&exists_on_github=true
  #
  # **Sortable by:** <code>name</code>, <code>last_build</code>, <code>exists_on_github</code>, <code>default_branch</code>, append <code>:desc</code> to any attribute to reverse order.
  # The default value is <code>default_branch</code>,<code>exists_on_github</code>,<code>last_build:desc</code>.
  #
  # GET <code>/repo/{repository.slug}/branches</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #     Query Parameter          Type       Description
  #     branch.exists_on_github  [Boolean]  Filters branches by whether or not the branch still exists on GitHub.
  #     exists_on_github         [Boolean]  Alias for branch.exists_on_github.
  #     include                  [String]   List of attributes to eager load.
  #     limit                    Integer    How many branches to include in the response. Used for pagination.
  #     offset                   Integer    How many branches to skip before the first entry in the response. Used for pagination.
  #     sort_by                  [String]   Attributes to sort branches by. Used for pagination.
  #
  #     Example:GET /repo/rails%2Frails/branches?limit=5&exists_on_github=true
  #
  # **Sortable by:** <code>name</code>, <code>last_build</code>, <code>exists_on_github</code>, <code>default_branch</code>, append <code>:desc</code> to any attribute to reverse order.
  # The default value is <code>default_branch</code>,<code>exists_on_github</code>,<code>last_build:desc</code>.
  #
  # @return [Success, RequestError]
  def branches
    get("#{with_repo}/branches#{opts}")
  end

  # An individual build.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name                 Type     Description
  #     id                   Integer  Value uniquely identifying the build.
  #     number               String   Incremental number for a repository's builds.
  #     state                String   Current state of the build.
  #     duration             Integer  Wall clock time in seconds.
  #     event_type           String   Event that triggered the build.
  #     previous_state       String   State of the previous build (useful to see if state changed).
  #     pull_request_title   String   Title of the build's pull request.
  #     pull_request_number  Integer  Number of the build's pull request.
  #     started_at           String   When the build started.
  #     finished_at          String   When the build finished.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name                 Type        Description
  #     id                   Integer     Value uniquely identifying the build.
  #     number               String      Incremental number for a repository's builds.
  #     state                String      Current state of the build.
  #     duration             Integer     Wall clock time in seconds.
  #     event_type           String      Event that triggered the build.
  #     previous_state       String      State of the previous build (useful to see if state changed).
  #     pull_request_title   String      Title of the build's pull request.
  #     pull_request_number  Integer     Number of the build's pull request.
  #     started_at           String      When the build started.
  #     finished_at          String      When the build finished.
  #     repository           Repository  GitHub user or organization the build belongs to.
  #     branch               Branch      The branch the build is associated with.
  #     tag                  Unknown     The build's tag.
  #     commit               Commit      The commit the build is associated with.
  #     jobs                 Jobs        List of jobs that are part of the build's matrix.
  #     stages               [Stage]     The stages of a build.
  #     created_by           Owner       The User or Organization that created the build.
  #     updated_at           Unknown     The build's updated_at.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a single build.
  #
  # GET <code>/build/{build.id}</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /build/86601346
  #
  # **Cancel**
  #
  # This cancels a currently running build. It will set the build and associated jobs to "state": "canceled".
  #
  # POST <code>/build/{build.id}/cancel</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Example: POST /build/86601346/cancel
  #
  # **Restart**
  #
  # This restarts a build that has completed or been canceled.
  #
  # POST <code>/build/{build.id}/restart</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Example: POST /build/86601346/restart
  #
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param id [String, Integer] the build id number
  # @return [Success, RequestError]
  def build(id)
    get("#{without_repo}/build/#{id}")
  end

  # A list of builds.
  #
  # ## Attributes
  #
  #     Name    Type     Description
  #     builds  [Build]  List of builds.
  #
  # **Collection Items**
  #
  # Each entry in the builds array has the following attributes:
  #
  #     Name                 Type        Description
  #     id                   Integer     Value uniquely identifying the build.
  #     number               String      Incremental number for a repository's builds.
  #     state                String      Current state of the build.
  #     duration             Integer     Wall clock time in seconds.
  #     event_type           String      Event that triggered the build.
  #     previous_state       String      State of the previous build (useful to see if state changed).
  #     pull_request_title   String      Title of the build's pull request.
  #     pull_request_number  Integer     Number of the build's pull request.
  #     started_at           String      When the build started.
  #     finished_at          String      When the build finished.
  #     repository           Repository  GitHub user or organization the build belongs to.
  #     branch               Branch      The branch the build is associated with.
  #     tag                  Unknown     The build's tag.
  #     commit               Commit      The commit the build is associated with.
  #     jobs                 Jobs        List of jobs that are part of the build's matrix.
  #     stages               [Stage]     The stages of a build.
  #     created_by           Owner       The User or Organization that created the build.
  #     updated_at           Unknown     The build's updated_at.
  #     request              Unknown     The build's request.
  #
  # ## Actions
  #
  # **For Current User**
  #
  # This returns a list of builds for the current user. The result is paginated.
  #
  # GET <code>/builds</code>
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #     limit            Integer   How many builds to include in the response. Used for pagination.
  #     limit            Integer   How many builds to include in the response. Used for pagination.
  #     offset           Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     offset           Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     sort_by          [String]  Attributes to sort builds by. Used for pagination.
  #     sort_by          [String]  Attributes to sort builds by. Used for pagination.
  #
  #     Example: GET /builds?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>started_at</code>, <code>finished_at</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # **Find**
  #
  # This returns a list of builds for an individual repository. It is possible to use the repository id or slug in the request. The result is paginated. Each request will return 25 results.
  #
  # GET <code>/repo/{repository.id}/builds</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Query Parameter       Type      Description
  #     branch.name           [String]  Filters builds by name of the git branch.
  #     build.created_by      [Owner]   Filters builds by the User or Organization that created the build.
  #     build.event_type      [String]  Filters builds by event that triggered the build.
  #     build.previous_state  [String]  Filters builds by state of the previous build (useful to see if state changed).
  #     build.state           [String]  Filters builds by current state of the build.
  #     created_by            [Owner]   Alias for build.created_by.
  #     event_type            [String]  Alias for build.event_type.
  #     include               [String]  List of attributes to eager load.
  #     limit                 Integer   How many builds to include in the response. Used for pagination.
  #     offset                Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     previous_state        [String]  Alias for build.previous_state.
  #     sort_by               [String]  Attributes to sort builds by. Used for pagination.
  #     state                 [String]  Alias for build.state.
  #
  #     Example: GET /repo/891/builds?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>started_at</code>, <code>finished_at</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/repo/{repository.slug}/builds</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Query Parameter       Type      Description
  #     branch.name           [String]  Filters builds by name of the git branch.
  #     build.created_by      [Owner]   Filters builds by the User or Organization that created the build.
  #     build.event_type      [String]  Filters builds by event that triggered the build.
  #     build.previous_state  [String]  Filters builds by state of the previous build (useful to see if state changed).
  #     build.state           [String]  Filters builds by current state of the build.
  #     created_by            [Owner]   Alias for build.created_by.
  #     event_type            [String]  Alias for build.event_type.
  #     include               [String]  List of attributes to eager load.
  #     limit                 Integer   How many builds to include in the response. Used for pagination.
  #     offset                Integer   How many builds to skip before the first entry in the response. Used for pagination.
  #     previous_state        [String]  Alias for build.previous_state.
  #     sort_by               [String]  Attributes to sort builds by. Used for pagination.
  #     state                 [String]  Alias for build.state.
  #
  #     Example: GET /repo/rails%2Frails/builds?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>started_at</code>, <code>finished_at</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # @return [Success, RequestError]
  def builds
    get("#{with_repo}/builds#{opts}")
  end

  # A list of jobs.
  #
  # ## Attributes
  #
  #     Name  Type  Description
  #     jobs  [Job]  List of jobs.
  #
  # **Collection Items**
  #
  # Each entry in the jobs array has the following attributes:
  #
  #     Name           Type        Description
  #     id             Integer     Value uniquely identifying the job.
  #     allow_failure  Unknown     The job's allow_failure.
  #     number         String      Incremental number for a repository's builds.
  #     state          String      Current state of the job.
  #     started_at     String      When the job started.
  #     finished_at    String      When the job finished.
  #     build          Build       The build the job is associated with.
  #     queue          String      Worker queue this job is/was scheduled on.
  #     repository     Repository  GitHub user or organization the job belongs to.
  #     commit         Commit      The commit the job is associated with.
  #     owner          Owner       GitHub user or organization the job belongs to.
  #     stage          [Stage]     The stages of a job.
  #     created_at     String      When the job was created.
  #     updated_at     String      When the job was updated.
  #     config         Object      The job's config.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a list of jobs belonging to an individual build.
  #
  # GET <code>/build/{build.id}/jobs</code>
  #
  #     Template Variable  Type     Description
  #     build.id           Integer  Value uniquely identifying the build.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /build/86601346/jobs
  #
  # **For Current User**
  #
  # This returns a list of jobs a current user has access to.
  #
  # GET <code>/jobs</code>
  #
  #     Query Parameter  Type      Description
  #     active           Unknown   Alias for job.active.
  #     created_by       Unknown   Alias for job.created_by.
  #     include          [String]  List of attributes to eager load.
  #     job.active       Unknown   Documentation missing.
  #     job.created_by   Unknown   Documentation missing.
  #     job.state        [String]  Filters jobs by current state of the job.
  #     limit            Integer   How many jobs to include in the response. Used for pagination.
  #     offset           Integer   How many jobs to skip before the first entry in the response. Used for pagination.
  #     sort_by          [String]  Attributes to sort jobs by. Used for pagination.
  #     state            [String]  Alias for job.state.
  #
  #     Example: GET /jobs?limit=5
  #
  # **Sortable by:** <code>id</code>, append <code>:desc</code> to any attribute to reverse order.
  # The default value is id:desc.
  #
  # @param id [String, Integer] the build id number
  # @return [Success, RequestError]
  def build_jobs(id)
    get("#{without_repo}/build/#{id}/jobs")
  end

  # An individual job.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type     Description
  #     id    Integer  Value uniquely identifying the job.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name           Type        Description
  #     id             Integer     Value uniquely identifying the job.
  #     allow_failure  Unknown     The job's allow_failure.
  #     number         String      Incremental number for a repository's builds.
  #     state          String      Current state of the job.
  #     started_at     String      When the job started.
  #     finished_at    String      When the job finished.
  #     build          Build       The build the job is associated with.
  #     queue          String      Worker queue this job is/was scheduled on.
  #     repository     Repository  GitHub user or organization the job belongs to.
  #     commit         Commit      The commit the job is associated with.
  #     owner          Owner       GitHub user or organization the job belongs to.
  #     stage          [Stage]     The stages of a job.
  #     created_at     String      When the job was created.
  #     updated_at     String      When the job was updated.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a single job.
  #
  # GET <code>/job/{job.id}</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /job/86601347
  #
  # **Cancel**
  #
  # This cancels a currently running job.
  #
  # POST <code>/job/{job.id}/cancel</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: POST /job/86601347/cancel
  #
  # **Restart**
  #
  # This restarts a job that has completed or been canceled.
  #
  # POST <code>/job/{job.id}/restart</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: POST /job/86601347/restart
  #
  # **Debug**
  #
  # This restarts a job in debug mode, enabling the logged-in user to ssh into the build VM. Please note this feature is only available on the travis-ci.com domain, and those repositories on the travis-ci.org domain for which the debug feature is enabled. See this document for more details.
  #
  # POST <code>/job/{job.id}/debug</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: POST /job/86601347/debug
  #
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param id [String, Integer] the job id number
  # @param option [Symbol] options for :cancel, :restart, or :debug
  # @return [Success, RequestError]
  def job(id, option = nil)
    case option
    when :cancel
      post("#{without_repo}/job/#{id}/cancel")
    when :restart
      post("#{without_repo}/job/#{id}/restart")
    when :debug
      post("#{without_repo}/job/#{id}/debug")
    else
      get("#{without_repo}/job/#{id}")
    end
  end

  # This validates the `.travis.yml` file and returns any warnings.
  #
  # The request body can contain the content of the .travis.yml file directly as a string, eg "foo: bar".
  #
  # ## Attributes
  #
  #     Name      Type   Description
  #     warnings  Array  An array of hashes with keys and warnings.
  #
  # ## Actions
  #
  # **Lint**
  #
  # POST <code>/lint</code>
  #
  #     Example:POST /lint
  #
  # @param yaml_content [String] the contents for the file `.travis.yml`
  # @return [Success, RequestError]
  def lint(yaml_content)
    raise TypeError, "String expected, #{yaml_content.class} given" unless \
      yaml_content.is_a? String

    ct = headers.remove(:'Content-Type')
    result = post("#{without_repo}/lint", body: yaml_content)
    h('Content-Type': ct) if ct
    result
  end

  # An individual log.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type     Description
  #     id    Unknown  The log's id.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name       Type     Description
  #     id         Unknown  The log's id.
  #     content    Unknown  The log's content.
  #     log_parts  Unknown  The log's log_parts.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns a single log.
  #
  # It's possible to specify the accept format of the request as text/plain if required. This will return the content of the log as a single blob of text.
  #
  #     curl -H "Travis-API-Version: 3" \
  #       -H "Accept: text/plain" \
  #       -H "Authorization: token xxxxxxxxxxxx" \
  #       https://api.travis-ci.org/job/{job.id}/log
  #
  # The default response type is application/json, and will include additional meta data such as @type, @representation etc. (see [https://developer.travis-ci.org/format](https://developer.travis-ci.org/format)).
  #
  # GET <code>/job/{job.id}/log</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #     log.token        Unknown   Documentation missing.
  #
  #     Example: GET /job/86601347/log
  #
  # GET <code>/job/{job.id}/log.txt</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #     log.token        Unknown   Documentation missing.
  #
  #     Example:GET /job/86601347/log.txt
  #
  # **Delete**
  #
  # This removes the contents of a log. It gets replace with the message: Log removed by XXX at 2017-02-13 16:00:00 UTC.
  #
  #     curl -X DELETE \
  #       -H "Travis-API-Version: 3" \
  #       -H "Authorization: token xxxxxxxxxxxx" \
  #       https://api.travis-ci.org/job/{job.id}/log
  #
  # DELETE <code>/job/{job.id}/log</code>
  #
  #     Template Variable  Type     Description
  #     job.id             Integer  Value uniquely identifying the job.
  #
  #     Example: DELETE /job/86601347/log
  #
  # @note DELETE is unimplemented
  #
  # @param id [String, Integer] the job id number
  # @param option [Symbol] options for :text or :delete
  # @return [Success, String, RequestError]
  def log(id, option = nil)
    case option
    when :text
      get("#{without_repo}/job/#{id}/log.txt", true)
    when :delete
      raise Unimplemented
    else
      get("#{without_repo}/job/#{id}/log")
    end
  end

  # An individual organization.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name   Type     Description
  #     id     Integer  Value uniquely identifying the organization.
  #     login  String   Login set on GitHub.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
  #
  #     Name             Type     Description
  #     id               Integer  Value uniquely identifying the organization.
  #     login            String   Login set on GitHub.
  #     name             String   Name set on GitHub.
  #     github_id        Integer  Id set on GitHub.
  #     avatar_url       String   Avatar_url set on GitHub.
  #     education        Boolean  Whether or not the organization has an education account.
  #     allow_migration  Unknown  The organization's allow_migration.
  #
  # **Additional Attributes**
  #
  #     Name          Type          Description
  #     repositories  [Repository]  Repositories belonging to this organization.
  #     installation  Installation  Installation belonging to the organization.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns an individual organization.
  #
  # GET <code>/org/{organization.id}</code>
  #
  #     Template Variable  Type      Description
  #     organization.id    Integer   Value uniquely identifying the organization.
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #
  #     Example:GET /org/87
  #
  # @param org_id [String, Integer] the organization id
  # @raise [TypeError] if given organization id is not a number
  # @return [Success, RequestError]
  def organization(org_id)
    raise TypeError, 'Integer expected for organization id' unless /^\d+$/.match? org_id.to_s

    get("#{without_repo}/org/#{org_id}")
  end

  # A list of organizations for the current user.
  #
  # ## Attributes
  #
  #     Name           Type            Description
  #     organizations  [Organization]  List of organizations.
  #
  # **Collection Items**
  #
  # Each entry in the **organizations** array has the following attributes:
  #
  #     Name             Type          Description
  #     id               Integer       Value uniquely identifying the organization.
  #     login            String        Login set on GitHub.
  #     name             String        Name set on GitHub.
  #     github_id        Integer       Id set on GitHub.
  #     avatar_url       String        Avatar_url set on GitHub.
  #     education        Boolean       Whether or not the organization has an education account.
  #     allow_migration  Unknown       The organization's allow_migration.
  #     repositories     [Repository]  Repositories belonging to this organization.
  #     installation     Installation  Installation belonging to the organization.
  #
  # ## Actions
  #
  # **For Current User**
  #
  # This returns a list of organizations the current user is a member of.
  #
  # GET <code>/orgs</code>
  #
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #     limit              Integer   How many organizations to include in the response. Used for pagination.
  #     offset             Integer   How many organizations to skip before the first entry in the response. Used for pagination.
  #     organization.role  Unknown   Documentation missing.
  #     role               Unknown   Alias for organization.role.
  #     sort_by            [String]  Attributes to sort organizations by. Used for pagination.
  #
  #     Example:GET /orgs?limit=5
  #
  # **Sortable by:** <code>id</code>, <code>login</code>, <code>name</code>, <code>github_id</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # @return [Success, RequestError]
  def organizations
    get("#{without_repo}/orgs")
  end

  # This will be either a user or organization.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name    Type     Description
  #     id      Integer  Value uniquely identifying the owner.
  #     login   String   User or organization login set on GitHub.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name        Type     Description
  #     id          Integer  Value uniquely identifying the owner.
  #     login       String   User or organization login set on GitHub.
  #     name        String   User or organization name set on GitHub.
  #     github_id   Integer  User or organization id set on GitHub.
  #     avatar_url  String   Link to user or organization avatar (image) set on GitHub.
  #
  # **Additional Attributes**
  #
  #     Name           Type           Description
  #     repositories   [Repository]   Repositories belonging to this account.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns an individual owner. It is possible to use the GitHub login or github_id in the request.
  #
  # GET <code>/owner/{owner.login}</code>
  #
  #     Template Variable  Type      Description
  #     owner.login        String    User or organization login set on GitHub.
  #
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/danielpclark
  #
  # GET <code>/owner/{user.login}</code>
  #
  #     Template Variable  Type      Description
  #     user.login         String    Login set on Github.
  #
  #     Query Parameter    Type      Description
  #     include            [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/danielpclark
  #
  # GET <code>/owner/{organization.login}</code>
  #
  #     Template Variable   Type      Description
  #     organization.login  String    Login set on GitHub.
  #
  #     Query Parameter     Type      Description
  #     include             [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/travis-ci
  #
  # GET <code>/owner/github_id/{owner.github_id}</code>
  #
  #     Template Variable   Type      Description
  #     owner.github_id     Integer   User or organization id set on GitHub.
  #
  #     Query Parameter     Type      Description
  #     include             [String]  List of attributes to eager load.
  #
  #     Example: GET /owner/github_id/639823
  #
  # @param owner [String] username or github ID
  # @return [Success, RequestError]
  def owner(owner = username)
    if /^\d+$/.match? owner.to_s
      get("#{without_repo}/owner/github_id/#{owner}")
    else
      get("#{without_repo}/owner/#{owner}")
    end
  end

  # A list of repositories for the current user.
  #
  # ## Attributes
  #
  #     Name           Type           Description
  #     repositories   [Repository]   List of repositories.
  #
  # **Collection Items**
  #
  # Each entry in the repositories array has the following attributes:
  #
  #     Name                Type     Description
  #     id                  Integer  Value uniquely identifying the repository.
  #     name                String   The repository's name on GitHub.
  #     slug                String   Same as {repository.owner.name}/{repository.name}.
  #     description         String   The repository's description from GitHub.
  #     github_language     String   The main programming language used according to GitHub.
  #     active              Boolean  Whether or not this repository is currently enabled on Travis CI.
  #     private             Boolean  Whether or not this repository is private.
  #     owner               Owner    GitHub user or organization the repository belongs to.
  #     default_branch      Branch   The default branch on GitHub.
  #     starred             Boolean  Whether or not this repository is starred.
  #     current_build       Build    The most recently started build (this excludes builds that have been created but have not yet started).
  #     last_started_build  Build    Alias for current_build.
  #
  # ## Actions
  #
  # **For Owner**
  #
  # This returns a list of repositories an owner has access to.
  #
  # GET <code>/owner/{owner.login}/repos</code>
  #
  #     Template Variable  Type    Description
  #     owner.login        String  User or organization login set on GitHub.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/owner/{user.login}/repos</code>
  #
  #     Template Variable  Type    Description
  #     user.login         String  Login set on Github.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/owner/{organization.login}/repos</code>
  #
  #     Template Variable   Type    Description
  #     organization.login  String  Login set on GitHub.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/travis-ci/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # GET <code>/owner/github_id/{owner.github_id}/repos</code>
  #
  #     Template Variable  Type     Description
  #     owner.github_id    Integer  User or organization id set on GitHub.
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /owner/github_id/639823/repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # **For Current User**<br />
  # This returns a list of repositories the current user has access to.
  #
  # GET <code>/repos</code>
  #
  #     Query Parameter     Type       Description
  #     active              [Boolean]  Alias for repository.active.
  #     include             [String]   List of attributes to eager load.
  #     limit               Integer    How many repositories to include in the response. Used for pagination.
  #     offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
  #     private             [Boolean]  Alias for repository.private.
  #     repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
  #     repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
  #     repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
  #     sort_by             [String]   Attributes to sort repositories by. Used for pagination.
  #     starred             [Boolean]  Alias for repository.starred.
  #
  #     Example: GET /repos?limit=5&sort_by=active,name
  #
  # **Sortable by:** <code>id</code>, <code>github_id</code>, <code>owner_name</code>, <code>name</code>, <code>active</code>, <code>default_branch.last_build</code>, append <code>:desc</code> to any attribute to reverse order.
  #
  # @param owner [String] username or github ID
  # @return [Success, RequestError]
  def repositories(owner = username)
    if /^\d+$/.match? owner.to_s
      get("#{without_repo}/owner/github_id/#{owner}/repos#{opts}")
    else
      get("#{without_repo}/owner/#{owner}/repos#{opts}")
    end
  end

  # An individual repository.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name   Type     Description
  #     id     Integer  Value uniquely identifying the repository.
  #     name   String   The repository's name on GitHub.
  #     slug   String   Same as {repository.owner.name}/{repository.name}.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is eager loaded.
  #
  #     Name             Type     Description
  #     id               Integer  Value uniquely identifying the repository.
  #     name             String   The repository's name on GitHub.
  #     slug             String   Same as {repository.owner.name}/{repository.name}.
  #     description      String   The repository's description from GitHub.
  #     github_language  String   The main programming language used according to GitHub.
  #     active           Boolean  Whether or not this repository is currently enabled on Travis CI.
  #     private          Boolean  Whether or not this repository is private.
  #     owner            Owner    GitHub user or organization the repository belongs to.
  #     default_branch   Branch   The default branch on GitHub.
  #     starred          Boolean  Whether or not this repository is starred.
  #
  # ## Actions
  #
  # **Find**
  #
  # This returns an individual repository.
  #
  # GET <code>/repo/{repository.id}</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /repo/891
  #
  # GET <code>/repo/{repository.slug}</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example: GET /repo/rails%2Frails
  #
  # **Activate**
  #
  # This will activate a repository, allowing its tests to be run on Travis CI.
  #
  # POST <code>/repo/{repository.id}/activate</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/activate
  #
  # POST <code>/repo/{repository.slug}/activate</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/activate
  #
  # **Deactivate**
  #
  # This will deactivate a repository, preventing any tests from running on Travis CI.
  #
  # POST <code>/repo/{repository.id}/deactivate</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/deactivate
  #
  # POST <code>/repo/{repository.slug}/deactivate</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/deactivate
  #
  # **Star**
  #
  # This will star a repository based on the currently logged in user.
  #
  # POST <code>/repo/{repository.id}/star</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/star
  #
  # POST <code>/repo/{repository.slug}/star</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/star
  #
  # **Unstar**
  #
  # This will unstar a repository based on the currently logged in user.
  #
  # POST <code>/repo/{repository.id}/unstar</code>
  #
  #     Template Variable  Type     Description
  #     repository.id      Integer  Value uniquely identifying the repository.
  #
  #     Example: POST /repo/891/unstar
  #
  # POST <code>/repo/{repository.slug}/unstar</code>
  #
  #     Template Variable  Type    Description
  #     repository.slug    String  Same as {repository.owner.name}/{repository.name}.
  #
  #     Example: POST /repo/rails%2Frails/unstar
  #
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param repo [String] github_username/repository_name
  # @param action [String, Symbol] Optional argument for star/unstar/activate/deactivate
  # @raise [InvalidRepository] if given input does not
  #   conform to valid repository identifier format
  # @return [Success, RequestError]
  def repository(repo = repository_name, action = nil)
    raise InvalidRepository unless repo_slug_or_id? repo

    repo = sanitize_repo_name repo
    action = '' unless %w[star unstar activate deavtivate].include? action.to_s

    if action.empty?
      get("#{without_repo}/repo/#{repo}")
    else
      post("#{without_repo}/repo/#{repo}/#{action}")
    end
  end

  # An individual user.
  #
  # ## Attributes
  #
  # **Minimal Representation**
  #
  # Included when the resource is returned as part of another resource.
  #
  #     Name  Type     Description
  #     id    Integer  Value uniquely identifying the user.
  #     login String   Login set on Github.
  #
  # **Standard Representation**
  #
  # Included when the resource is the main response of a request, or is {https://developer.travis-ci.com/eager-loading eager loaded}.
  #
  #     Name              Type     Description
  #     id                Integer  Value uniquely identifying the user.
  #     login             String   Login set on Github.
  #     name              String   Name set on GitHub.
  #     github_id         Integer  Id set on GitHub.
  #     avatar_url        String   Avatar URL set on GitHub.
  #     education         Boolean  Whether or not the user has an education account.
  #     allow_migration   Unknown  The user's allow_migration.
  #     is_syncing        Boolean  Whether or not the user is currently being synced with Github.
  #     synced_at         String   The last time the user was synced with GitHub.
  #
  # **Additional Attributes**
  #
  #     Name          Type          Description
  #     repositories  [Repository]  Repositories belonging to this user.
  #     installation  Installation  Installation belonging to the user.
  #     emails        Unknown       The user's emails.
  #
  # ## Actions
  #
  # **Find**
  #
  # This will return information about an individual user.
  #
  # GET <code>/user/{user.id}</code>
  #
  #     Template Variable  Type     Description
  #     user.id            Integer  Value uniquely identifying the user.
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /user/119240
  #
  # **Sync**
  #
  # This triggers a sync on a user's account with their GitHub account.
  #
  # POST <code>/user/{user.id}/sync</code>
  #
  #     Template Variable  Type     Description
  #     user.id            Integer  Value uniquely identifying the user.
  #
  #     Example:POST /user/119240/sync
  #
  # **Current**
  #
  # This will return information about the current user.
  #
  # GET <code>/user</code>
  #
  #     Query Parameter  Type      Description
  #     include          [String]  List of attributes to eager load.
  #
  #     Example:GET /user
  #
  # @note sync feature may not be permitted
  # @note POST requests require an authorization token set in the headers. See: {h}
  #
  # @param user_id [String, Integer] optional user id
  # @param sync [Boolean] optional argument for syncing your Travis CI account with Github
  # @raise [TypeError] if given user id is not a number
  # @return [Success, RequestError]
  def user(user_id = nil, sync = false)
    return get("#{without_repo}/user") if !user_id && !sync
    raise TypeError, 'Integer expected for user id' unless /^\d+$/.match? user_id.to_s

    if sync
      get("#{without_repo}/user/#{user_id}/sync")
    else
      get("#{without_repo}/user/#{user_id}")
    end
  end

  private # @private

  def get(url, raw_reply = false)
    Trav3::GET.call(self, url, raw_reply)
  end

  def initial_defaults
    defaults(limit: 25)
    h('Content-Type': 'application/json')
    h('Accept': 'application/json')
    h('Travis-API-Version': 3)
  end

  def opts
    @options
  end

  def post(url, fields = {})
    Trav3::POST.call(self, url, fields)
  end

  def repo_slug_or_id?(repo)
    Regexp.new(/(^\d+$)|(^\w+(?:\/|%2F){1}\w+$)/).match? repo
  end

  def repository_name
    @repo
  end

  def sanitize_repo_name(repo)
    repo.to_s.gsub(/\//, '%2F')
  end

  def username
    @repo[/.*?(?=(?:\/|%2F)|$)/]
  end

  def with_repo
    "#{api_endpoint}/repo/#{@repo}"
  end

  def without_repo
    api_endpoint
  end
end

Instance Method Details

#branch(name) ⇒ Success, RequestError

The branch of a GitHub repository. Useful for obtaining information about the last build on a given branch.

If querying using the repository slug, it must be formatted using standard URL encoding, including any special characters.

Attributes

Minimal Representation

Included when the resource is returned as part of another resource.

Name  Type    Description
name  String  Name of the git branch.

Standard Representation

Included when the resource is the main response of a request, or is eager loaded.

Name              Type        Description
name              String      Name of the git branch.
repository        Repository  GitHub user or organization the branch belongs to.
default_branch    Boolean     Whether or not this is the resposiotry's default branch.
exists_on_github  Boolean     Whether or not the branch still exists on GitHub.
last_build        Build       Last build on the branch.

Additional Attributes

Name           Type     Description
recent_builds  [Build]  Last 10 builds on the branch (when `include=branch.recent_builds` is used).

Actions

Find

This will return information about an individual branch. The request can include either the repository id or slug.

GET /repo/{repository.id}/branch/{branch.name}

Template Variable  Type     Description
repository.id      Integer  Value uniquely identifying the repository.
branch.name        String   Name of the git branch.
Query Parameter  Type      Description
include          [String]  List of attributes to eager load.

Example:GET /repo/891/branch/master

GET /repo/{repository.slug}/branch/{branch.name}

Template Variable  Type    Description
repository.slug    String  Same as {repository.owner.name}/{repository.name}.
branch.name        String  Name of the git branch.
Query Parameter  Type      Description
include          [String]  List of attributes to eager load.

Example:GET /repo/rails%2Frails/branch/master

Parameters:

  • id (String)

    the branch name for the current repository

Returns:


138
139
140
# File 'lib/trav3.rb', line 138

def branch(name)
  get("#{with_repo}/branch/#{name}#{opts}")
end

#branchesSuccess, RequestError

A list of branches.

If querying using the repository slug, it must be formatted using standard URL encoding, including any special characters.

Attributes

Name      Type      Description
branches  [Branch]  List of branches.

Collection Items

Each entry in the branches array has the following attributes:

Name              Type        Description
name              String      Name of the git branch.
repository        Repository  GitHub user or organization the branch belongs to.
default_branch    Boolean     Whether or not this is the resposiotry's default branch.
exists_on_github  Boolean     Whether or not the branch still exists on GitHub.
last_build        Build       Last build on the branch.
recent_builds    [Build]      Last 10 builds on the branch (when `include=branch.recent_builds` is used).

Actions

Find

This will return a list of branches a repository has on GitHub.

GET /repo/{repository.id}/branches

Template Variable  Type     Description
repository.id      Integer  Value uniquely identifying the repository.
Query Parameter          Type       Description
branch.exists_on_github  [Boolean]  Filters branches by whether or not the branch still exists on GitHub.
exists_on_github         [Boolean]  Alias for branch.exists_on_github.
include                  [String]   List of attributes to eager load.
limit                    Integer    How many branches to include in the response. Used for pagination.
offset                   Integer    How many branches to skip before the first entry in the response. Used for pagination.
sort_by                  [String]   Attributes to sort branches by. Used for pagination.

Example:GET /repo/891/branches?limit=5&exists_on_github=true

Sortable by: name, last_build, exists_on_github, default_branch, append :desc to any attribute to reverse order. The default value is default_branch,exists_on_github,last_build:desc.

GET /repo/{repository.slug}/branches

Template Variable  Type    Description
repository.slug    String  Same as {repository.owner.name}/{repository.name}.
Query Parameter          Type       Description
branch.exists_on_github  [Boolean]  Filters branches by whether or not the branch still exists on GitHub.
exists_on_github         [Boolean]  Alias for branch.exists_on_github.
include                  [String]   List of attributes to eager load.
limit                    Integer    How many branches to include in the response. Used for pagination.
offset                   Integer    How many branches to skip before the first entry in the response. Used for pagination.
sort_by                  [String]   Attributes to sort branches by. Used for pagination.

Example:GET /repo/rails%2Frails/branches?limit=5&exists_on_github=true

Sortable by: name, last_build, exists_on_github, default_branch, append :desc to any attribute to reverse order. The default value is default_branch,exists_on_github,last_build:desc.

Returns:


204
205
206
# File 'lib/trav3.rb', line 204

def branches
  get("#{with_repo}/branches#{opts}")
end

#build(id) ⇒ Success, RequestError

Note:

POST requests require an authorization token set in the headers. See: #h

An individual build.

Attributes

Minimal Representation

Included when the resource is returned as part of another resource.

Name                 Type     Description
id                   Integer  Value uniquely identifying the build.
number               String   Incremental number for a repository's builds.
state                String   Current state of the build.
duration             Integer  Wall clock time in seconds.
event_type           String   Event that triggered the build.
previous_state       String   State of the previous build (useful to see if state changed).
pull_request_title   String   Title of the build's pull request.
pull_request_number  Integer  Number of the build's pull request.
started_at           String   When the build started.
finished_at          String   When the build finished.

Standard Representation

Included when the resource is the main response of a request, or is eager loaded.

Name                 Type        Description
id                   Integer     Value uniquely identifying the build.
number               String      Incremental number for a repository's builds.
state                String      Current state of the build.
duration             Integer     Wall clock time in seconds.
event_type           String      Event that triggered the build.
previous_state       String      State of the previous build (useful to see if state changed).
pull_request_title   String      Title of the build's pull request.
pull_request_number  Integer     Number of the build's pull request.
started_at           String      When the build started.
finished_at          String      When the build finished.
repository           Repository  GitHub user or organization the build belongs to.
branch               Branch      The branch the build is associated with.
tag                  Unknown     The build's tag.
commit               Commit      The commit the build is associated with.
jobs                 Jobs        List of jobs that are part of the build's matrix.
stages               [Stage]     The stages of a build.
created_by           Owner       The User or Organization that created the build.
updated_at           Unknown     The build's updated_at.

Actions

Find

This returns a single build.

GET /build/{build.id}

Template Variable  Type     Description
build.id           Integer  Value uniquely identifying the build.

Query Parameter  Type      Description
include          [String]  List of attributes to eager load.

Example: GET /build/86601346

Cancel

This cancels a currently running build. It will set the build and associated jobs to "state": "canceled".

POST /build/{build.id}/cancel

Template Variable  Type     Description
build.id           Integer  Value uniquely identifying the build.

Example: POST /build/86601346/cancel

Restart

This restarts a build that has completed or been canceled.

POST /build/{build.id}/restart

Template Variable  Type     Description
build.id           Integer  Value uniquely identifying the build.

Example: POST /build/86601346/restart

Parameters:

  • id (String, Integer)

    the build id number

Returns:


294
295
296
# File 'lib/trav3.rb', line 294

def build(id)
  get("#{without_repo}/build/#{id}")
end

#build_jobs(id) ⇒ Success, RequestError

A list of jobs.

Attributes

Name  Type  Description
jobs  [Job]  List of jobs.

Collection Items

Each entry in the jobs array has the following attributes:

Name           Type        Description
id             Integer     Value uniquely identifying the job.
allow_failure  Unknown     The job's allow_failure.
number         String      Incremental number for a repository's builds.
state          String      Current state of the job.
started_at     String      When the job started.
finished_at    String      When the job finished.
build          Build       The build the job is associated with.
queue          String      Worker queue this job is/was scheduled on.
repository     Repository  GitHub user or organization the job belongs to.
commit         Commit      The commit the job is associated with.
owner          Owner       GitHub user or organization the job belongs to.
stage          [Stage]     The stages of a job.
created_at     String      When the job was created.
updated_at     String      When the job was updated.
config         Object      The job's config.

Actions

Find

This returns a list of jobs belonging to an individual build.

GET /build/{build.id}/jobs

Template Variable  Type     Description
build.id           Integer  Value uniquely identifying the build.

Query Parameter  Type      Description
include          [String]  List of attributes to eager load.

Example: GET /build/86601346/jobs

For Current User

This returns a list of jobs a current user has access to.

GET /jobs

Query Parameter  Type      Description
active           Unknown   Alias for job.active.
created_by       Unknown   Alias for job.created_by.
include          [String]  List of attributes to eager load.
job.active       Unknown   Documentation missing.
job.created_by   Unknown   Documentation missing.
job.state        [String]  Filters jobs by current state of the job.
limit            Integer   How many jobs to include in the response. Used for pagination.
offset           Integer   How many jobs to skip before the first entry in the response. Used for pagination.
sort_by          [String]  Attributes to sort jobs by. Used for pagination.
state            [String]  Alias for job.state.

Example: GET /jobs?limit=5

Sortable by: id, append :desc to any attribute to reverse order. The default value is id:desc.

Parameters:

  • id (String, Integer)

    the build id number

Returns:


477
478
479
# File 'lib/trav3.rb', line 477

def build_jobs(id)
  get("#{without_repo}/build/#{id}/jobs")
end

#buildsSuccess, RequestError

A list of builds.

Attributes

Name    Type     Description
builds  [Build]  List of builds.

Collection Items

Each entry in the builds array has the following attributes:

Name                 Type        Description
id                   Integer     Value uniquely identifying the build.
number               String      Incremental number for a repository's builds.
state                String      Current state of the build.
duration             Integer     Wall clock time in seconds.
event_type           String      Event that triggered the build.
previous_state       String      State of the previous build (useful to see if state changed).
pull_request_title   String      Title of the build's pull request.
pull_request_number  Integer     Number of the build's pull request.
started_at           String      When the build started.
finished_at          String      When the build finished.
repository           Repository  GitHub user or organization the build belongs to.
branch               Branch      The branch the build is associated with.
tag                  Unknown     The build's tag.
commit               Commit      The commit the build is associated with.
jobs                 Jobs        List of jobs that are part of the build's matrix.
stages               [Stage]     The stages of a build.
created_by           Owner       The User or Organization that created the build.
updated_at           Unknown     The build's updated_at.
request              Unknown     The build's request.

Actions

For Current User

This returns a list of builds for the current user. The result is paginated.

GET /builds

Query Parameter  Type      Description
include          [String]  List of attributes to eager load.
limit            Integer   How many builds to include in the response. Used for pagination.
limit            Integer   How many builds to include in the response. Used for pagination.
offset           Integer   How many builds to skip before the first entry in the response. Used for pagination.
offset           Integer   How many builds to skip before the first entry in the response. Used for pagination.
sort_by          [String]  Attributes to sort builds by. Used for pagination.
sort_by          [String]  Attributes to sort builds by. Used for pagination.

Example: GET /builds?limit=5

Sortable by: id, started_at, finished_at, append :desc to any attribute to reverse order.

Find

This returns a list of builds for an individual repository. It is possible to use the repository id or slug in the request. The result is paginated. Each request will return 25 results.

GET /repo/{repository.id}/builds

Template Variable  Type     Description
repository.id      Integer  Value uniquely identifying the repository.

Query Parameter       Type      Description
branch.name           [String]  Filters builds by name of the git branch.
build.created_by      [Owner]   Filters builds by the User or Organization that created the build.
build.event_type      [String]  Filters builds by event that triggered the build.
build.previous_state  [String]  Filters builds by state of the previous build (useful to see if state changed).
build.state           [String]  Filters builds by current state of the build.
created_by            [Owner]   Alias for build.created_by.
event_type            [String]  Alias for build.event_type.
include               [String]  List of attributes to eager load.
limit                 Integer   How many builds to include in the response. Used for pagination.
offset                Integer   How many builds to skip before the first entry in the response. Used for pagination.
previous_state        [String]  Alias for build.previous_state.
sort_by               [String]  Attributes to sort builds by. Used for pagination.
state                 [String]  Alias for build.state.

Example: GET /repo/891/builds?limit=5

Sortable by: id, started_at, finished_at, append :desc to any attribute to reverse order.

GET /repo/{repository.slug}/builds

Template Variable  Type    Description
repository.slug    String  Same as {repository.owner.name}/{repository.name}.

Query Parameter       Type      Description
branch.name           [String]  Filters builds by name of the git branch.
build.created_by      [Owner]   Filters builds by the User or Organization that created the build.
build.event_type      [String]  Filters builds by event that triggered the build.
build.previous_state  [String]  Filters builds by state of the previous build (useful to see if state changed).
build.state           [String]  Filters builds by current state of the build.
created_by            [Owner]   Alias for build.created_by.
event_type            [String]  Alias for build.event_type.
include               [String]  List of attributes to eager load.
limit                 Integer   How many builds to include in the response. Used for pagination.
offset                Integer   How many builds to skip before the first entry in the response. Used for pagination.
previous_state        [String]  Alias for build.previous_state.
sort_by               [String]  Attributes to sort builds by. Used for pagination.
state                 [String]  Alias for build.state.

Example: GET /repo/rails%2Frails/builds?limit=5

Sortable by: id, started_at, finished_at, append :desc to any attribute to reverse order.

Returns:


404
405
406
# File 'lib/trav3.rb', line 404

def builds
  get("#{with_repo}/builds#{opts}")
end

#defaults(key: value, ...) ⇒ self

Set as many options as you'd like for collections queried via an API request

Parameters:

  • key (Symbol, String)

    name for value to set

  • value (Symbol, String, Integer)

    value for key

Returns:

  • (self)

63
64
65
66
# File 'lib/trav3.rb', line 63

def defaults(**args)
  (@options ||= Options.new).build(**args)
  self
end

#h(key: value, ...) ⇒ self

Set as many headers as you'd like for API requests

h("Authorization": "token xxxxxxxxxxxxxxxxxxxxxx")

Parameters:

  • key (Symbol, String)

    name for value to set

  • value (Symbol, String, Integer)

    value for key

Returns:

  • (self)

76
77
78
79
# File 'lib/trav3.rb', line 76

def h(**args)
  (@headers ||= Headers.new).build(**args)
  self
end

#job(id, option = nil) ⇒ Success, RequestError

Note:

POST requests require an authorization token set in the headers. See: #h

An individual job.

Attributes

Minimal Representation

Included when the resource is returned as part of another resource.

Name  Type     Description
id    Integer  Value uniquely identifying the job.

Standard Representation

Included when the resource is the main response of a request, or is eager loaded.

Name           Type        Description
id             Integer     Value uniquely identifying the job.
allow_failure  Unknown     The job's allow_failure.
number         String      Incremental number for a repository's builds.
state          String      Current state of the job.
started_at     String      When the job started.
finished_at    String      When the job finished.
build          Build       The build the job is associated with.
queue          String      Worker queue this job is/was scheduled on.
repository     Repository  GitHub user or organization the job belongs to.
commit         Commit      The commit the job is associated with.
owner          Owner       GitHub user or organization the job belongs to.
stage          [Stage]     The stages of a job.
created_at     String      When the job was created.
updated_at     String      When the job was updated.

Actions

Find

This returns a single job.

GET /job/{job.id}

Template Variable  Type     Description
job.id             Integer  Value uniquely identifying the job.

Query Parameter  Type      Description
include          [String]  List of attributes to eager load.

Example: GET /job/86601347

Cancel

This cancels a currently running job.

POST /job/{job.id}/cancel

Template Variable  Type     Description
job.id             Integer  Value uniquely identifying the job.

Example: POST /job/86601347/cancel

Restart

This restarts a job that has completed or been canceled.

POST /job/{job.id}/restart

Template Variable  Type     Description
job.id             Integer  Value uniquely identifying the job.

Example: POST /job/86601347/restart

Debug

This restarts a job in debug mode, enabling the logged-in user to ssh into the build VM. Please note this feature is only available on the travis-ci.com domain, and those repositories on the travis-ci.org domain for which the debug feature is enabled. See this document for more details.

POST /job/{job.id}/debug

Template Variable  Type     Description
job.id             Integer  Value uniquely identifying the job.

Example: POST /job/86601347/debug

Parameters:

  • id (String, Integer)

    the job id number

  • option (Symbol) (defaults to: nil)

    options for :cancel, :restart, or :debug

Returns:


566
567
568
569
570
571
572
573
574
575
576
577
# File 'lib/trav3.rb', line 566

def job(id, option = nil)
  case option
  when :cancel
    post("#{without_repo}/job/#{id}/cancel")
  when :restart
    post("#{without_repo}/job/#{id}/restart")
  when :debug
    post("#{without_repo}/job/#{id}/debug")
  else
    get("#{without_repo}/job/#{id}")
  end
end

#lint(yaml_content) ⇒ Success, RequestError

This validates the .travis.yml file and returns any warnings.

The request body can contain the content of the .travis.yml file directly as a string, eg "foo: bar".

Attributes

Name      Type   Description
warnings  Array  An array of hashes with keys and warnings.

Actions

Lint

POST /lint

Example:POST /lint

Parameters:

  • yaml_content (String)

    the contents for the file .travis.yml

Returns:

Raises:

  • (TypeError)

598
599
600
601
602
603
604
605
606
# File 'lib/trav3.rb', line 598

def lint(yaml_content)
  raise TypeError, "String expected, #{yaml_content.class} given" unless \
    yaml_content.is_a? String

  ct = headers.remove(:'Content-Type')
  result = post("#{without_repo}/lint", body: yaml_content)
  h('Content-Type': ct) if ct
  result
end

#log(id, option = nil) ⇒ Success, ...

Note:

DELETE is unimplemented

An individual log.

Attributes

Minimal Representation

Included when the resource is returned as part of another resource.

Name  Type     Description
id    Unknown  The log's id.

Standard Representation

Included when the resource is the main response of a request, or is eager loaded.

Name       Type     Description
id         Unknown  The log's id.
content    Unknown  The log's content.
log_parts  Unknown  The log's log_parts.

Actions

Find

This returns a single log.

It's possible to specify the accept format of the request as text/plain if required. This will return the content of the log as a single blob of text.

curl -H "Travis-API-Version: 3" \
  -H "Accept: text/plain" \
  -H "Authorization: token xxxxxxxxxxxx" \
  https://api.travis-ci.org/job/{job.id}/log

The default response type is application/json, and will include additional meta data such as @type, @representation etc. (see https://developer.travis-ci.org/format).

GET /job/{job.id}/log

Template Variable  Type     Description
job.id             Integer  Value uniquely identifying the job.

Query Parameter  Type      Description
include          [String]  List of attributes to eager load.
log.token        Unknown   Documentation missing.

Example: GET /job/86601347/log

GET /job/{job.id}/log.txt

Template Variable  Type     Description
job.id             Integer  Value uniquely identifying the job.

Query Parameter  Type      Description
include          [String]  List of attributes to eager load.
log.token        Unknown   Documentation missing.

Example:GET /job/86601347/log.txt

Delete

This removes the contents of a log. It gets replace with the message: Log removed by XXX at 2017-02-13 16:00:00 UTC.

curl -X DELETE \
  -H "Travis-API-Version: 3" \
  -H "Authorization: token xxxxxxxxxxxx" \
  https://api.travis-ci.org/job/{job.id}/log

DELETE /job/{job.id}/log

Template Variable  Type     Description
job.id             Integer  Value uniquely identifying the job.

Example: DELETE /job/86601347/log

Parameters:

  • id (String, Integer)

    the job id number

  • option (Symbol) (defaults to: nil)

    options for :text or :delete

Returns:


686
687
688
689
690
691
692
693
694
695
# File 'lib/trav3.rb', line 686

def log(id, option = nil)
  case option
  when :text
    get("#{without_repo}/job/#{id}/log.txt", true)
  when :delete
    raise Unimplemented
  else
    get("#{without_repo}/job/#{id}/log")
  end
end

#organization(org_id) ⇒ Success, RequestError

An individual organization.

Attributes

Minimal Representation

Included when the resource is returned as part of another resource.

Name   Type     Description
id     Integer  Value uniquely identifying the organization.
login  String   Login set on GitHub.

Standard Representation

Included when the resource is the main response of a request, or is eager loaded.

Name             Type     Description
id               Integer  Value uniquely identifying the organization.
login            String   Login set on GitHub.
name             String   Name set on GitHub.
github_id        Integer  Id set on GitHub.
avatar_url       String   Avatar_url set on GitHub.
education        Boolean  Whether or not the organization has an education account.
allow_migration  Unknown  The organization's allow_migration.

Additional Attributes

Name          Type          Description
repositories  [Repository]  Repositories belonging to this organization.
installation  Installation  Installation belonging to the organization.

Actions

Find

This returns an individual organization.

GET /org/{organization.id}

Template Variable  Type      Description
organization.id    Integer   Value uniquely identifying the organization.
Query Parameter    Type      Description
include            [String]  List of attributes to eager load.

Example:GET /org/87

Parameters:

  • org_id (String, Integer)

    the organization id

Returns:

Raises:

  • (TypeError)

    if given organization id is not a number


746
747
748
749
750
# File 'lib/trav3.rb', line 746

def organization(org_id)
  raise TypeError, 'Integer expected for organization id' unless /^\d+$/.match? org_id.to_s

  get("#{without_repo}/org/#{org_id}")
end

#organizationsSuccess, RequestError

A list of organizations for the current user.

Attributes

Name           Type            Description
organizations  [Organization]  List of organizations.

Collection Items

Each entry in the organizations array has the following attributes:

Name             Type          Description
id               Integer       Value uniquely identifying the organization.
login            String        Login set on GitHub.
name             String        Name set on GitHub.
github_id        Integer       Id set on GitHub.
avatar_url       String        Avatar_url set on GitHub.
education        Boolean       Whether or not the organization has an education account.
allow_migration  Unknown       The organization's allow_migration.
repositories     [Repository]  Repositories belonging to this organization.
installation     Installation  Installation belonging to the organization.

Actions

For Current User

This returns a list of organizations the current user is a member of.

GET /orgs

Query Parameter    Type      Description
include            [String]  List of attributes to eager load.
limit              Integer   How many organizations to include in the response. Used for pagination.
offset             Integer   How many organizations to skip before the first entry in the response. Used for pagination.
organization.role  Unknown   Documentation missing.
role               Unknown   Alias for organization.role.
sort_by            [String]  Attributes to sort organizations by. Used for pagination.

Example:GET /orgs?limit=5

Sortable by: id, login, name, github_id, append :desc to any attribute to reverse order.

Returns:


795
796
797
# File 'lib/trav3.rb', line 795

def organizations
  get("#{without_repo}/orgs")
end

#owner(owner = username) ⇒ Success, RequestError

This will be either a user or organization.

Attributes

Minimal Representation

Included when the resource is returned as part of another resource.

Name    Type     Description
id      Integer  Value uniquely identifying the owner.
login   String   User or organization login set on GitHub.

Standard Representation

Included when the resource is the main response of a request, or is eager loaded.

Name        Type     Description
id          Integer  Value uniquely identifying the owner.
login       String   User or organization login set on GitHub.
name        String   User or organization name set on GitHub.
github_id   Integer  User or organization id set on GitHub.
avatar_url  String   Link to user or organization avatar (image) set on GitHub.

Additional Attributes

Name           Type           Description
repositories   [Repository]   Repositories belonging to this account.

Actions

Find

This returns an individual owner. It is possible to use the GitHub login or github_id in the request.

GET /owner/{owner.login}

Template Variable  Type      Description
owner.login        String    User or organization login set on GitHub.

Query Parameter    Type      Description
include            [String]  List of attributes to eager load.

Example: GET /owner/danielpclark

GET /owner/{user.login}

Template Variable  Type      Description
user.login         String    Login set on Github.

Query Parameter    Type      Description
include            [String]  List of attributes to eager load.

Example: GET /owner/danielpclark

GET /owner/{organization.login}

Template Variable   Type      Description
organization.login  String    Login set on GitHub.

Query Parameter     Type      Description
include             [String]  List of attributes to eager load.

Example: GET /owner/travis-ci

GET /owner/github_id/{owner.github_id}

Template Variable   Type      Description
owner.github_id     Integer   User or organization id set on GitHub.

Query Parameter     Type      Description
include             [String]  List of attributes to eager load.

Example: GET /owner/github_id/639823

Parameters:

  • owner (String) (defaults to: username)

    username or github ID

Returns:


875
876
877
878
879
880
881
# File 'lib/trav3.rb', line 875

def owner(owner = username)
  if /^\d+$/.match? owner.to_s
    get("#{without_repo}/owner/github_id/#{owner}")
  else
    get("#{without_repo}/owner/#{owner}")
  end
end

#repositories(owner = username) ⇒ Success, RequestError

A list of repositories for the current user.

Attributes

Name           Type           Description
repositories   [Repository]   List of repositories.

Collection Items

Each entry in the repositories array has the following attributes:

Name                Type     Description
id                  Integer  Value uniquely identifying the repository.
name                String   The repository's name on GitHub.
slug                String   Same as {repository.owner.name}/{repository.name}.
description         String   The repository's description from GitHub.
github_language     String   The main programming language used according to GitHub.
active              Boolean  Whether or not this repository is currently enabled on Travis CI.
private             Boolean  Whether or not this repository is private.
owner               Owner    GitHub user or organization the repository belongs to.
default_branch      Branch   The default branch on GitHub.
starred             Boolean  Whether or not this repository is starred.
current_build       Build    The most recently started build (this excludes builds that have been created but have not yet started).
last_started_build  Build    Alias for current_build.

Actions

For Owner

This returns a list of repositories an owner has access to.

GET /owner/{owner.login}/repos

Template Variable  Type    Description
owner.login        String  User or organization login set on GitHub.

Query Parameter     Type       Description
active              [Boolean]  Alias for repository.active.
include             [String]   List of attributes to eager load.
limit               Integer    How many repositories to include in the response. Used for pagination.
offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
private             [Boolean]  Alias for repository.private.
repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
sort_by             [String]   Attributes to sort repositories by. Used for pagination.
starred             [Boolean]  Alias for repository.starred.

Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name

Sortable by: id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.

GET /owner/{user.login}/repos

Template Variable  Type    Description
user.login         String  Login set on Github.

Query Parameter     Type       Description
active              [Boolean]  Alias for repository.active.
include             [String]   List of attributes to eager load.
limit               Integer    How many repositories to include in the response. Used for pagination.
offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
private             [Boolean]  Alias for repository.private.
repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
sort_by             [String]   Attributes to sort repositories by. Used for pagination.
starred             [Boolean]  Alias for repository.starred.

Example: GET /owner/danielpclark/repos?limit=5&sort_by=active,name

Sortable by: id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.

GET /owner/{organization.login}/repos

Template Variable   Type    Description
organization.login  String  Login set on GitHub.

Query Parameter     Type       Description
active              [Boolean]  Alias for repository.active.
include             [String]   List of attributes to eager load.
limit               Integer    How many repositories to include in the response. Used for pagination.
offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
private             [Boolean]  Alias for repository.private.
repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
sort_by             [String]   Attributes to sort repositories by. Used for pagination.
starred             [Boolean]  Alias for repository.starred.

Example: GET /owner/travis-ci/repos?limit=5&sort_by=active,name

Sortable by: id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.

GET /owner/github_id/{owner.github_id}/repos

Template Variable  Type     Description
owner.github_id    Integer  User or organization id set on GitHub.

Query Parameter     Type       Description
active              [Boolean]  Alias for repository.active.
include             [String]   List of attributes to eager load.
limit               Integer    How many repositories to include in the response. Used for pagination.
offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
private             [Boolean]  Alias for repository.private.
repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
sort_by             [String]   Attributes to sort repositories by. Used for pagination.
starred             [Boolean]  Alias for repository.starred.

Example: GET /owner/github_id/639823/repos?limit=5&sort_by=active,name

Sortable by: id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.

For Current User
This returns a list of repositories the current user has access to.

GET /repos

Query Parameter     Type       Description
active              [Boolean]  Alias for repository.active.
include             [String]   List of attributes to eager load.
limit               Integer    How many repositories to include in the response. Used for pagination.
offset              Integer    How many repositories to skip before the first entry in the response. Used for pagination.
private             [Boolean]  Alias for repository.private.
repository.active   [Boolean]  Filters repositories by whether or not this repository is currently enabled on Travis CI.
repository.private  [Boolean]  Filters repositories by whether or not this repository is private.
repository.starred  [Boolean]  Filters repositories by whether or not this repository is starred.
sort_by             [String]   Attributes to sort repositories by. Used for pagination.
starred             [Boolean]  Alias for repository.starred.

Example: GET /repos?limit=5&sort_by=active,name

Sortable by: id, github_id, owner_name, name, active, default_branch.last_build, append :desc to any attribute to reverse order.

Parameters:

  • owner (String) (defaults to: username)

    username or github ID

Returns:


1021
1022
1023
1024
1025
1026
1027
# File 'lib/trav3.rb', line 1021

def repositories(owner = username)
  if /^\d+$/.match? owner.to_s
    get("#{without_repo}/owner/github_id/#{owner}/repos#{opts}")
  else
    get("#{without_repo}/owner/#{owner}/repos#{opts}")
  end
end

#repository(repo = repository_name, action = nil) ⇒ Success, RequestError

Note:

POST requests require an authorization token set in the headers. See: #h

An individual repository.

Attributes

Minimal Representation

Included when the resource is returned as part of another resource.

Name   Type     Description
id     Integer  Value uniquely identifying the repository.
name   String   The repository's name on GitHub.
slug   String   Same as {repository.owner.name}/{repository.name}.

Standard Representation

Included when the resource is the main response of a request, or is eager loaded.

Name             Type     Description
id               Integer  Value uniquely identifying the repository.
name             String   The repository's name on GitHub.
slug             String   Same as {repository.owner.name}/{repository.name}.
description      String   The repository's description from GitHub.
github_language  String   The main programming language used according to GitHub.
active           Boolean  Whether or not this repository is currently enabled on Travis CI.
private          Boolean  Whether or not this repository is private.
owner            Owner    GitHub user or organization the repository belongs to.
default_branch   Branch   The default branch on GitHub.
starred          Boolean  Whether or not this repository is starred.

Actions

Find

This returns an individual repository.

GET /repo/{repository.id}

Template Variable  Type     Description
repository.id      Integer  Value uniquely identifying the repository.

Query Parameter  Type      Description
include          [String]  List of attributes to eager load.

Example: GET /repo/891

GET /repo/{repository.slug}

Template Variable  Type    Description
repository.slug    String  Same as {repository.owner.name}/{repository.name}.

Query Parameter  Type      Description
include          [String]  List of attributes to eager load.

Example: GET /repo/rails%2Frails

Activate

This will activate a repository, allowing its tests to be run on Travis CI.

POST /repo/{repository.id}/activate

Template Variable  Type     Description
repository.id      Integer  Value uniquely identifying the repository.

Example: POST /repo/891/activate

POST /repo/{repository.slug}/activate

Template Variable  Type    Description
repository.slug    String  Same as {repository.owner.name}/{repository.name}.

Example: POST /repo/rails%2Frails/activate

Deactivate

This will deactivate a repository, preventing any tests from running on Travis CI.

POST /repo/{repository.id}/deactivate

Template Variable  Type     Description
repository.id      Integer  Value uniquely identifying the repository.

Example: POST /repo/891/deactivate

POST /repo/{repository.slug}/deactivate

Template Variable  Type    Description
repository.slug    String  Same as {repository.owner.name}/{repository.name}.

Example: POST /repo/rails%2Frails/deactivate

Star

This will star a repository based on the currently logged in user.

POST /repo/{repository.id}/star

Template Variable  Type     Description
repository.id      Integer  Value uniquely identifying the repository.

Example: POST /repo/891/star

POST /repo/{repository.slug}/star

Template Variable  Type    Description
repository.slug    String  Same as {repository.owner.name}/{repository.name}.

Example: POST /repo/rails%2Frails/star

Unstar

This will unstar a repository based on the currently logged in user.

POST /repo/{repository.id}/unstar

Template Variable  Type     Description
repository.id      Integer  Value uniquely identifying the repository.

Example: POST /repo/891/unstar

POST /repo/{repository.slug}/unstar

Template Variable  Type    Description
repository.slug    String  Same as {repository.owner.name}/{repository.name}.

Example: POST /repo/rails%2Frails/unstar

Parameters:

  • repo (String) (defaults to: repository_name)

    github_username/repository_name

  • action (String, Symbol) (defaults to: nil)

    Optional argument for star/unstar/activate/deactivate

Returns:

Raises:

  • (InvalidRepository)

    if given input does not conform to valid repository identifier format


1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
# File 'lib/trav3.rb', line 1163

def repository(repo = repository_name, action = nil)
  raise InvalidRepository unless repo_slug_or_id? repo

  repo = sanitize_repo_name repo
  action = '' unless %w[star unstar activate deavtivate].include? action.to_s

  if action.empty?
    get("#{without_repo}/repo/#{repo}")
  else
    post("#{without_repo}/repo/#{repo}/#{action}")
  end
end

#user(user_id = nil, sync = false) ⇒ Success, RequestError

Note:

sync feature may not be permitted

Note:

POST requests require an authorization token set in the headers. See: #h

An individual user.

Attributes

Minimal Representation

Included when the resource is returned as part of another resource.

Name  Type     Description
id    Integer  Value uniquely identifying the user.
login String   Login set on Github.

Standard Representation

Included when the resource is the main response of a request, or is eager loaded.

Name              Type     Description
id                Integer  Value uniquely identifying the user.
login             String   Login set on Github.
name              String   Name set on GitHub.
github_id         Integer  Id set on GitHub.
avatar_url        String   Avatar URL set on GitHub.
education         Boolean  Whether or not the user has an education account.
allow_migration   Unknown  The user's allow_migration.
is_syncing        Boolean  Whether or not the user is currently being synced with Github.
synced_at         String   The last time the user was synced with GitHub.

Additional Attributes

Name          Type          Description
repositories  [Repository]  Repositories belonging to this user.
installation  Installation  Installation belonging to the user.
emails        Unknown       The user's emails.

Actions

Find

This will return information about an individual user.

GET /user/{user.id}

Template Variable  Type     Description
user.id            Integer  Value uniquely identifying the user.
Query Parameter  Type      Description
include          [String]  List of attributes to eager load.

Example:GET /user/119240

Sync

This triggers a sync on a user's account with their GitHub account.

POST /user/{user.id}/sync

Template Variable  Type     Description
user.id            Integer  Value uniquely identifying the user.

Example:POST /user/119240/sync

Current

This will return information about the current user.

GET /user

Query Parameter  Type      Description
include          [String]  List of attributes to eager load.

Example:GET /user

Parameters:

  • user_id (String, Integer) (defaults to: nil)

    optional user id

  • sync (Boolean) (defaults to: false)

    optional argument for syncing your Travis CI account with Github

Returns:

Raises:

  • (TypeError)

    if given user id is not a number


1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
# File 'lib/trav3.rb', line 1254

def user(user_id = nil, sync = false)
  return get("#{without_repo}/user") if !user_id && !sync
  raise TypeError, 'Integer expected for user id' unless /^\d+$/.match? user_id.to_s

  if sync
    get("#{without_repo}/user/#{user_id}/sync")
  else
    get("#{without_repo}/user/#{user_id}")
  end
end