Skip to content

Commit 90e06f7

Browse files
authored
ruby update + q2 maint. (#848)
* update the gems to the latest version - stage 1 * require faraday/rack to fix rack adapter issue * params removed form cancel and restart spec * rubocop stage1 * rubocop stage2 * faraday-rack up to 2.0 * Default API endpoint switched * activesupport 7.0
1 parent 8372ee3 commit 90e06f7

File tree

157 files changed

+3468
-2899
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+3468
-2899
lines changed

.rubocop.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require: rubocop-performance
2+
require: rubocop-rspec
3+
4+
Documentation:
5+
Enabled: false
6+
Metrics/ClassLength:
7+
Enabled: false
8+
Style/ClassAndModuleChildren:
9+
Enabled: false
10+
Metrics/LineLength:
11+
Enabled: false
12+
Metrics/MethodLength:
13+
Max: 40
14+
Style/AsciiComments:
15+
Enabled: false
16+
Metrics/AbcSize:
17+
Enabled: false
18+
Style/GuardClause:
19+
Enabled: false
20+
Style/FormatStringToken:
21+
Enabled: false
22+
Lint/AssignmentInCondition:
23+
Enabled: false
24+
Style/IfUnlessModifier:
25+
Enabled: false
26+
Naming/MemoizedInstanceVariableName:
27+
EnforcedStyleForLeadingUnderscores: required
28+
Style/MultilineBlockChain:
29+
Enabled: false
30+
Lint/ConstantDefinitionInBlock:
31+
Enabled: false
32+
Naming/VariableNumber:
33+
Enabled: false
34+
Metrics/BlockLength:
35+
Enabled: false
36+
Lint/ImplicitStringConcatenation:
37+
Enabled: false
38+
Metrics/MethodLength:
39+
Enabled: false
40+
Style/StructInheritance:
41+
Enabled: false
42+
Lint/RescueException:
43+
Enabled: false
44+
Lint/SuppressedException:
45+
Enabled: false
46+
Naming/MemoizedInstanceVariableName:
47+
Enabled: false
48+
Style/SymbolProc:
49+
Enabled: false
50+
RSpec/MultipleMemoizedHelpers:
51+
Enabled: false

.travis.yml

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
language: ruby
22
cache: bundler
3+
dist: bionic
34

45
os:
56
- linux
67

78
rvm:
8-
- jruby
9-
- "2.4"
10-
- "2.5"
11-
- "2.6"
12-
- "2.7"
9+
- "3.2"
1310

1411
jobs:
1512
include:
16-
- rvm: "2.3"
13+
- rvm: "3.2"
1714
before_script:
1815
- gem install faraday -v 1.0.1
1916
- os: osx
20-
rvm: "2.5"
17+
rvm: "3.2"
2118
- os: osx
22-
rvm: "2.6"
19+
rvm: "3.2"
2320
- stage: deploy
2421
if: repo = travis-ci/travis.rb and branch = master and type = push
2522
os: linux
26-
rvm: "2.6"
23+
rvm: "3.2"
2724
deploy:
2825
provider: rubygems
2926
api_key:

Gemfile

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24
gemspec
35

6+
gem 'gh', git: 'https://github.com/travis-ci/gh', branch: 'prd-ruby-upgrade-dev'
47
gem 'rake'
8+
gem 'activesupport', '~> 7.0.6'
9+
10+
group :development, :test do
11+
gem 'rubocop'
12+
gem 'rubocop-performance'
13+
gem 'rubocop-rspec'
14+
gem 'simplecov-console'
15+
end

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,12 @@ See https://github.com/travis-ci/travis.rb/issues/768#issuecomment-700220351 for
20662066

20672067
## Version History
20682068

2069+
### 1.12.0
2070+
2071+
* Upgraded ruby version to 3.2 https://github.com/travis-ci/travis.rb/pull/848
2072+
* Added API Key Reset Capabilities https://github.com/travis-ci/travis.rb/pull/842
2073+
* Fix travis lint issues https://github.com/travis-ci/travis.rb/pull/840
2074+
20692075
### 1.11.1
20702076

20712077
* Fix `travis sshkey --generate` https://github.com/travis-ci/travis.rb/pull/820

Rakefile

+22-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
# encoding: utf-8
2-
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
1+
# frozen_string_literal: true
2+
3+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
34
windows = RUBY_PLATFORM =~ /mswin|mingw/
45

56
require 'bundler/gem_tasks'
67

7-
desc "run specs"
8-
task(:spec) { ruby "-S rspec spec#{" -c" unless windows}" }
8+
desc 'run specs'
9+
task(:spec) { ruby "-S rspec spec#{' -c' unless windows}" }
910

10-
desc "generate gemspec, update readme"
11-
task :update => :completion do
11+
desc 'generate gemspec, update readme'
12+
task update: :completion do
1213
require 'travis/version'
1314
content = File.read('travis.gemspec')
1415

1516
# fetch data
1617
fields = {
17-
:authors => sort_by_commits_alpha(`git shortlog -sn`.b, /[^\d\s].*/).uniq,
18-
:email => sort_by_commits_alpha(`git shortlog -sne`.b, /[^<]+@[^>]+/).uniq,
19-
:files => `git ls-files`.b.split("\n").reject { |f| f =~ /^(\.|Gemfile)/ }
18+
authors: sort_by_commits_alpha(`git shortlog -sn`.b, /[^\d\s].*/).uniq,
19+
email: sort_by_commits_alpha(`git shortlog -sne`.b, /[^<]+@[^>]+/).uniq,
20+
files: `git ls-files`.b.split("\n").reject { |f| f =~ /^(\.|Gemfile)/ }
2021
}
2122

2223
# :(
23-
fields[:email].delete("[email protected]")
24+
fields[:email].delete('[email protected]')
2425

2526
# insert data
2627
fields.each do |field, values|
@@ -31,20 +32,21 @@ task :update => :completion do
3132
end
3233

3334
# set version
34-
content.sub! /(s\.version.*=\s+).*/, "\\1\"#{Travis::VERSION}\""
35+
content.sub!(/(s\.version.*=\s+).*/, "\\1\"#{Travis::VERSION}\"")
3536

3637
# escape unicode
3738
content.gsub!(/./) { |c| c.bytesize > 1 ? "\\u{#{c.codepoints.first.to_s(16)}}" : c }
3839

3940
File.open('travis.gemspec', 'w') { |f| f << content }
4041

4142
readme = File.read('README.md').b
42-
readme.gsub! /^(\s+\$ travis version\n\s+).*$/, "\\1#{Travis::VERSION}"
43-
readme.gsub! /(gem install travis -v )\S+/, "\\1#{Travis::VERSION}"
44-
readme.gsub! /^\*\*#{Regexp.escape(Travis::VERSION)}\*\* \(not yet released?\)\n/i, "**#{Travis::VERSION}** (#{Time.now.strftime("%B %-d, %Y")})\n"
43+
readme.gsub!(/^(\s+\$ travis version\n\s+).*$/, "\\1#{Travis::VERSION}")
44+
readme.gsub!(/(gem install travis -v )\S+/, "\\1#{Travis::VERSION}")
45+
readme.gsub!(/^\*\*#{Regexp.escape(Travis::VERSION)}\*\* \(not yet released?\)\n/i,
46+
"**#{Travis::VERSION}** (#{Time.now.strftime('%B %-d, %Y')})\n")
4547

4648
Travis::CLI.commands.each do |c|
47-
readme.sub! /^( \* \[\`#{c.command_name}\`\]\(##{c.command_name}\)).*$/, "\\1 - #{c.description}"
49+
readme.sub!(/^( \* \[`#{c.command_name}`\]\(##{c.command_name}\)).*$/, "\\1 - #{c.description}")
4850
end
4951

5052
File.write('README.md', readme)
@@ -58,13 +60,13 @@ end
5860
task 'travis.gemspec' => :update
5961
task 'README.md' => :update
6062

61-
task :gemspec => :update
62-
task :default => :spec
63-
task :default => :gemspec unless windows or RUBY_VERSION < '2.0'
64-
task :test => :spec
63+
task gemspec: :update
64+
task default: :spec
65+
task default: :gemspec unless windows || (RUBY_VERSION < '2.0')
66+
task test: :spec
6567

6668
def sort_by_commits_alpha(shortlog_output, patt)
67-
shortlog_output.split("\n").sort do |a,b|
69+
shortlog_output.split("\n").sort do |a, b|
6870
a_comm, a_name = a.strip.split(/\t/)
6971
b_comm, b_name = b.strip.split(/\t/)
7072

bin/travis

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
24
# :(
35
Encoding.default_external = Encoding::UTF_8 if defined? Encoding
46

57
# load travis library
6-
require 'bundler/setup' if File.exist? File.expand_path('../../Gemfile', __FILE__)
8+
require 'bundler/setup' if File.exist? File.expand_path('../Gemfile', __dir__)
79
require 'travis/cli'
810

911
# load plugins
10-
TRAVIS_PLUGINS = []
12+
TRAVIS_PLUGINS = [].freeze
1113
config_path = ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', Dir.home) }
1214
Dir.glob(File.expand_path('*/init.rb', config_path)) do |file|
13-
TRAVIS_PLUGINS << file.sub(config_path + '/', '').sub(/\/init\.rb$/, '')
15+
TRAVIS_PLUGINS << file.sub("#{config_path}/", '').sub(%r{/init\.rb$}, '')
1416
load(file)
1517
end
1618

examples/org_overview.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'travis'
24
repos = Travis::Repository.find_all(owner_name: 'travis-ci')
35
repos.each { |repo| puts "#{repo.slug} #{repo.last_build_state}" }

examples/pro_auth.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
require 'travis/pro'
24
require 'travis/tools/github'
35
require 'highline/import' # so we can hide the password
46

5-
github_token = ask("GitHub token: ")
7+
github_token = ask('GitHub token: ')
68

79
# Set up GitHub tool for doing the login handshake.
810
github = Travis::Tools::Github.new(drop_token: true) do |g|

examples/stream.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# frozen_string_literal: true
2+
13
require 'travis'
24

35
Travis.listen do |listener|
4-
listener.on("job:started") { |e| puts "job started for #{e.repository.slug}" }
5-
listener.on("job:finished") { |e| puts "job finished for #{e.repository.slug}" }
6-
end
6+
listener.on('job:started') { |e| puts "job started for #{e.repository.slug}" }
7+
listener.on('job:finished') { |e| puts "job finished for #{e.repository.slug}" }
8+
end

lib/travis.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
module Travis
24
autoload :Client, 'travis/client'
35
autoload :CLI, 'travis/cli'
46
autoload :Pro, 'travis/pro'
57
autoload :Version, 'travis/version'
68

7-
include Client::Namespace.new(Client::ORG_URI)
9+
include Client::Namespace.new(Client::COM_URI)
810
end

lib/travis/auto_login.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'travis'
24
require 'travis/client/auto_login'
35
Travis::Client::AutoLogin.new(Travis).authenticate

lib/travis/cli.rb

+39-36
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
# frozen_string_literal: true
2+
13
begin
24
require 'travis/client'
35
rescue LoadError => e
4-
if e.message == 'no such file to load -- json'
5-
$stderr.puts "You should either run `gem install json` or upgrade your Ruby version!"
6-
exit 1
7-
else
8-
raise e
9-
end
6+
raise e unless e.message == 'no such file to load -- json'
7+
8+
warn 'You should either run `gem install json` or upgrade your Ruby version!'
9+
exit 1
1010
end
1111

1212
require 'stringio'
@@ -66,11 +66,11 @@ def run(*args)
6666

6767
def command(name)
6868
const_name = command_name(name)
69-
constant = CLI.const_get(const_name) if const_name =~ /^[A-Z][A-Za-z]+$/ and const_defined? const_name
69+
constant = CLI.const_get(const_name) if const_name =~ (/^[A-Z][A-Za-z]+$/) && const_defined?(const_name)
7070
if command? constant
7171
constant
7272
else
73-
$stderr.puts "unknown command #{name}"
73+
warn "unknown command #{name}"
7474
exit 1
7575
end
7676
end
@@ -80,8 +80,10 @@ def commands
8080
end
8181

8282
def silent
83-
stderr, $stderr = $stderr, dummy_io
84-
stdout, $stdout = $stdout, dummy_io
83+
stderr = $stderr
84+
$stderr = dummy_io
85+
stdout = $stdout
86+
$stdout = dummy_io
8587
yield
8688
ensure
8789
$stderr = stderr if stderr
@@ -90,37 +92,38 @@ def silent
9092

9193
private
9294

93-
def try_const_get(name)
94-
CLI.const_get(name)
95-
rescue Exception
96-
end
95+
def try_const_get(name)
96+
CLI.const_get(name)
97+
rescue Exception
98+
end
9799

98-
def dummy_io
99-
return StringIO.new unless defined? IO::NULL and IO::NULL
100-
File.open(IO::NULL, 'w')
101-
end
100+
def dummy_io
101+
return StringIO.new unless defined? IO::NULL && IO::NULL
102102

103-
def command?(constant)
104-
constant.is_a? Class and constant < Command and not constant.abstract?
105-
end
103+
File.open(IO::NULL, 'w')
104+
end
105+
106+
def command?(constant)
107+
constant.is_a? Class and constant < Command and !constant.abstract?
108+
end
106109

107-
def command_name(name)
108-
case name
109-
when nil, '-h', '-?' then 'Help'
110-
when '-v' then 'Version'
111-
when /^--/ then command_name(name[2..-1])
112-
else name.split('-').map(&:capitalize).join
113-
end
110+
def command_name(name)
111+
case name
112+
when nil, '-h', '-?' then 'Help'
113+
when '-v' then 'Version'
114+
when /^--/ then command_name(name[2..])
115+
else name.split('-').map(&:capitalize).join
114116
end
117+
end
115118

116-
# can't use flatten as it will flatten hashes
117-
def preparse(unparsed, args = [], opts = {})
118-
case unparsed
119-
when Hash then opts.merge! unparsed
120-
when Array then unparsed.each { |e| preparse(e, args, opts) }
121-
else args << unparsed.to_s
122-
end
123-
[args, opts]
119+
# can't use flatten as it will flatten hashes
120+
def preparse(unparsed, args = [], opts = {})
121+
case unparsed
122+
when Hash then opts.merge! unparsed
123+
when Array then unparsed.each { |e| preparse(e, args, opts) }
124+
else args << unparsed.to_s
124125
end
126+
[args, opts]
127+
end
125128
end
126129
end

0 commit comments

Comments
 (0)