diff --git a/Gemfile b/Gemfile index 6d94ac01..645dc7a1 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' gemspec -gem 'gh', git: 'https://github.com/travis-ci/gh', branch: 'prd-ruby-upgrade-dev' +gem 'gh', git: 'https://github.com/travis-ci/gh' gem 'rake' gem 'activesupport', '~> 7.0.6' diff --git a/README.md b/README.md index 4f0eabd9..d664dfbe 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ The [travis gem](https://rubygems.org/gems/travis) includes both a [command line * [`login`](#login) - authenticates against the API and stores the token * [`monitor`](#monitor) - live monitor for what's going on * [`raw`](#raw) - makes an (authenticated) API call and prints out the result + * [`regenerate-token`](#regenerate-token) - regenerates the stored API token + * [`remove-token`](#remove-token) - deletes the stored API token * [`report`](#report) - generates a report useful for filing issues * [`repos`](#repos) - lists repositories the user has certain permissions on * [`sync`](#sync) - triggers a new sync with GitHub @@ -329,6 +331,24 @@ $ travis raw /repos/travis-ci/travis.rb Use `--json` if you'd rather prefer the output to be JSON. +#### `regenerate-token` + +This command is used to regenerate the stored API token. New token will be stored in the config. + +``` console +$ travis regenerate-token +Successfully regenerated the token! +``` + +#### `remove-token` + +This command is used to remove the access token from the config, log out the user and disable the token. + +``` console +$ travis remove-token +Successfully removed the access token! +``` + #### `report` When inspecting a bug or reporting an issue, it can be handy to include a report about the system and configuration used for running a command. @@ -2066,6 +2086,11 @@ See https://github.com/travis-ci/travis.rb/issues/768#issuecomment-700220351 for ## Version History +### 1.13.0 + +* Default API endpoint switched https://github.com/travis-ci/travis.rb/pull/840 +* Api key regenerate https://github.com/travis-ci/travis.rb/pull/842 + ### 1.12.0 * Upgraded ruby version to 3.2 https://github.com/travis-ci/travis.rb/pull/848 diff --git a/lib/travis/cli.rb b/lib/travis/cli.rb index 403413c8..3f60b534 100644 --- a/lib/travis/cli.rb +++ b/lib/travis/cli.rb @@ -13,46 +13,48 @@ module Travis module CLI - autoload :Token, 'travis/cli/token' - autoload :ApiCommand, 'travis/cli/api_command' - autoload :Accounts, 'travis/cli/accounts' - autoload :Branches, 'travis/cli/branches' - autoload :Cache, 'travis/cli/cache' - autoload :Cancel, 'travis/cli/cancel' - autoload :Command, 'travis/cli/command' - autoload :Console, 'travis/cli/console' - autoload :Disable, 'travis/cli/disable' - autoload :Enable, 'travis/cli/enable' - autoload :Encrypt, 'travis/cli/encrypt' - autoload :EncryptFile, 'travis/cli/encrypt_file' - autoload :Endpoint, 'travis/cli/endpoint' - autoload :Env, 'travis/cli/env' - autoload :Help, 'travis/cli/help' - autoload :History, 'travis/cli/history' - autoload :Init, 'travis/cli/init' - autoload :Lint, 'travis/cli/lint' - autoload :Login, 'travis/cli/login' - autoload :Logout, 'travis/cli/logout' - autoload :Logs, 'travis/cli/logs' - autoload :Monitor, 'travis/cli/monitor' - autoload :Open, 'travis/cli/open' - autoload :Parser, 'travis/cli/parser' - autoload :Pubkey, 'travis/cli/pubkey' - autoload :Raw, 'travis/cli/raw' - autoload :RepoCommand, 'travis/cli/repo_command' - autoload :Report, 'travis/cli/report' - autoload :Repos, 'travis/cli/repos' - autoload :Restart, 'travis/cli/restart' - autoload :Requests, 'travis/cli/requests' - autoload :Settings, 'travis/cli/settings' - autoload :Setup, 'travis/cli/setup' - autoload :Show, 'travis/cli/show' - autoload :Sshkey, 'travis/cli/sshkey' - autoload :Status, 'travis/cli/status' - autoload :Sync, 'travis/cli/sync' - autoload :Version, 'travis/cli/version' - autoload :Whatsup, 'travis/cli/whatsup' - autoload :Whoami, 'travis/cli/whoami' + autoload :Token, 'travis/cli/token' + autoload :ApiCommand, 'travis/cli/api_command' + autoload :Accounts, 'travis/cli/accounts' + autoload :Branches, 'travis/cli/branches' + autoload :Cache, 'travis/cli/cache' + autoload :Cancel, 'travis/cli/cancel' + autoload :Command, 'travis/cli/command' + autoload :Console, 'travis/cli/console' + autoload :Disable, 'travis/cli/disable' + autoload :Enable, 'travis/cli/enable' + autoload :Encrypt, 'travis/cli/encrypt' + autoload :EncryptFile, 'travis/cli/encrypt_file' + autoload :Endpoint, 'travis/cli/endpoint' + autoload :Env, 'travis/cli/env' + autoload :Help, 'travis/cli/help' + autoload :History, 'travis/cli/history' + autoload :Init, 'travis/cli/init' + autoload :Lint, 'travis/cli/lint' + autoload :Login, 'travis/cli/login' + autoload :Logout, 'travis/cli/logout' + autoload :Logs, 'travis/cli/logs' + autoload :Monitor, 'travis/cli/monitor' + autoload :Open, 'travis/cli/open' + autoload :Parser, 'travis/cli/parser' + autoload :Pubkey, 'travis/cli/pubkey' + autoload :Raw, 'travis/cli/raw' + autoload :RegenerateToken, 'travis/cli/regenerate_token' + autoload :RemoveToken, 'travis/cli/remove_token' + autoload :RepoCommand, 'travis/cli/repo_command' + autoload :Report, 'travis/cli/report' + autoload :Repos, 'travis/cli/repos' + autoload :Restart, 'travis/cli/restart' + autoload :Requests, 'travis/cli/requests' + autoload :Settings, 'travis/cli/settings' + autoload :Setup, 'travis/cli/setup' + autoload :Show, 'travis/cli/show' + autoload :Sshkey, 'travis/cli/sshkey' + autoload :Status, 'travis/cli/status' + autoload :Sync, 'travis/cli/sync' + autoload :Version, 'travis/cli/version' + autoload :Whatsup, 'travis/cli/whatsup' + autoload :Whoami, 'travis/cli/whoami' extend self diff --git a/lib/travis/cli/help.rb b/lib/travis/cli/help.rb index bae0f5bf..6ca23a17 100644 --- a/lib/travis/cli/help.rb +++ b/lib/travis/cli/help.rb @@ -21,7 +21,7 @@ def run(command = nil) [other_cmds, api_cmds, repo_cmds].each do |cmd_grp| say " #{cmd_grp.header}" cmd_grp.cmds.each do |cmd| - say " #{color(cmd.command_name, :command).ljust(22)} #{color(cmd.description, :info)}" + say " #{color(cmd.command_name, :command).ljust(25)} #{color(cmd.description, :info)}" end end say "\nrun `#{$PROGRAM_NAME} help COMMAND` for more info" diff --git a/lib/travis/cli/regenerate_token.rb b/lib/travis/cli/regenerate_token.rb new file mode 100644 index 00000000..c11ada2c --- /dev/null +++ b/lib/travis/cli/regenerate_token.rb @@ -0,0 +1,15 @@ +require 'travis/cli' + +module Travis + module CLI + class RegenerateToken < ApiCommand + description "regenerates the stored API token" + + def run + token = session.regenerate_token['token'] + endpoint_config['access_token'] = token + success("Successfully regenerated the token!") + end + end + end +end diff --git a/lib/travis/cli/remove_token.rb b/lib/travis/cli/remove_token.rb new file mode 100644 index 00000000..9e55a12f --- /dev/null +++ b/lib/travis/cli/remove_token.rb @@ -0,0 +1,15 @@ +require 'travis/cli' + +module Travis + module CLI + class RemoveToken < ApiCommand + description "deletes the stored API token" + + def run + session.remove_token + endpoint_config['access_token'] = nil + success("Successfully removed the access token!") + end + end + end +end diff --git a/lib/travis/client/methods.rb b/lib/travis/client/methods.rb index f8391687..63f60324 100644 --- a/lib/travis/client/methods.rb +++ b/lib/travis/client/methods.rb @@ -97,6 +97,22 @@ def logout session.get_raw('/logout') end + def regenerate_token + session.headers['Travis-Api-Version'] = '3' + token = session.patch_raw('/access_token') + session.headers.delete('Travis-Api-Version') + + token + end + + def remove_token + session.headers['Travis-Api-Version'] = '3' + resp = session.delete_raw('/access_token') + session.headers.delete('Travis-Api-Version') + + resp + end + def listen(*entities, &block) listener = Listener.new(session) listener.subscribe(*entities, &block) diff --git a/lib/travis/version.rb b/lib/travis/version.rb index 386d27d6..2cfca748 100644 --- a/lib/travis/version.rb +++ b/lib/travis/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Travis - VERSION = '1.12.0' + VERSION = '1.13.0' end diff --git a/travis.gemspec b/travis.gemspec index ce538d2d..7271a225 100644 --- a/travis.gemspec +++ b/travis.gemspec @@ -4,7 +4,7 @@ Gem::Specification.new do |s| # general info s.name = 'travis' - s.version = '1.12.0' + s.version = '1.13.0' s.required_ruby_version = '>= 3.2.0' s.description = 'CLI and Ruby client library for Travis CI' s.homepage = 'https://github.com/travis-ci/travis.rb' @@ -288,6 +288,8 @@ Gem::Specification.new do |s| 'lib/travis/cli/parser.rb', 'lib/travis/cli/pubkey.rb', 'lib/travis/cli/raw.rb', + 'lib/travis/cli/regenerate_token.rb', + 'lib/travis/cli/remove_token.rb', 'lib/travis/cli/repo_command.rb', 'lib/travis/cli/report.rb', 'lib/travis/cli/repos.rb',