Skip to content

Commit

Permalink
Generate key and switch default (#855)
Browse files Browse the repository at this point in the history
* Default API endpoint switched

* fix: Remove branch from gh dependency gem (#854)

* v1.13.0
  • Loading branch information
murtaza-swati committed Mar 19, 2024
1 parent 90e06f7 commit 5c992ae
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
82 changes: 42 additions & 40 deletions lib/travis/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/travis/cli/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions lib/travis/cli/regenerate_token.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions lib/travis/cli/remove_token.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions lib/travis/client/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/travis/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Travis
VERSION = '1.12.0'
VERSION = '1.13.0'
end
4 changes: 3 additions & 1 deletion travis.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 5c992ae

Please sign in to comment.