Skip to content

Commit

Permalink
ruby update + q2 maint. (#848)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
GbArc committed Feb 27, 2024
1 parent 8372ee3 commit 90e06f7
Show file tree
Hide file tree
Showing 157 changed files with 3,468 additions and 2,899 deletions.
51 changes: 51 additions & 0 deletions .rubocop.yml
@@ -0,0 +1,51 @@
require: rubocop-performance
require: rubocop-rspec

Documentation:
Enabled: false
Metrics/ClassLength:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/MethodLength:
Max: 40
Style/AsciiComments:
Enabled: false
Metrics/AbcSize:
Enabled: false
Style/GuardClause:
Enabled: false
Style/FormatStringToken:
Enabled: false
Lint/AssignmentInCondition:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Naming/MemoizedInstanceVariableName:
EnforcedStyleForLeadingUnderscores: required
Style/MultilineBlockChain:
Enabled: false
Lint/ConstantDefinitionInBlock:
Enabled: false
Naming/VariableNumber:
Enabled: false
Metrics/BlockLength:
Enabled: false
Lint/ImplicitStringConcatenation:
Enabled: false
Metrics/MethodLength:
Enabled: false
Style/StructInheritance:
Enabled: false
Lint/RescueException:
Enabled: false
Lint/SuppressedException:
Enabled: false
Naming/MemoizedInstanceVariableName:
Enabled: false
Style/SymbolProc:
Enabled: false
RSpec/MultipleMemoizedHelpers:
Enabled: false
15 changes: 6 additions & 9 deletions .travis.yml
@@ -1,29 +1,26 @@
language: ruby
cache: bundler
dist: bionic

os:
- linux

rvm:
- jruby
- "2.4"
- "2.5"
- "2.6"
- "2.7"
- "3.2"

jobs:
include:
- rvm: "2.3"
- rvm: "3.2"
before_script:
- gem install faraday -v 1.0.1
- os: osx
rvm: "2.5"
rvm: "3.2"
- os: osx
rvm: "2.6"
rvm: "3.2"
- stage: deploy
if: repo = travis-ci/travis.rb and branch = master and type = push
os: linux
rvm: "2.6"
rvm: "3.2"
deploy:
provider: rubygems
api_key:
Expand Down
11 changes: 11 additions & 0 deletions Gemfile
@@ -1,4 +1,15 @@
# frozen_string_literal: true

source 'https://rubygems.org'
gemspec

gem 'gh', git: 'https://github.com/travis-ci/gh', branch: 'prd-ruby-upgrade-dev'
gem 'rake'
gem 'activesupport', '~> 7.0.6'

group :development, :test do
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rspec'
gem 'simplecov-console'
end
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -2066,6 +2066,12 @@ See https://github.com/travis-ci/travis.rb/issues/768#issuecomment-700220351 for

## Version History

### 1.12.0

* Upgraded ruby version to 3.2 https://github.com/travis-ci/travis.rb/pull/848
* Added API Key Reset Capabilities https://github.com/travis-ci/travis.rb/pull/842
* Fix travis lint issues https://github.com/travis-ci/travis.rb/pull/840

### 1.11.1

* Fix `travis sshkey --generate` https://github.com/travis-ci/travis.rb/pull/820
Expand Down
42 changes: 22 additions & 20 deletions Rakefile
@@ -1,26 +1,27 @@
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path('lib', __dir__)
windows = RUBY_PLATFORM =~ /mswin|mingw/

require 'bundler/gem_tasks'

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

desc "generate gemspec, update readme"
task :update => :completion do
desc 'generate gemspec, update readme'
task update: :completion do
require 'travis/version'
content = File.read('travis.gemspec')

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

# :(
fields[:email].delete("konstantin.haase@gmail.com")
fields[:email].delete('konstantin.haase@gmail.com')

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

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

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

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

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

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

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

task :gemspec => :update
task :default => :spec
task :default => :gemspec unless windows or RUBY_VERSION < '2.0'
task :test => :spec
task gemspec: :update
task default: :spec
task default: :gemspec unless windows || (RUBY_VERSION < '2.0')
task test: :spec

def sort_by_commits_alpha(shortlog_output, patt)
shortlog_output.split("\n").sort do |a,b|
shortlog_output.split("\n").sort do |a, b|
a_comm, a_name = a.strip.split(/\t/)
b_comm, b_name = b.strip.split(/\t/)

Expand Down
8 changes: 5 additions & 3 deletions bin/travis
@@ -1,16 +1,18 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# :(
Encoding.default_external = Encoding::UTF_8 if defined? Encoding

# load travis library
require 'bundler/setup' if File.exist? File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exist? File.expand_path('../Gemfile', __dir__)
require 'travis/cli'

# load plugins
TRAVIS_PLUGINS = []
TRAVIS_PLUGINS = [].freeze
config_path = ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', Dir.home) }
Dir.glob(File.expand_path('*/init.rb', config_path)) do |file|
TRAVIS_PLUGINS << file.sub(config_path + '/', '').sub(/\/init\.rb$/, '')
TRAVIS_PLUGINS << file.sub("#{config_path}/", '').sub(%r{/init\.rb$}, '')
load(file)
end

Expand Down
2 changes: 2 additions & 0 deletions examples/org_overview.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'travis'
repos = Travis::Repository.find_all(owner_name: 'travis-ci')
repos.each { |repo| puts "#{repo.slug} #{repo.last_build_state}" }
4 changes: 3 additions & 1 deletion examples/pro_auth.rb
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require 'travis/pro'
require 'travis/tools/github'
require 'highline/import' # so we can hide the password

github_token = ask("GitHub token: ")
github_token = ask('GitHub token: ')

# Set up GitHub tool for doing the login handshake.
github = Travis::Tools::Github.new(drop_token: true) do |g|
Expand Down
8 changes: 5 additions & 3 deletions examples/stream.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require 'travis'

Travis.listen do |listener|
listener.on("job:started") { |e| puts "job started for #{e.repository.slug}" }
listener.on("job:finished") { |e| puts "job finished for #{e.repository.slug}" }
end
listener.on('job:started') { |e| puts "job started for #{e.repository.slug}" }
listener.on('job:finished') { |e| puts "job finished for #{e.repository.slug}" }
end
4 changes: 3 additions & 1 deletion lib/travis.rb
@@ -1,8 +1,10 @@
# frozen_string_literal: true

module Travis
autoload :Client, 'travis/client'
autoload :CLI, 'travis/cli'
autoload :Pro, 'travis/pro'
autoload :Version, 'travis/version'

include Client::Namespace.new(Client::ORG_URI)
include Client::Namespace.new(Client::COM_URI)
end
2 changes: 2 additions & 0 deletions lib/travis/auto_login.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'travis'
require 'travis/client/auto_login'
Travis::Client::AutoLogin.new(Travis).authenticate
75 changes: 39 additions & 36 deletions lib/travis/cli.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true

begin
require 'travis/client'
rescue LoadError => e
if e.message == 'no such file to load -- json'
$stderr.puts "You should either run `gem install json` or upgrade your Ruby version!"
exit 1
else
raise e
end
raise e unless e.message == 'no such file to load -- json'

warn 'You should either run `gem install json` or upgrade your Ruby version!'
exit 1
end

require 'stringio'
Expand Down Expand Up @@ -66,11 +66,11 @@ def run(*args)

def command(name)
const_name = command_name(name)
constant = CLI.const_get(const_name) if const_name =~ /^[A-Z][A-Za-z]+$/ and const_defined? const_name
constant = CLI.const_get(const_name) if const_name =~ (/^[A-Z][A-Za-z]+$/) && const_defined?(const_name)
if command? constant
constant
else
$stderr.puts "unknown command #{name}"
warn "unknown command #{name}"
exit 1
end
end
Expand All @@ -80,8 +80,10 @@ def commands
end

def silent
stderr, $stderr = $stderr, dummy_io
stdout, $stdout = $stdout, dummy_io
stderr = $stderr
$stderr = dummy_io
stdout = $stdout
$stdout = dummy_io
yield
ensure
$stderr = stderr if stderr
Expand All @@ -90,37 +92,38 @@ def silent

private

def try_const_get(name)
CLI.const_get(name)
rescue Exception
end
def try_const_get(name)
CLI.const_get(name)
rescue Exception
end

def dummy_io
return StringIO.new unless defined? IO::NULL and IO::NULL
File.open(IO::NULL, 'w')
end
def dummy_io
return StringIO.new unless defined? IO::NULL && IO::NULL

def command?(constant)
constant.is_a? Class and constant < Command and not constant.abstract?
end
File.open(IO::NULL, 'w')
end

def command?(constant)
constant.is_a? Class and constant < Command and !constant.abstract?
end

def command_name(name)
case name
when nil, '-h', '-?' then 'Help'
when '-v' then 'Version'
when /^--/ then command_name(name[2..-1])
else name.split('-').map(&:capitalize).join
end
def command_name(name)
case name
when nil, '-h', '-?' then 'Help'
when '-v' then 'Version'
when /^--/ then command_name(name[2..])
else name.split('-').map(&:capitalize).join
end
end

# can't use flatten as it will flatten hashes
def preparse(unparsed, args = [], opts = {})
case unparsed
when Hash then opts.merge! unparsed
when Array then unparsed.each { |e| preparse(e, args, opts) }
else args << unparsed.to_s
end
[args, opts]
# can't use flatten as it will flatten hashes
def preparse(unparsed, args = [], opts = {})
case unparsed
when Hash then opts.merge! unparsed
when Array then unparsed.each { |e| preparse(e, args, opts) }
else args << unparsed.to_s
end
[args, opts]
end
end
end

0 comments on commit 90e06f7

Please sign in to comment.