travis-cli-gh 0.0.2.travis.3.1 → 0.0.2.travis.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGMzOTJhN2NiOTNmZTdjYjExNGE3NTFiMWY5NTQ0NTcxZDZkZTk2Mg==
4
+ ZGExMWMzYjk1ZWYxNmFmNDllZDg1N2U4YzJkZjRhOTA4MDE1MzZiOA==
5
5
  data.tar.gz: !binary |-
6
- MTgyYzlmYzM1OTc1MGM4Nzk5NGFjMmZlNWUxMDkyMmM3MTE5ZjJjZQ==
6
+ YmJjNzc4Zjk1YjRjMzVjZjA4MTM2NzFlYmZkMWFkM2IzZjE4Y2E2MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2VjZGEyN2Y0Y2YzYjEyNDA5NmM5M2RiMGUzZmQwZDkyMDY4MDk4ZWRkYzQ4
10
- MmFkMjM1YTQ1ZDc0MmZhNjRiY2U2ODZmNTM2YzZjYmVlMzBlZTIxY2MxN2Ix
11
- ZDY5YjY0OGJiMTM4Y2I4ZTZiMzZiYWU3ZDUyNjY0YTk5ZWZkZDU=
9
+ NGJmYjY3MDU4ZTE1YWJjY2E0MDdiZjgyNDI1ZjVjNTFmYzE0YjllODMyY2U5
10
+ MTk2MDY4YjBjNDExZmJhMGM5M2UwMjk2ZjIwNDNlMzhmMjNjNmRlZDY1ZDkx
11
+ ODFhMzMxNzI4N2JlNjBiOWQwOGY5MjRlNzQ1MGQxNTQzZDRjNTU=
12
12
  data.tar.gz: !binary |-
13
- ZGU5YzA3ZDNmMWU3YjExNjYzZTQwODdlMGU3OGRkN2ZkMmRhNDgzMWVlYjhh
14
- NDBhMzU0OTEyZmUyMGM1YWJmOWQyYmExN2UzZmYzYjg1NTQzZDFlNzczODIx
15
- MjhjOWNjY2ExYTg1ZmMzMDE4MDU1NmMwM2YzNzBlMzI4ZTE5Y2Q=
13
+ YjNmNzg5ZjZiNGU1ZGViOGI4MDUwZTExZDRhYThlNjA3YTgyZDc3ZGM4ZGFl
14
+ ZGMwODEzMmEzM2MzZTUwOWUyZjVhYTgzOWMzZGNlOTVlZmU5MjRjMGZlZTgx
15
+ NTY1ZmNhNjM4YmY4NzJiZTU5OWRlYWEyYzQwNGQ5Nzg3YWU0Mzg=
data/README.md CHANGED
@@ -4,7 +4,7 @@ This plugin for the [Travis Command Line Client](https://github.com/travis-ci/tr
4
4
 
5
5
  ## Usage
6
6
 
7
- This plugin adds the following commands: [`gh-cat`](#gh-cat), [`gh-fetch`](#gh-fetch), [`gh-login`](#gh-login), [`gh-signature`](#gh-signature) and [`gh-whoami`](#gh-whoami). 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).
7
+ This plugin adds the following commands: [`gh-cat`](#gh-cat), [`gh-fetch`](#gh-fetch), [`gh-login`](#gh-login), [`gh-signature`](#gh-signature), [`gh-upload`](#gh-upload), [`gh-whoami`](#gh-whoami) and [`gh-write`](#gh-write). 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
8
 
9
9
  ### `gh-cat`
10
10
 
@@ -42,6 +42,28 @@ Like [other commands](https://github.com/travis-ci/travis#repository-commands),
42
42
 
43
43
  This signature should be kept somewhat secret, otherwise other people can send you fake web hooks.
44
44
 
45
+ ### `gh-upload`
46
+
47
+ GitHub plugin: upload one or more files to the repository.
48
+ -h, --help Display help
49
+ -E, --[no-]explode don't rescue exceptions
50
+ --debug show API requests
51
+ -X, --enterprise [NAME] use enterprise setup (optionally takes name for multiple setups)
52
+ -r, --repo SLUG repository to use (will try to detect from current git clone)
53
+ -b, --branch BRANCH branch to write to
54
+ -m, --message MESSAGE commit message
55
+ -C, --create only create new files
56
+ -U, --update only update existing files
57
+ -c, --committer USER set committer (format: "name <email>", defaults to current user)
58
+ -a, --author USER set author (format: "name <email>", defaults to committer)
59
+ -A, --append append to file if it already exists
60
+ -p, --prefix DIR prefix to store it under
61
+
62
+ Like [`gh-write`](#gh-write), but uploads a file by the same name.
63
+
64
+ $ travis gh-upload ../somwhere/example.txt -p test
65
+ Uploading ../somwhere/example.txt as test/example.txt
66
+
45
67
  ### `gh-whoami`
46
68
 
47
69
  Displays which GitHub account you are logged in with on GitHub.
@@ -49,6 +71,29 @@ Displays which GitHub account you are logged in with on GitHub.
49
71
  $ travis gh-whoami
50
72
  logged in as rkh
51
73
 
74
+ ### `gh-write`
75
+
76
+ GitHub plugin: write stdin to the given path in the repository.
77
+ Usage: travis gh-write path [options]
78
+ -h, --help Display help
79
+ -E, --[no-]explode don't rescue exceptions
80
+ --debug show API requests
81
+ -X, --enterprise [NAME] use enterprise setup (optionally takes name for multiple setups)
82
+ -r, --repo SLUG repository to use (will try to detect from current git clone)
83
+ -b, --branch BRANCH branch to write to
84
+ -m, --message MESSAGE commit message
85
+ -C, --create only create new files
86
+ -U, --update only update existing files
87
+ -c, --committer USER set committer (format: "name <email>", defaults to current user)
88
+ -a, --author USER set author (format: "name <email>", defaults to committer)
89
+ -A, --append append to file if it already exists
90
+
91
+ Reads from stdin and writes it to the given file in the repository.
92
+
93
+ $ travis gh-write example -r example/repo
94
+ Hi folks!
95
+ <Ctrl+d>
96
+
52
97
  ## Installation
53
98
 
54
99
  You install it like any other gem:
@@ -10,9 +10,10 @@ module Travis
10
10
  autoload :Login, 'travis/cli/gh/login'
11
11
  autoload :Signature, 'travis/cli/gh/signature'
12
12
  autoload :Subcommands, 'travis/cli/gh/subcommands'
13
+ autoload :Upload, 'travis/cli/gh/upload'
13
14
  autoload :VERSION, 'travis/cli/gh/version'
14
15
  autoload :Whoami, 'travis/cli/gh/whoami'
15
- #autoload :Write, 'travis/cli/gh/write'
16
+ autoload :Write, 'travis/cli/gh/write'
16
17
 
17
18
  extend self
18
19
 
@@ -2,7 +2,7 @@ module Travis::CLI
2
2
  module Gh
3
3
  class Fetch < Cat
4
4
  description "download a file from a repository"
5
- on '-p', '--prefix DIR', 'Prefix to store it under'
5
+ on '-p', '--prefix DIR', 'prefix to store it under'
6
6
  on '-f', '--force', 'override existing files'
7
7
 
8
8
  def run(*paths)
@@ -6,9 +6,10 @@ module Travis::CLI
6
6
  module GitHub
7
7
  module Error
8
8
  def gh_error(e)
9
- raise e unless e.respond_to? :info
9
+ raise e if explode? or not e.respond_to? :info
10
10
  message = e.info[:response_body].to_s
11
11
  message = JSON.load(message).fetch('message') rescue nil
12
+ message = "GitHub says: #{message}"
12
13
  error message
13
14
  end
14
15
  end
@@ -0,0 +1,24 @@
1
+ require "base64"
2
+
3
+ module Travis::CLI
4
+ module Gh
5
+ class Upload < Write
6
+ description "upload one or more files to the repository"
7
+ on '-p', '--prefix DIR', 'prefix to store it under'
8
+
9
+ def run(*paths)
10
+ paths.each do |source|
11
+ error "cannot read #{source}" unless File.readable? source
12
+ target = File.basename(source)
13
+ target = File.join(prefix, target) if prefix
14
+ message = "Uploading " << color(source, :important)
15
+ message << " as " << color(target, :important) if target != source
16
+ say message
17
+ write(target, File.read(source))
18
+ end
19
+ rescue GH::Error => e
20
+ gh_error(e)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,74 @@
1
+ require "base64"
2
+
3
+ module Travis::CLI
4
+ module Gh
5
+ class Write < RepoCommand
6
+ include GitHub::Authenticated, GitHub::Error
7
+ USER_FORMAT = /^(?<name>.+) <(?<email>.+@.+)>$/
8
+
9
+ description "write stdin to the given path in the repository"
10
+ on '-b', '--branch BRANCH', 'branch to write to'
11
+ on '-m', '--message MESSAGE', 'commit message'
12
+ on '-C', '--create', 'only create new files'
13
+ on '-U', '--update', 'only update existing files'
14
+ on '-c', '--committer USER', 'set committer (format: "name <email>", defaults to current user)'
15
+ on '-a', '--author USER', 'set author (format: "name <email>", defaults to committer)'
16
+ on '-A', '--append', 'append to file if it already exists'
17
+
18
+ def run(path)
19
+ write(path, input.read)
20
+ rescue GH::Error => e
21
+ gh_error(e)
22
+ end
23
+
24
+ def write(path, content)
25
+ current = get(path)
26
+ error "file already exists" unless update?
27
+ update(path, content, current)
28
+ rescue GH::Error => e
29
+ gh_error(e) unless e.info[:response_status] == 404
30
+ error "file does not exist" unless create?
31
+ create(path, content)
32
+ end
33
+
34
+ def update(path, content, current = get(path))
35
+ error "#{path} is not a file" unless current.respond_to?(:to_hash) and current['type'] == 'file'
36
+ content = Base64.decode64(current['content']) + content if append?
37
+ put(path, content, message: "Update #{path}", sha: current['sha'])
38
+ end
39
+
40
+ def create(path, content)
41
+ put(path, content, message: "Create #{path}")
42
+ end
43
+
44
+ def put(path, content = "", encoded_content: Base64.encode64(content), **options)
45
+ options[:message] = message if message
46
+ options[:branch] = branch if branch
47
+ options[:content] = encoded_content
48
+ options[:path] = path
49
+ options[:committer] = parse_user(:committer) if committer
50
+ options[:author] = parse_user(:author) if author
51
+ gh.put("/repos/#{repository.slug}/contents/#{path}", options)
52
+ end
53
+
54
+ def get(path)
55
+ path = "repos/#{repository.slug}/contents/#{path}"
56
+ path << "?ref=#{branch}" if branch
57
+ gh[path]
58
+ end
59
+
60
+ def parse_user(field)
61
+ error "wrong format for #{field}, should be NAME <EMAIL>." unless match = USER_FORMAT.match(send(field).to_s)
62
+ { name: match[:name], email: match[:email] }
63
+ end
64
+
65
+ def create?
66
+ @create.nil? ? @update.nil? : @create
67
+ end
68
+
69
+ def update?
70
+ @update.nil? ? @create.nil? : @update
71
+ end
72
+ end
73
+ end
74
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: travis-cli-gh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.travis.3.1
4
+ version: 0.0.2.travis.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Haase
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-28 00:00:00.000000000 Z
11
+ date: 2013-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: travis
@@ -86,8 +86,10 @@ files:
86
86
  - lib/travis/cli/gh/login.rb
87
87
  - lib/travis/cli/gh/signature.rb
88
88
  - lib/travis/cli/gh/subcommands.rb
89
+ - lib/travis/cli/gh/upload.rb
89
90
  - lib/travis/cli/gh/version.rb
90
91
  - lib/travis/cli/gh/whoami.rb
92
+ - lib/travis/cli/gh/write.rb
91
93
  - setup/extconf.rb
92
94
  - spec/subcommands_spec.rb
93
95
  - travis-cli-gh.gemspec