gistribute 0.2 → 0.3
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/.github/workflows/blocking-issues.yml +14 -0
- data/.github/workflows/lint.yml +17 -0
- data/.github/workflows/test.yml +21 -0
- data/.gitignore +21 -0
- data/.rubocop.yml +94 -0
- data/Gemfile +4 -0
- data/README.md +32 -23
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/bin/gistribute +3 -83
- data/gistribute.gemspec +14 -7
- data/lib/cli/auth.rb +64 -0
- data/lib/cli/install.rb +86 -0
- data/lib/cli/upload.rb +54 -0
- data/lib/cli.rb +117 -0
- data/lib/gistribute.rb +33 -0
- data/spec/.rubocop.yml +46 -0
- data/spec/gistribute/cli_auth_spec.rb +133 -0
- data/spec/gistribute/cli_install_spec.rb +193 -0
- data/spec/gistribute/cli_spec.rb +31 -0
- data/spec/gistribute/cli_upload_spec.rb +161 -0
- data/spec/gistribute_spec.rb +15 -27
- data/spec/spec_helper.rb +40 -0
- data/spec/support/cli.rb +27 -0
- data/spec/support/constants.rb +4 -0
- metadata +123 -6
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
ENCODED_TEMP = "|tmp|gistribute_spec"
|
6
|
+
|
7
|
+
SINGLE_FILE_PATH = "#{TEMP}/#{FILENAME}".freeze
|
8
|
+
ENCODED_SINGLE_FILE_PATH = "#{ENCODED_TEMP}|#{FILENAME}".freeze
|
9
|
+
HOME_FILE_PATH = "#{Dir.home}/#{FILENAME}".freeze
|
10
|
+
ENCODED_HOME_FILE_PATH = "~|#{FILENAME}".freeze
|
11
|
+
|
12
|
+
SINGLE_FILE_CONTENT = "Line 1\nLine 2\n"
|
13
|
+
SINGLE_FILE_DESC = "Test File"
|
14
|
+
|
15
|
+
MOCK_GIST_URL = "https://gist.github.com/vinnydiehl/thisisnotarealgistid"
|
16
|
+
|
17
|
+
describe Gistribute::CLI do
|
18
|
+
let(:octokit_client) { instance_double(Octokit::Client) }
|
19
|
+
|
20
|
+
before do
|
21
|
+
FileUtils.rm_rf TEMP
|
22
|
+
FileUtils.mkdir_p TEMP
|
23
|
+
|
24
|
+
allow(Octokit::Client).to receive(:new).and_return(octokit_client)
|
25
|
+
allow(octokit_client).to receive(:user).and_return(double(login: "test"))
|
26
|
+
allow(octokit_client).to receive(:create_gist).and_return(double(html_url: MOCK_GIST_URL))
|
27
|
+
|
28
|
+
suppress_stdout
|
29
|
+
end
|
30
|
+
|
31
|
+
after { FileUtils.rm_rf TEMP }
|
32
|
+
|
33
|
+
describe "#upload" do
|
34
|
+
before { allow($stdout).to receive(:puts) }
|
35
|
+
|
36
|
+
context "with a single file" do
|
37
|
+
before do
|
38
|
+
File.write(SINGLE_FILE_PATH, SINGLE_FILE_CONTENT)
|
39
|
+
simulate_user_input "Test File\n", "y\n"
|
40
|
+
run "upload", SINGLE_FILE_PATH
|
41
|
+
end
|
42
|
+
|
43
|
+
let :expected_api_call do
|
44
|
+
{
|
45
|
+
description: "[gistribution]",
|
46
|
+
public: true,
|
47
|
+
files: {
|
48
|
+
"#{SINGLE_FILE_DESC} || #{ENCODED_SINGLE_FILE_PATH}" => {
|
49
|
+
content: SINGLE_FILE_CONTENT
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
it "uploads the file correctly" do
|
56
|
+
expect(octokit_client).to have_received(:create_gist)
|
57
|
+
.with(expected_api_call)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "prints the URL of the Gist" do
|
61
|
+
expect($stdout).to have_received(:puts).with MOCK_GIST_URL
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "with a single file in the home directory" do
|
66
|
+
before do
|
67
|
+
File.write(HOME_FILE_PATH, SINGLE_FILE_CONTENT)
|
68
|
+
simulate_user_input "Test File\n", "y\n"
|
69
|
+
run "upload", "~/#{FILENAME}"
|
70
|
+
end
|
71
|
+
|
72
|
+
after { FileUtils.rm HOME_FILE_PATH }
|
73
|
+
|
74
|
+
let :expected_api_call do
|
75
|
+
{
|
76
|
+
description: "[gistribution]",
|
77
|
+
public: true,
|
78
|
+
files: { "#{SINGLE_FILE_DESC} || #{ENCODED_HOME_FILE_PATH}" => { content: SINGLE_FILE_CONTENT } }
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
it "uploads the file correctly" do
|
83
|
+
expect(octokit_client).to have_received(:create_gist)
|
84
|
+
.with(expected_api_call)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
{
|
89
|
+
"multiple files": ["#{TEMP}/dir/file1", "#{TEMP}/file2"],
|
90
|
+
"a directory containing multiple files": [TEMP]
|
91
|
+
}.each do |desc, args|
|
92
|
+
context "with #{desc} passed in" do
|
93
|
+
let(:file1_content) { "F1L1\nF1L2\n" }
|
94
|
+
let(:file2_content) { "F2L1\nF2L2\n" }
|
95
|
+
|
96
|
+
before do
|
97
|
+
FileUtils.mkdir_p "#{TEMP}/dir"
|
98
|
+
File.write("#{TEMP}/dir/file1", file1_content)
|
99
|
+
File.write("#{TEMP}/file2", file2_content)
|
100
|
+
|
101
|
+
simulate_user_input "File 1\n", "File 2\n", "y\n"
|
102
|
+
run "upload", *args
|
103
|
+
end
|
104
|
+
|
105
|
+
let :expected_api_call do
|
106
|
+
{
|
107
|
+
description: "[gistribution]",
|
108
|
+
public: true,
|
109
|
+
files: {
|
110
|
+
"File 1 || #{ENCODED_TEMP}|dir|file1" => { content: file1_content },
|
111
|
+
"File 2 || #{ENCODED_TEMP}|file2" => { content: file2_content }
|
112
|
+
}
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
it "uploads the files correctly" do
|
117
|
+
expect(octokit_client).to have_received(:create_gist)
|
118
|
+
.with(expected_api_call)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "with the `--description` flag" do
|
124
|
+
before do
|
125
|
+
File.write(SINGLE_FILE_PATH, SINGLE_FILE_CONTENT)
|
126
|
+
simulate_user_input "Test File\n", "y\n"
|
127
|
+
run "upload", "--description", "foo bar", SINGLE_FILE_PATH
|
128
|
+
end
|
129
|
+
|
130
|
+
it "uses the given description" do
|
131
|
+
expect(octokit_client).to have_received(:create_gist)
|
132
|
+
.with(a_hash_including(description: "[gistribution] foo bar"))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "with the `--private` flag" do
|
137
|
+
before do
|
138
|
+
File.write(SINGLE_FILE_PATH, SINGLE_FILE_CONTENT)
|
139
|
+
simulate_user_input "Test File\n", "y\n"
|
140
|
+
run "upload", "--private", SINGLE_FILE_PATH
|
141
|
+
end
|
142
|
+
|
143
|
+
it "uploads a private Gist" do
|
144
|
+
expect(octokit_client).to have_received(:create_gist)
|
145
|
+
.with(a_hash_including(public: false))
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "with the `--yes` flag" do
|
150
|
+
before do
|
151
|
+
File.write(SINGLE_FILE_PATH, SINGLE_FILE_CONTENT)
|
152
|
+
simulate_user_input "Test File\n"
|
153
|
+
run "upload", "--yes", SINGLE_FILE_PATH
|
154
|
+
end
|
155
|
+
|
156
|
+
it "uploads without prompting the user" do
|
157
|
+
expect(octokit_client).to have_received(:create_gist)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
data/spec/gistribute_spec.rb
CHANGED
@@ -1,33 +1,21 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
|
-
describe
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
%w[--version -v].each do |flag|
|
21
|
-
context "with the #{flag} flag" do
|
22
|
-
it "outputs the version" do
|
23
|
-
expect(`gistribute #{flag}`).to eq "Gistribute #{version}\n"
|
5
|
+
describe Gistribute do
|
6
|
+
describe "::parse_id" do
|
7
|
+
[PUB_SINGLE_FILE_ID, SEC_SINGLE_FILE_ID].each do |id|
|
8
|
+
[
|
9
|
+
"https://gist.github.com/username/#{id}",
|
10
|
+
"https://gist.github.com/#{id}",
|
11
|
+
id
|
12
|
+
].each do |link|
|
13
|
+
context "when given the String: #{link}" do
|
14
|
+
it "parses down to the Gist ID" do
|
15
|
+
expect(described_class.parse_id(link)).to eq(id)
|
16
|
+
end
|
17
|
+
end
|
24
18
|
end
|
25
19
|
end
|
26
20
|
end
|
27
|
-
|
28
|
-
context "with a single file Gist" do
|
29
|
-
it "allows both the full URL and the Gist ID" do
|
30
|
-
expect(output).to eq output_only_id
|
31
|
-
end
|
32
|
-
end
|
33
21
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "gistribute"
|
4
|
+
|
5
|
+
# Get OAuth token from environment if there is none
|
6
|
+
unless File.exist?(CONFIG_FILE)
|
7
|
+
File.write(CONFIG_FILE, ENV.fetch("GISTRIBUTE_TEST_OAUTH_TOKEN"))
|
8
|
+
end
|
9
|
+
|
10
|
+
# Yes, this could be leaked in CI, but it's just a gist scoped token for a dummy account
|
11
|
+
OAUTH_TOKEN = File.read(CONFIG_FILE).freeze
|
12
|
+
|
13
|
+
# Include all files in spec/support
|
14
|
+
Dir[File.expand_path("support/**/*.rb", __dir__)].each { |f| require f }
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
# Add `focus: true` hash parameter to a describe/context/it block
|
18
|
+
# to only run the specs in that block
|
19
|
+
config.filter_run_when_matching :focus
|
20
|
+
|
21
|
+
# Fuubar
|
22
|
+
unless ARGV.any? { |arg| arg.include? "-f" }
|
23
|
+
config.add_formatter "Fuubar"
|
24
|
+
config.fuubar_progress_bar_options = { format: " %c/%C |%b>%i|%e " }
|
25
|
+
end
|
26
|
+
|
27
|
+
# More verbose output if only running one spec
|
28
|
+
config.default_formatter = "doc" if config.files_to_run.one?
|
29
|
+
|
30
|
+
# Print the 10 slowest examples and example groups at the
|
31
|
+
# end of the spec run, to help surface which specs are running
|
32
|
+
# particularly slow.
|
33
|
+
config.profile_examples = 10
|
34
|
+
|
35
|
+
# Run specs in random order to surface order dependencies. If you find an
|
36
|
+
# order dependency and want to debug it, fix the order by providing the seed,
|
37
|
+
# which is printed after each run, e.g. --seed 1234
|
38
|
+
config.order = :random
|
39
|
+
Kernel.srand config.seed
|
40
|
+
end
|
data/spec/support/cli.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
def suppress_stdout
|
4
|
+
allow($stdout).to receive(:write)
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_argv(*args)
|
8
|
+
ARGV.replace(args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def run(*args, fail_on_exit: true)
|
12
|
+
set_argv(*args)
|
13
|
+
|
14
|
+
begin
|
15
|
+
Gistribute::CLI.new.run
|
16
|
+
rescue SystemExit
|
17
|
+
fail "unexpected exit" if fail_on_exit
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def simulate_user_input(*inputs)
|
22
|
+
# The reference to `inputs` ends up getting stored in the mock, since
|
23
|
+
# it's passed in with the block. Each time `gets` is called we pull
|
24
|
+
# one off the beginning. If there aren't enough inputs, the error
|
25
|
+
# gets raised.
|
26
|
+
allow($stdin).to receive(:gets) { inputs.shift || fail("blocked for input") }
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gistribute
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinny Diehl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -24,6 +24,62 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday-retry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: launchy
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: octokit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '6.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '6.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: optimist_xl
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.3'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.3'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
84
|
name: fuubar
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +108,48 @@ dependencies:
|
|
52
108
|
- - "~>"
|
53
109
|
- !ruby/object:Gem::Version
|
54
110
|
version: '3.12'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.54'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.54'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop-rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '2.22'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.22'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: yard
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.9'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.9'
|
55
153
|
description: Distribute files simply using GitHub Gist.
|
56
154
|
email: vinny.diehl@gmail.com
|
57
155
|
executables:
|
@@ -59,17 +157,37 @@ executables:
|
|
59
157
|
extensions: []
|
60
158
|
extra_rdoc_files: []
|
61
159
|
files:
|
160
|
+
- ".github/workflows/blocking-issues.yml"
|
161
|
+
- ".github/workflows/lint.yml"
|
162
|
+
- ".github/workflows/test.yml"
|
163
|
+
- ".gitignore"
|
164
|
+
- ".rubocop.yml"
|
165
|
+
- Gemfile
|
62
166
|
- LICENSE
|
63
167
|
- README.md
|
64
168
|
- Rakefile
|
65
169
|
- VERSION
|
66
170
|
- bin/gistribute
|
67
171
|
- gistribute.gemspec
|
172
|
+
- lib/cli.rb
|
173
|
+
- lib/cli/auth.rb
|
174
|
+
- lib/cli/install.rb
|
175
|
+
- lib/cli/upload.rb
|
176
|
+
- lib/gistribute.rb
|
177
|
+
- spec/.rubocop.yml
|
178
|
+
- spec/gistribute/cli_auth_spec.rb
|
179
|
+
- spec/gistribute/cli_install_spec.rb
|
180
|
+
- spec/gistribute/cli_spec.rb
|
181
|
+
- spec/gistribute/cli_upload_spec.rb
|
68
182
|
- spec/gistribute_spec.rb
|
69
|
-
|
183
|
+
- spec/spec_helper.rb
|
184
|
+
- spec/support/cli.rb
|
185
|
+
- spec/support/constants.rb
|
186
|
+
homepage: https://github.com/vinnydiehl/gistribute
|
70
187
|
licenses:
|
71
188
|
- MIT
|
72
|
-
metadata:
|
189
|
+
metadata:
|
190
|
+
rubygems_mfa_required: 'true'
|
73
191
|
post_install_message:
|
74
192
|
rdoc_options: []
|
75
193
|
require_paths:
|
@@ -89,5 +207,4 @@ rubygems_version: 3.4.17
|
|
89
207
|
signing_key:
|
90
208
|
specification_version: 4
|
91
209
|
summary: GitHub Gist based file distribution.
|
92
|
-
test_files:
|
93
|
-
- spec/gistribute_spec.rb
|
210
|
+
test_files: []
|