rosette-client 1.0.0
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 +7 -0
- data/Gemfile +14 -0
- data/History.txt +3 -0
- data/README.md +4 -0
- data/Rakefile +18 -0
- data/bin/git-rosette +17 -0
- data/lib/rosette/client/api.rb +128 -0
- data/lib/rosette/client/cli.rb +42 -0
- data/lib/rosette/client/commands/commit_command.rb +42 -0
- data/lib/rosette/client/commands/diff_command.rb +110 -0
- data/lib/rosette/client/commands/repo_snapshot_command.rb +38 -0
- data/lib/rosette/client/commands/show_command.rb +40 -0
- data/lib/rosette/client/commands/snapshot_command.rb +41 -0
- data/lib/rosette/client/commands/status_command.rb +96 -0
- data/lib/rosette/client/commands.rb +68 -0
- data/lib/rosette/client/repo.rb +32 -0
- data/lib/rosette/client/response.rb +38 -0
- data/lib/rosette/client/terminal.rb +33 -0
- data/lib/rosette/client/version.rb +7 -0
- data/lib/rosette/client.rb +13 -0
- data/rosette-client.gemspec +23 -0
- data/spec/api_spec.rb +96 -0
- data/spec/cli_spec.rb +33 -0
- data/spec/commands/commit_command_spec.rb +69 -0
- data/spec/commands/diff_command_spec.rb +151 -0
- data/spec/commands/repo_snapshot_command_spec.rb +71 -0
- data/spec/commands/show_command_spec.rb +72 -0
- data/spec/commands/snapshot_command_spec.rb +72 -0
- data/spec/commands/status_command_spec.rb +77 -0
- data/spec/helpers/fake_terminal.rb +30 -0
- data/spec/repo_spec.rb +31 -0
- data/spec/response_spec.rb +51 -0
- data/spec/spec_helper.rb +49 -0
- data/spec/terminal_spec.rb +22 -0
- metadata +108 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Client
|
6
|
+
include Rosette::Client::Commands
|
7
|
+
|
8
|
+
describe SnapshotCommand do
|
9
|
+
let(:api) { double }
|
10
|
+
let(:base_repo) { TmpRepo.new }
|
11
|
+
let(:repo) { Repo.new(base_repo.working_dir) }
|
12
|
+
let(:terminal) { FakeTerminal.new }
|
13
|
+
let(:repo_name) { 'my_awesome_repo' }
|
14
|
+
let(:commit_id) { base_repo.git('rev-parse HEAD').strip }
|
15
|
+
let(:command) { SnapshotCommand.new(api, terminal, repo, [commit_id]) }
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
add_user_to(base_repo)
|
19
|
+
base_repo.git("remote add origin git@github.com/camertron/#{repo_name}")
|
20
|
+
base_repo.create_file('file.txt') { |f| f.write('hello, world') }
|
21
|
+
base_repo.add_all
|
22
|
+
base_repo.commit('Initial commit')
|
23
|
+
end
|
24
|
+
|
25
|
+
around(:each) do |example|
|
26
|
+
Dir.chdir(base_repo.working_dir) do
|
27
|
+
example.run
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#execute' do
|
32
|
+
it 'makes a snapshot api call' do
|
33
|
+
expect(api).to receive(:snapshot)
|
34
|
+
.with(repo_name: repo_name, ref: commit_id)
|
35
|
+
.and_return(Response.new({}))
|
36
|
+
|
37
|
+
command.execute
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'prints the array of phrases' do
|
41
|
+
expect(api).to receive(:snapshot)
|
42
|
+
.with(repo_name: repo_name, ref: commit_id)
|
43
|
+
.and_return(
|
44
|
+
Response.new([
|
45
|
+
{ 'key' => 'Foo', 'commit_id' => 'abc123' },
|
46
|
+
{ 'key' => 'Bar', 'commit_id' => 'def456' },
|
47
|
+
{ 'key' => 'Baz', 'commit_id' => 'ghi789' }
|
48
|
+
])
|
49
|
+
)
|
50
|
+
|
51
|
+
command.execute
|
52
|
+
|
53
|
+
expect(terminal).to have_said('key: Foo')
|
54
|
+
expect(terminal).to have_said('commit_id: abc123')
|
55
|
+
expect(terminal).to have_said('key: Bar')
|
56
|
+
expect(terminal).to have_said('commit_id: def456')
|
57
|
+
expect(terminal).to have_said('key: Baz')
|
58
|
+
expect(terminal).to have_said('commit_id: ghi789')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'prints the error if the api response contains one' do
|
62
|
+
expect(api).to receive(:snapshot)
|
63
|
+
.with(repo_name: repo_name, ref: commit_id)
|
64
|
+
.and_return(
|
65
|
+
Response.new({ 'error' => 'Jelly beans' })
|
66
|
+
)
|
67
|
+
|
68
|
+
command.execute
|
69
|
+
expect(terminal).to have_said('Jelly beans')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Client
|
6
|
+
include Rosette::Client::Commands
|
7
|
+
|
8
|
+
describe StatusCommand do
|
9
|
+
let(:api) { double }
|
10
|
+
let(:base_repo) { TmpRepo.new }
|
11
|
+
let(:repo) { Repo.new(base_repo.working_dir) }
|
12
|
+
let(:terminal) { FakeTerminal.new }
|
13
|
+
let(:repo_name) { 'my_awesome_repo' }
|
14
|
+
let(:commit_id) { base_repo.git('rev-parse HEAD').strip }
|
15
|
+
let(:command) { StatusCommand.new(api, terminal, repo, [commit_id]) }
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
add_user_to(base_repo)
|
19
|
+
base_repo.git("remote add origin git@github.com/camertron/#{repo_name}")
|
20
|
+
base_repo.create_file('file.txt') { |f| f.write('hello, world') }
|
21
|
+
base_repo.add_all
|
22
|
+
base_repo.commit('Initial commit')
|
23
|
+
end
|
24
|
+
|
25
|
+
around(:each) do |example|
|
26
|
+
Dir.chdir(base_repo.working_dir) do
|
27
|
+
example.run
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#execute' do
|
32
|
+
it 'makes a commit api call' do
|
33
|
+
expect(api).to receive(:status)
|
34
|
+
.with(repo_name: repo_name, ref: commit_id)
|
35
|
+
.and_return(Response.new({}))
|
36
|
+
|
37
|
+
command.execute
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'prints the status as a table' do
|
41
|
+
expect(api).to receive(:status)
|
42
|
+
.with(repo_name: repo_name, ref: commit_id)
|
43
|
+
.and_return(
|
44
|
+
Response.new({
|
45
|
+
'commit_id' => commit_id,
|
46
|
+
'status' => 'UNTRANSLATED',
|
47
|
+
'phrase_count' => 10,
|
48
|
+
'locales' => [{
|
49
|
+
'locale' => 'fr-FR',
|
50
|
+
'percent_translated' => 0.5,
|
51
|
+
'translated_count' => 5
|
52
|
+
}, {
|
53
|
+
'locale' => 'pt-BR',
|
54
|
+
'percent_translated' => 0.2,
|
55
|
+
'translated_count' => 2
|
56
|
+
}]
|
57
|
+
})
|
58
|
+
)
|
59
|
+
|
60
|
+
command.execute
|
61
|
+
|
62
|
+
expect(terminal).to have_said(Regexp.compile(['fr-FR', '10', '5', '0.5'].join('[ ]*\|[ ]*')))
|
63
|
+
expect(terminal).to have_said(Regexp.compile(['pt-BR', '10', '2', '0.2'].join('[ ]*\|[ ]*')))
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'prints the error if the api response contains one' do
|
67
|
+
expect(api).to receive(:status)
|
68
|
+
.with(repo_name: repo_name, ref: commit_id)
|
69
|
+
.and_return(
|
70
|
+
Response.new({ 'error' => 'Jelly beans' })
|
71
|
+
)
|
72
|
+
|
73
|
+
command.execute
|
74
|
+
expect(terminal).to have_said('Jelly beans')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
class FakeTerminal
|
4
|
+
attr_reader :statements
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@statements = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def say(text, color = nil)
|
11
|
+
statements << [text, color]
|
12
|
+
end
|
13
|
+
|
14
|
+
def has_said?(text_or_regex, color = nil)
|
15
|
+
case text_or_regex
|
16
|
+
when Regexp
|
17
|
+
statements.any? do |statement|
|
18
|
+
matches = text_or_regex =~ statement.first
|
19
|
+
matches &&= color == statement.last if color
|
20
|
+
matches
|
21
|
+
end
|
22
|
+
when String
|
23
|
+
statements.any? do |statement|
|
24
|
+
matches = text_or_regex == statement.first
|
25
|
+
matches &&= color == statement.last if color
|
26
|
+
matches
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/repo_spec.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Client
|
6
|
+
|
7
|
+
describe Repo do
|
8
|
+
let(:base_repo) { TmpRepo.new }
|
9
|
+
let(:repo) { Repo.new(base_repo.working_dir) }
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
add_user_to(base_repo)
|
13
|
+
base_repo.create_file('file.txt') { |f| f.write('hello, world') }
|
14
|
+
base_repo.add_all
|
15
|
+
base_repo.commit('Initial commit')
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#get_head' do
|
19
|
+
it 'returns the symbolic ref (i.e. branch name) of HEAD' do
|
20
|
+
expect(repo.get_head).to eq('master')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#rev_parse' do
|
25
|
+
it 'returns the commit id of the given ref' do
|
26
|
+
expect(repo.rev_parse('master')).to(
|
27
|
+
eq(base_repo.git('rev-parse master').strip)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Client
|
6
|
+
|
7
|
+
describe Response do
|
8
|
+
let(:response_class) { Response }
|
9
|
+
|
10
|
+
it 'responds to methods that are also keys in the attributes hash' do
|
11
|
+
response = response_class.new({ 'hello' => 'world' })
|
12
|
+
expect(response.hello).to eq('world')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns nil if the method isn't part of the attributes hash" do
|
16
|
+
response = response_class.new({ 'hello' => 'world' })
|
17
|
+
expect(response.nothing).to be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'from_api_response' do
|
21
|
+
it 'accepts a hash of attributes and returns an instance of Response' do
|
22
|
+
response = response_class.from_api_response({ 'foo' => 'bar' })
|
23
|
+
expect(response).to be_a(response_class)
|
24
|
+
expect(response.attributes).to eq({ 'foo' => 'bar' })
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#error?' do
|
29
|
+
it 'returns true if the attributes hash contains an "error" key' do
|
30
|
+
response = response_class.new({ 'error' => 'jelly beans' })
|
31
|
+
expect(response).to be_error
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns false if the attributes hasn does not contain an "error" key' do
|
35
|
+
response = response_class.new({ 'not error' => 'lima beans' })
|
36
|
+
expect(response).to_not be_error
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#success?' do
|
41
|
+
it 'returns true if the attributes hasn does not contain an "error" key' do
|
42
|
+
response = response_class.new({ 'not error' => 'lima beans' })
|
43
|
+
expect(response).to be_success
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns false if the attributes hash contains an "error" key' do
|
47
|
+
response = response_class.new({ 'error' => 'jelly beans' })
|
48
|
+
expect(response).to_not be_success
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'pry-nav'
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'rosette/client'
|
7
|
+
require 'helpers/fake_terminal'
|
8
|
+
require 'tmp-repo'
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
# config goes here
|
12
|
+
|
13
|
+
def sample_diff(commit_id)
|
14
|
+
{
|
15
|
+
'added' => [{
|
16
|
+
'key' => "I'm a little teapot",
|
17
|
+
'meta_key' => 'about.training.teapot',
|
18
|
+
'file' => 'config/locales/en.yml',
|
19
|
+
'commit_id' => commit_id
|
20
|
+
}],
|
21
|
+
|
22
|
+
'removed' => [{
|
23
|
+
'key' => 'The green albatross flitters in the moonlight',
|
24
|
+
'meta_key' => 'animals.birds.albatross.message',
|
25
|
+
'file' => 'config/locales/en.yml',
|
26
|
+
'commit_id' => commit_id
|
27
|
+
}],
|
28
|
+
|
29
|
+
'modified' => [{
|
30
|
+
'key' => 'Purple eggplants make delicious afternoon snacks',
|
31
|
+
'old_key' => 'Blue eggplants make wonderful evening meals',
|
32
|
+
'meta_key' => 'foods.vegetables.eggplant.snack_message',
|
33
|
+
'file' => 'config/locales/en.yml',
|
34
|
+
'commit_id' => commit_id
|
35
|
+
}, {
|
36
|
+
'key' => 'The Seattle Seahawks rock',
|
37
|
+
'old_key' => 'The Seattle Seahawks rule',
|
38
|
+
'meta_key' => 'sports.teams.football.best',
|
39
|
+
'file' => 'config/locales/en.yml',
|
40
|
+
'commit_id' => commit_id
|
41
|
+
}]
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_user_to(repo)
|
46
|
+
repo.git('config user.name Fake User')
|
47
|
+
repo.git('config user.email fake@user.com')
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Rosette::Client
|
6
|
+
|
7
|
+
describe Terminal do
|
8
|
+
let(:stream) { StringIO.new }
|
9
|
+
let(:terminal) { Terminal.new(stream) }
|
10
|
+
|
11
|
+
describe '#say' do
|
12
|
+
it 'writes to the stream' do
|
13
|
+
terminal.say("I'm a little teapot")
|
14
|
+
expect(stream.string).to eq("I'm a little teapot\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'colorizes the output when asked' do
|
18
|
+
terminal.say("I'm a little teapot", :red)
|
19
|
+
expect(stream.string).to eq("\e[0;31;49mI'm a little teapot\e[0m\n")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rosette-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cameron Dutro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.0
|
41
|
+
description: Git command integration for the Rosette internationalization platform
|
42
|
+
that manages the translatable content in the source files of a git repository.
|
43
|
+
email:
|
44
|
+
- camertron@gmail.com
|
45
|
+
executables:
|
46
|
+
- git-rosette
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- lib/rosette/client/api.rb
|
51
|
+
- lib/rosette/client/cli.rb
|
52
|
+
- lib/rosette/client/commands/commit_command.rb
|
53
|
+
- lib/rosette/client/commands/diff_command.rb
|
54
|
+
- lib/rosette/client/commands/repo_snapshot_command.rb
|
55
|
+
- lib/rosette/client/commands/show_command.rb
|
56
|
+
- lib/rosette/client/commands/snapshot_command.rb
|
57
|
+
- lib/rosette/client/commands/status_command.rb
|
58
|
+
- lib/rosette/client/commands.rb
|
59
|
+
- lib/rosette/client/repo.rb
|
60
|
+
- lib/rosette/client/response.rb
|
61
|
+
- lib/rosette/client/terminal.rb
|
62
|
+
- lib/rosette/client/version.rb
|
63
|
+
- lib/rosette/client.rb
|
64
|
+
- spec/api_spec.rb
|
65
|
+
- spec/cli_spec.rb
|
66
|
+
- spec/commands/commit_command_spec.rb
|
67
|
+
- spec/commands/diff_command_spec.rb
|
68
|
+
- spec/commands/repo_snapshot_command_spec.rb
|
69
|
+
- spec/commands/show_command_spec.rb
|
70
|
+
- spec/commands/snapshot_command_spec.rb
|
71
|
+
- spec/commands/status_command_spec.rb
|
72
|
+
- spec/helpers/fake_terminal.rb
|
73
|
+
- spec/repo_spec.rb
|
74
|
+
- spec/response_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
- spec/terminal_spec.rb
|
77
|
+
- Gemfile
|
78
|
+
- History.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- rosette-client.gemspec
|
82
|
+
- bin/git-rosette
|
83
|
+
homepage: http://github.com/camertron
|
84
|
+
licenses: []
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.0.14
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: Git command integration for the Rosette internationalization platform that
|
106
|
+
manages the translatable content in the source files of a git repository.
|
107
|
+
test_files: []
|
108
|
+
has_rdoc: true
|