travis-cli-gh 0.0.2.travis.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTdmMzc1YzkyNDZlZTZhNTExNjU1NWU4ZTU5N2ViZjk2NDdlYTI5YQ==
5
+ data.tar.gz: !binary |-
6
+ YzlmNjQ2NzlmNzNmM2E4MGQyOTQ5MTFhNTVkMTE5ZWQ1ZWJjOTBiMg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NjFiNTZjZWRlMjM3NTRhNjcxMzMyODVhYzk5ZDcxODViMTEwYWM1OWQ5ZWIw
10
+ ZTViYTU1Y2NlOWYzMmQwODMzZmRmYjhlM2JiM2M4M2U5MGMwYWUyZWZjMWM5
11
+ ZmEzZjkxMDdiYzk1NjYxYTYwNDZkZjk0MTU1MGQxY2FlYzJmODk=
12
+ data.tar.gz: !binary |-
13
+ MTE2ZjMwZGI4MmUxMDBkZGI2YzRmN2E5MTM2ODg2MDE5MDY4NmFmMTRmYTcx
14
+ NzdlOTMwYWJlZjY2MjA5Y2YwM2IxNzgxYWFlNDRkMzEwMjJmNDE2MTkwMDUw
15
+ ZDA1ODY0ZmEwYWMzNWI1NGE4YzExMGM2NDhmZDdkODJkMGYxNmE=
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ Makefile
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ script: bundle exec rspec -bc
6
+ deploy:
7
+ provider: rubygems
8
+ api_key:
9
+ secure: AAZsdcsu1vs/T1e+zu6GQtsXjllJhQGxl2VpPFyEJCF2RamZTH13yEoZg1WhySDPhF9lG9tVh6XstK0AiC8Skui0g1UhrGLsyqF+AEqAHnSkdGudqV4OWUWXN78C12DZdWR1825k46ZQG7PVYIUpShN1Fu/VUNK+oK0Pydrk+vw=
10
+ gem: travis-cli-gh
11
+ on:
12
+ repo: travis-ci/travis-cli-gh
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Konstantin Haase
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ # GitHub Plugin for Travis CLI
2
+
3
+ This plugin for the [Travis Command Line Client](https://github.com/travis-ci/travis#readme) adds commands that interact with the [GitHub API](http://developer.github.com/v3/) rather than the Travis API. This plugin requires Ruby 2.0 or newer.
4
+
5
+ ## Usage
6
+
7
+ This plugin adds the following commands: [`gh-login`](#gh-login) and [`gh-signature`](#gh-signature). All these commands will use the Travis API endpoint for automatically figuring out which GitHub API endpoint to use (relevant for setups using GitHub Enterprise).
8
+
9
+ ### `gh-login`
10
+
11
+ This command basically mimics [`travis login`](https://github.com/travis-ci/travis#login) with the notable difference that it does not delete the token on GitHub afterwards (as it will be needed for running other commands) and does not send the GitHub token to Travis CI. Instead, it will store the GitHub token for later use.
12
+
13
+ Note that it might not be necessary to run this command if you already have a GitHub token available (for instance, in your .netrc).
14
+
15
+ ### `gh-signature`
16
+
17
+ This command lets you calculate the signature [used for web hooks](http://about.travis-ci.org/docs/user/notifications/#Authorization):
18
+
19
+ $ travis gh-signature
20
+ Signature used for travis-ci/travis web hooks: 57ca05aa0db5d27d20b2df24e27e2a191deeb7dd37075d921b76b95eddf60b9b
21
+
22
+ You can use this signature in your web application to verify that a hook was indeed fired by Travis CI.
23
+
24
+ Like [other commands](https://github.com/travis-ci/travis#repository-commands), it uses the current directory to determine the repository slug. It is also possible to provide it explicitly:
25
+
26
+ $ travis gh-signature -r sinatra/sinatra
27
+ Signature used for travis-ci/travis web hooks: 68db16bb1ec6e38e31c3eg35f38f3b2102effc8ee48186e1032c87c106feeg71
28
+
29
+ This signature should be kept somewhat secret, otherwise other people can send you fake web hooks.
30
+
31
+ ### `gh-whoami`
32
+
33
+ Displays which GitHub account you are logged in with on GitHub.
34
+
35
+ $ travis gh-whoami
36
+ logged in as rkh
37
+
38
+ ## Installation
39
+
40
+ You install it like any other gem:
41
+
42
+ $ gem install travis-cli-gh
43
+
44
+ We also push pre-releases to rubygems.org on a regular basis:
45
+
46
+ $ gem install travis-cli-gh --pre
47
+
48
+ ### Running against a local clone
49
+
50
+ If you want to run commands from a local clone of the travis-cli-gh repository (say, if you want to contribute a patch), make sure you have the lib directory on your load path.
51
+
52
+ Here's an example:
53
+
54
+ $ ruby -Ilib -S travis gh-signature
55
+
56
+ ## Version History
57
+
58
+ **0.1.0** (not yet released)
59
+
60
+ * Initial release
data/init.rb ADDED
@@ -0,0 +1,18 @@
1
+ begin
2
+ raise LoadError, "requires Ruby 2.0 or later" if RUBY_VERSION < '2.0'
3
+ require 'travis/cli/gh'
4
+ Travis::CLI::Gh.setup
5
+ rescue LoadError => e
6
+ require 'travis/cli'
7
+
8
+ dummy = Class.new(Travis::CLI::Command) do
9
+ define_method(:run) { error "GitHub plugin not available: #{color e.message, :bold}" }
10
+ end
11
+
12
+ Travis::CLI.module_eval do
13
+ alias_method :command_without_gh, :command unless method_defined? :command_without_gh
14
+ define_method(:command) do |name|
15
+ name =~ /^gh-/ ? dummy : command_without_gh(name)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,52 @@
1
+ require 'travis/cli'
2
+ require 'fileutils'
3
+
4
+ module Travis
5
+ module CLI
6
+ module Gh
7
+ autoload :GitHub, 'travis/cli/gh/github'
8
+ autoload :Login, 'travis/cli/gh/login'
9
+ autoload :Signature, 'travis/cli/gh/signature'
10
+ autoload :Subcommands, 'travis/cli/gh/subcommands'
11
+ autoload :VERSION, 'travis/cli/gh/version'
12
+ autoload :Whoami, 'travis/cli/gh/whoami'
13
+
14
+ extend self
15
+
16
+ def setup(force = false)
17
+ setup_commands(force)
18
+ setup_plugin(force)
19
+ setup_completion(force)
20
+ end
21
+
22
+ def setup_commands(force)
23
+ CLI.singleton_class.send(:prepend, Subcommands)
24
+ end
25
+
26
+ def setup_plugin(force)
27
+ target_dir = File.expand_path('travis-cli-gh', config_path)
28
+ target = File.expand_path('init.rb', target_dir)
29
+ source = File.expand_path('../../../init.rb', __dir__)
30
+ if force or !File.exist?(target)
31
+ FileUtils.mkdir_p(target_dir)
32
+ FileUtils.cp(source, target)
33
+ end
34
+ end
35
+
36
+ def setup_completion(force)
37
+ cmp_file = File.expand_path('travis.sh', config_path)
38
+ unless File.exist?(cmp_file) and File.read(cmp_file).include?("travis-cli-gh #{VERSION}")
39
+ require 'travis/tools/completion'
40
+ Travis::Tools::Completion.compile
41
+ Travis::Tools::Completion.update_completion
42
+ content = File.read(cmp_file)
43
+ File.write(cmp_file, "# travis-cli-gh #{VERSION}\n\n#{content}")
44
+ end
45
+ end
46
+
47
+ def config_path
48
+ ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', ENV['HOME']) }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,60 @@
1
+ require 'travis/tools/github'
2
+
3
+ module Travis::CLI
4
+ module Gh
5
+ module GitHub
6
+ module Anonymous
7
+ def gh
8
+ GH
9
+ end
10
+ end
11
+
12
+ module Authenticated
13
+ def gh
14
+ @gh ||= auth.with_token do |token|
15
+ plugin_config['token'] = token
16
+ GH.with(token: token)
17
+ end
18
+ end
19
+
20
+ def auth
21
+ @auth ||= Travis::Tools::Github.new(session.config['github']) do |g|
22
+ g.note = "token for travis-cli-gh"
23
+ g.scopes = ['user', 'user:email', 'repo']
24
+ g.manual_login = false
25
+ g.explode = explode?
26
+ g.auto_token = true
27
+ g.auto_password = true
28
+ g.drop_token = false
29
+ g.github_token = plugin_config['token'] || endpoint_config['pr_token']
30
+ g.check_token = !g.github_token
31
+ g.ask_login = proc { ask("Username: ") }
32
+ g.ask_password = proc { |user| ask("Password for #{user}: ") { |q| q.echo = "*" } }
33
+ g.ask_otp = proc { |user| ask("Two-factor authentication code for #{user}: ") }
34
+ g.debug = proc { |log| debug(log) }
35
+ g.after_tokens = proc { g.explode = true and error("no suitable github token found, try running gh-login.") }
36
+ end
37
+ end
38
+
39
+ def plugin_config
40
+ config['gihub'] ||= {}
41
+ config['gihub'][github_endpoint.host] ||= {}
42
+ end
43
+ end
44
+
45
+ module Hooks
46
+ def hooks
47
+ @hooks ||= gh["/repos/#{repository.slug}/hooks"]
48
+ rescue GH::Error
49
+ error "admin access needed for #{repository.slug} in order to access hooks"
50
+ end
51
+
52
+ def travis_hook
53
+ @travis_hook ||= hooks.detect { |h| h['name'] == 'travis' }
54
+ error "GitHub hook not found. Project might not be enabled." unless @travis_hook
55
+ @travis_hook
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,29 @@
1
+ module Travis::CLI
2
+ module Gh
3
+ class Login < ApiCommand
4
+ description "authenticates against GitHub and stores the token"
5
+ include GitHub::Authenticated
6
+
7
+ def run
8
+ say color("Successfully logged in as #{color(gh['user']['login'], :bold)}", :success)
9
+ end
10
+
11
+ def auth
12
+ auth = super
13
+ auth.manual_login = true
14
+ auth.auto_password = false
15
+ auth.auto_token = false
16
+ auth.github_token = nil
17
+ auth.check_token = false
18
+ auth.login_header = proc { login_header }
19
+ auth
20
+ end
21
+
22
+ def login_header
23
+ say "We need your #{color("GitHub login", :important)} to identify you against #{color(github_endpoint.host, :info)}."
24
+ say "The password will not be displayed. No information will be sent to Travis CI."
25
+ empty_line
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ require 'digest/sha2'
2
+
3
+ module Travis::CLI
4
+ module Gh
5
+ class Signature < RepoCommand
6
+ description "generates the signature used to verify Travis CI web hooks"
7
+ include GitHub::Authenticated, GitHub::Hooks
8
+
9
+ def run
10
+ signature = Digest::SHA2.hexdigest(repository.slug + travis_hook["config"]["token"])
11
+ say signature, "Signature used for #{repository.slug} web hooks: %s"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ module Travis::CLI
2
+ module Gh
3
+ module Subcommands
4
+ module CommandMixin
5
+ def description(input = nil)
6
+ "GitHub plugin: #{super(input)}"
7
+ end
8
+
9
+ def command_name
10
+ "gh-#{super}"
11
+ end
12
+ end
13
+
14
+ def command(name)
15
+ if name =~ /^gh-(.+)$/
16
+ const_name = command_name($1)
17
+ constant = Gh.const_get(const_name) if const_name =~ /^[A-Z][a-z]+$/ and Gh.const_defined? const_name
18
+ constant.extend(CommandMixin) if constant
19
+ end
20
+ command?(constant) ? constant : super
21
+ end
22
+
23
+ def commands
24
+ super + gh_commands
25
+ end
26
+
27
+ def gh_commands
28
+ Gh.constants.map { |c| Gh.const_get(c).extend(CommandMixin) }.select { |c| command? c }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ module Travis
2
+ module CLI
3
+ module Gh
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Travis::CLI
2
+ module Gh
3
+ class Whoami < ApiCommand
4
+ description "displays the user you are logged in as on GitHub"
5
+ include GitHub::Authenticated
6
+
7
+ def run
8
+ say gh['user']['login'], 'logged in as %s'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift File.expand_path('../lib', __dir__)
2
+
3
+ require 'travis/cli/gh'
4
+ Travis::CLI::Gh.setup(true)
5
+
6
+ # fake Makefile
7
+ File.open('Makefile', 'w') { |f| f.puts 'all:', 'install:' }
@@ -0,0 +1,24 @@
1
+ require 'travis/cli'
2
+ require 'travis/cli/gh'
3
+
4
+ describe Travis::CLI::Gh::Subcommands do
5
+ before :all do
6
+ Travis::CLI::Gh.setup
7
+ end
8
+
9
+ it "resolves commands with gh-prefix" do
10
+ Travis::CLI.command('gh-signature').should be == Travis::CLI::Gh::Signature
11
+ end
12
+
13
+ it "lists gh commands" do
14
+ Travis::CLI.commands.should include(Travis::CLI::Gh::Signature)
15
+ end
16
+
17
+ it "prefixes the command name" do
18
+ Travis::CLI.command('gh-signature').command_name.should be == 'gh-signature'
19
+ end
20
+
21
+ it "prefixes the description" do
22
+ Travis::CLI.command('gh-signature').description.should start_with("GitHub plugin: ")
23
+ end
24
+ end
@@ -0,0 +1,30 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "travis/cli/gh/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "travis-cli-gh"
6
+ s.version = Travis::CLI::Gh::VERSION
7
+ s.author = "Konstantin Haase"
8
+ s.email = "konstantin@travis-ci.com"
9
+ s.homepage = "https://github.com/travis-ci/travis-cli-gh"
10
+ s.summary = %q{GitHub plugin for Travis CI command line client}
11
+ s.description = %q{Adds commands to interact with the GitHub API}
12
+ s.license = 'MIT'
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_path = 'lib'
17
+ s.extensions = ["setup/extconf.rb"]
18
+ s.required_ruby_version = '>= 2.0.0'
19
+
20
+ # runtime dependencies
21
+ s.add_dependency 'travis', '~> 1.6'
22
+ s.add_dependency 'gh', '~> 0.13'
23
+
24
+ # development depenendencies
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency "rake"
27
+
28
+ # prereleases from Travis CI
29
+ s.version = s.version.to_s.succ + ".travis.#{ENV['TRAVIS_JOB_NUMBER']}" if ENV['CI']
30
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: travis-cli-gh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2.travis.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Konstantin Haase
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: travis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gh
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.13'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Adds commands to interact with the GitHub API
70
+ email: konstantin@travis-ci.com
71
+ executables: []
72
+ extensions:
73
+ - setup/extconf.rb
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - init.rb
82
+ - lib/travis/cli/gh.rb
83
+ - lib/travis/cli/gh/github.rb
84
+ - lib/travis/cli/gh/login.rb
85
+ - lib/travis/cli/gh/signature.rb
86
+ - lib/travis/cli/gh/subcommands.rb
87
+ - lib/travis/cli/gh/version.rb
88
+ - lib/travis/cli/gh/whoami.rb
89
+ - setup/extconf.rb
90
+ - spec/subcommands_spec.rb
91
+ - travis-cli-gh.gemspec
92
+ homepage: https://github.com/travis-ci/travis-cli-gh
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: 2.0.0
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>'
108
+ - !ruby/object:Gem::Version
109
+ version: 1.3.1
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.0
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: GitHub plugin for Travis CI command line client
116
+ test_files: []