github-upload 0.0.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.
Files changed (2) hide show
  1. data/bin/github-upload +87 -0
  2. metadata +91 -0
data/bin/github-upload ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'confparser'
4
+ require 'optparse'
5
+ require 'net/github-upload'
6
+
7
+ module Net
8
+ module GitHub
9
+ class Upload
10
+ def list_files repos
11
+ raise "required repository name" unless repos
12
+ res = HTTPClient.get_content("https://github.com/#{repos}/downloads", {
13
+ "login" => @login,
14
+ "token" => @token
15
+ })
16
+ Nokogiri::HTML(res).xpath('id("manual_downloads")/li').map do |fileinfo|
17
+ obj = {
18
+ description: fileinfo.at_xpath('descendant::h4').text.force_encoding('BINARY').gsub(/.+?\xe2\x80\x94 (.+?)(\n\s*)?$/m, '\1'),
19
+ date: fileinfo.at_xpath('descendant::p/time').attribute('title').text,
20
+ size: fileinfo.at_xpath('descendant::p/strong').text,
21
+ id: /\d+$/.match(fileinfo.at_xpath('a').attribute('href').text)[0]
22
+ }
23
+ anchor = fileinfo.at_xpath('descendant::h4/a')
24
+ obj[:link] = anchor.attribute('href').text
25
+ obj[:name] = anchor.text
26
+ obj
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def git_root (dir=Dir.pwd)
34
+ return dir if File.file?(File.join('.git', 'config'))
35
+ sup = File.dirname
36
+ if dir == sup
37
+ puts "This is NOT a git repository."
38
+ exit 1
39
+ end
40
+ git_root(dir)
41
+ end
42
+
43
+ login, token = ConfParser.from_file(File.join(Dir.home, '.gitconfig'))['github'].tap {|conf| break [conf['user'], conf['token']] }
44
+
45
+ file, meth, repo, message = nil, :upload, nil, 'Uploaded wih git-upload'
46
+
47
+ OptionParser.new {|opts|
48
+ opts.banner = "Usage: #$0 [options] [repository] file"
49
+
50
+ opts.on('-r', '--replace', 'Replace file if exists') {|*|
51
+ meth = :replace
52
+ }
53
+
54
+ opts.on('-m', '--message MESSAGE', 'Insert an upload message') {|mes|
55
+ message = mes
56
+ }
57
+ }.tap {|opts|
58
+ o = opts.parse!(ARGV)
59
+
60
+ case o.size
61
+ when 1
62
+ repo = ConfParser.from_file(File.join(git_root, '.git', 'config')).tap {|conf|
63
+ break conf[conf.keys.grep(/remote \".+?\"/).first]
64
+ }['url'].match(/\/(.+?)\.git$/)[1]
65
+
66
+ file = o.first
67
+ when 2
68
+ repo, file = o
69
+ else
70
+ puts opts
71
+ exit 1
72
+ end
73
+ }
74
+
75
+ raise "File doesn't exist." unless File.file?(file)
76
+
77
+ puts "Uploading file '#{file}' to http://github.com/#{login}/#{repo}/downloads"
78
+
79
+ gh = Net::GitHub::Upload.new(login: login, token: token)
80
+
81
+ begin
82
+ raise "Unrecognized error." unless gh.send(meth, {repos: repo, file: file, description: message})
83
+ puts "Done."
84
+ rescue Exception => e
85
+ puts "An error as occured: #{e}"
86
+ exit 1
87
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-upload
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - shura
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-08-11 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: confparser
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: net-github-upload
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 0
44
+ - 5
45
+ version: 0.0.5
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: A simple cli client to upload file in a github repository.
49
+ email: shura1991@gmail.com
50
+ executables:
51
+ - github-upload
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - bin/github-upload
58
+ has_rdoc: true
59
+ homepage: http://github.com/shurizzle/github-upload
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A simple cli client to upload file in a github repository.
90
+ test_files: []
91
+