targit 0.0.1 → 0.0.2
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 +4 -4
- data/Rakefile +1 -1
- data/bin/targit +24 -2
- data/lib/targit.rb +1 -0
- data/lib/targit/asset.rb +14 -8
- data/lib/targit/release.rb +21 -11
- data/lib/targit/version.rb +5 -0
- data/targit.gemspec +5 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a6f6704460360a2e8248be6fe24353af06eb91f
|
4
|
+
data.tar.gz: 882f78545351adad22d2ede7fc3aa4b0e3ce4640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 350dba608c95da32eb1ef03147d01a66a5b7d9b4cee3dba57aa2a5180ab9adeefb6427508df5b50f1c86e84c651b05f6c03b409ebe27c0c9632d341d78b2cda4
|
7
|
+
data.tar.gz: 1dc6688a82844894d895682d645a4c99345c493fe5bffbe0d4ccf2a108b5cbec3a7b7545eb47d8bfee1918ce8cc3d336e01ef7c63d493eb91a16c0c738de730c
|
data/Rakefile
CHANGED
data/bin/targit
CHANGED
@@ -1,7 +1,29 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'targit'
|
4
|
+
require 'mercenary'
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
Mercenary.program(:targit) do |p|
|
7
|
+
p.version Targit::VERSION
|
8
|
+
p.description 'Tool for adding GitHub release assets'
|
9
|
+
p.syntax 'targit [options] USER/REPO TAG /path/to/file'
|
7
10
|
|
11
|
+
# rubocop:disable Style/LineLength
|
12
|
+
p.option :force, '-f', '--force', 'Replace the asset if it already exists'
|
13
|
+
p.option :create, '-c', '--create', 'Create release if it does not exist'
|
14
|
+
p.option :prerelease, '-p', '--prerelease', 'With -c, create as a dev release'
|
15
|
+
p.option :authfile, '-a FILE', '--authfile FILE', 'Set the auth file for GitHub credentials'
|
16
|
+
# rubocop:enable Style/LineLength
|
17
|
+
|
18
|
+
p.action do |args, options|
|
19
|
+
repo, tag, file = args
|
20
|
+
if repo && tag && file
|
21
|
+
puts "Attempting to upload #{file} on #{tag} of #{repo}"
|
22
|
+
asset = Targit.new(file, repo, tag, options)
|
23
|
+
asset.upload!
|
24
|
+
puts "Successfully created asset! #{asset.url}"
|
25
|
+
else
|
26
|
+
puts p
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/targit.rb
CHANGED
data/lib/targit/asset.rb
CHANGED
@@ -7,12 +7,12 @@ module Targit
|
|
7
7
|
class Asset
|
8
8
|
attr_reader :release, :asset, :name, :github_data
|
9
9
|
|
10
|
-
def initialize(asset, params = {})
|
10
|
+
def initialize(asset, repo, tag, params = {})
|
11
11
|
@options = params
|
12
12
|
@config = _config
|
13
13
|
@client = _client
|
14
|
-
@release = _release
|
15
|
-
@upload_options =
|
14
|
+
@release = _release repo, tag
|
15
|
+
@upload_options = _upload_options
|
16
16
|
@asset = asset
|
17
17
|
@name = @upload_options[:name] || File.basename(@asset)
|
18
18
|
end
|
@@ -20,7 +20,8 @@ module Targit
|
|
20
20
|
def upload!
|
21
21
|
delete! if @options[:force]
|
22
22
|
fail('Release asset already exists') if already_exists?
|
23
|
-
@client.upload_asset @release[:url], @asset, @
|
23
|
+
asset = @client.upload_asset @release.data[:url], @asset, @upload_options
|
24
|
+
@client.release_asset asset[:url]
|
24
25
|
end
|
25
26
|
|
26
27
|
def already_exists?
|
@@ -34,7 +35,12 @@ module Targit
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def github_data
|
37
|
-
@client.release_assets(@release[:url]).find { |x| x[:name] == @name }
|
38
|
+
@client.release_assets(@release.data[:url]).find { |x| x[:name] == @name }
|
39
|
+
end
|
40
|
+
|
41
|
+
def url
|
42
|
+
'https://github.com/' \
|
43
|
+
"#{@release.repo}/releases/download/#{@release.tag}/#{@name}"
|
38
44
|
end
|
39
45
|
|
40
46
|
private
|
@@ -58,11 +64,11 @@ module Targit
|
|
58
64
|
)
|
59
65
|
end
|
60
66
|
|
61
|
-
def _release
|
62
|
-
Targit::Release.new(@client, @options)
|
67
|
+
def _release(repo, tag)
|
68
|
+
Targit::Release.new(@client, repo, tag, @options)
|
63
69
|
end
|
64
70
|
|
65
|
-
def
|
71
|
+
def _upload_options
|
66
72
|
[:name, :content_type].each_with_object({}) do |option, hash|
|
67
73
|
hash[option] = @options[option] if @options[option]
|
68
74
|
end
|
data/lib/targit/release.rb
CHANGED
@@ -2,26 +2,36 @@ module Targit
|
|
2
2
|
##
|
3
3
|
# GitHub Release object
|
4
4
|
class Release
|
5
|
-
attr_reader :data
|
5
|
+
attr_reader :data, :repo, :tag
|
6
6
|
|
7
|
-
def initialize(client, params = {})
|
7
|
+
def initialize(client, repo, tag, params = {})
|
8
8
|
@client = client
|
9
|
-
@
|
10
|
-
|
9
|
+
@options = params
|
10
|
+
@repo = repo
|
11
|
+
@tag = tag
|
12
|
+
@create_options = _create_options
|
13
|
+
@data = find
|
14
|
+
create if @data.nil? && @options[:create]
|
15
|
+
fail('No release found') if @data.nil?
|
11
16
|
end
|
12
17
|
|
13
18
|
private
|
14
19
|
|
15
|
-
def find
|
16
|
-
@client.releases(
|
17
|
-
x[:tag_name] ==
|
20
|
+
def find
|
21
|
+
@client.releases(@repo).find do |x|
|
22
|
+
x[:tag_name] == @tag
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
|
-
def create
|
22
|
-
@client.create_release(
|
23
|
-
|
24
|
-
|
26
|
+
def create
|
27
|
+
@client.create_release(@repo, @tag)
|
28
|
+
@data = find
|
29
|
+
end
|
30
|
+
|
31
|
+
def _create_options
|
32
|
+
[:prerelease, :target_commitish].each_with_object({}) do |option, hash|
|
33
|
+
hash[option] = @options[option] if @options[option]
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
27
37
|
end
|
data/targit.gemspec
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
$:.unshift File.expand_path('../lib/', __FILE__)
|
2
|
+
require 'targit/version'
|
3
|
+
|
1
4
|
Gem::Specification.new do |s|
|
2
5
|
s.name = 'targit'
|
3
|
-
s.version =
|
6
|
+
s.version = Targit::VERSION
|
4
7
|
s.date = Time.now.strftime("%Y-%m-%d")
|
5
8
|
|
6
9
|
s.summary = 'Tool for adding GitHub release assets'
|
@@ -16,6 +19,7 @@ Gem::Specification.new do |s|
|
|
16
19
|
|
17
20
|
s.add_dependency 'octokit', '~> 3.2.0'
|
18
21
|
s.add_dependency 'octoauth', '~> 0.0.6'
|
22
|
+
s.add_dependency 'mercenary', '~> 0.3.3'
|
19
23
|
|
20
24
|
s.add_development_dependency 'rubocop', '~> 0.24.0'
|
21
25
|
s.add_development_dependency 'rake', '~> 10.3.2'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: targit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Les Aker
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.0.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mercenary
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.3.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.3.3
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rubocop
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -127,6 +141,7 @@ files:
|
|
127
141
|
- lib/targit.rb
|
128
142
|
- lib/targit/asset.rb
|
129
143
|
- lib/targit/release.rb
|
144
|
+
- lib/targit/version.rb
|
130
145
|
- spec/spec_helper.rb
|
131
146
|
- spec/targit_spec.rb
|
132
147
|
- targit.gemspec
|