reivt 1.5.0 → 1.6.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 +4 -4
- data/.gitignore +15 -14
- data/.rubocop.yml +1168 -1168
- data/Gemfile +11 -11
- data/README.md +3 -2
- data/Rakefile +22 -22
- data/bin/console +9 -9
- data/exe/revit +5 -5
- data/guides/BaemptyError.md +31 -31
- data/guides/CreatingRevs.md +50 -50
- data/guides/GraphQLDataIssue.md +5 -5
- data/guides/GraphQLValidationError.md +5 -5
- data/guides/LoggingIn.md +17 -17
- data/lib/reivt/api/mutations/document_create.mutation.rb +50 -50
- data/lib/reivt/api/mutations/document_delete.mutation.rb +36 -36
- data/lib/reivt/api/mutations/rev_create.mutation.rb +38 -38
- data/lib/reivt/api/mutations/rev_delete.mutation.rb +36 -36
- data/lib/reivt/api/mutations/user_create.mutation.rb +32 -32
- data/lib/reivt/api/mutations/user_signin.mutation.rb +39 -39
- data/lib/reivt/api.rb +64 -64
- data/lib/reivt/auth.rb +96 -82
- data/lib/reivt/cli.rb +167 -165
- data/lib/reivt/document.rb +67 -67
- data/lib/reivt/exception.rb +48 -35
- data/lib/reivt/schema/schema.json +20981 -20981
- data/lib/reivt/util.rb +112 -112
- data/lib/reivt/version.rb +3 -3
- data/lib/reivt.rb +42 -42
- data/revit.gemspec +44 -44
- metadata +2 -2
data/lib/reivt/cli.rb
CHANGED
@@ -1,165 +1,167 @@
|
|
1
|
-
# rubocop: disable Metrics/AbcSize, Metrics/MethodLength, Metrics/ClassLength
|
2
|
-
require 'paint'
|
3
|
-
require 'thor'
|
4
|
-
require 'tty-spinner'
|
5
|
-
|
6
|
-
#
|
7
|
-
# An extension of our main module
|
8
|
-
#
|
9
|
-
# @author [brwnrclse]
|
10
|
-
#
|
11
|
-
module Reivt
|
12
|
-
#
|
13
|
-
# Rev's cli
|
14
|
-
#
|
15
|
-
# @author [brwnrclse]
|
16
|
-
#
|
17
|
-
class CLI < Thor
|
18
|
-
namespace :revit
|
19
|
-
|
20
|
-
map %w(--version -v) => :__print_version
|
21
|
-
desc '--version, -v', 'print the version'
|
22
|
-
def __print_version
|
23
|
-
puts VERSION
|
24
|
-
end
|
25
|
-
|
26
|
-
method_option :description, type: :string, aliases: '-d', lazy_default: '',
|
27
|
-
desc: 'A short summary of the changes'
|
28
|
-
method_option :list_files, type: :array, aliases: '-l',
|
29
|
-
desc: 'A list of files to add to the rev'
|
30
|
-
method_option :title, type: :string, aliases: '-t', lazy_default: '',
|
31
|
-
desc: 'A title for the rev'
|
32
|
-
desc 'create PATH', 'Make a new rev and populate with documents'
|
33
|
-
long_desc <<-LONGDESC
|
34
|
-
`Initiates a flow for creating a new rev. To bypass the prompts users can use the provided flags.
|
35
|
-
If using git the title, description and files will be retrieved from git via the git repo name, latest commit msg and latest commit file list respectively.
|
36
|
-
|
37
|
-
`revit create ./Bucket/repo` # Create a new rev from the provided path
|
38
|
-
`revit create ./Bucket/repo --title, -t "Test Repo"` # Create a new revo with a title of Test Repo
|
39
|
-
`revit create ./Bucket/repo --description, -d "A test repo."` # Create a new revo with a description of "a test repo"
|
40
|
-
`revit create ./Bucket/repo --list_files, -l ~/Bucket/oneoffs/help.js` # Create a new rev with a list of files, ignoring the current folder
|
41
|
-
LONGDESC
|
42
|
-
def create(path)
|
43
|
-
doc_set = Set.new
|
44
|
-
doc_ids = Set.new
|
45
|
-
paths = path.split
|
46
|
-
paths += options[:list_files] if options[:list_files]
|
47
|
-
rev_id = nil
|
48
|
-
spinner = TTY::Spinner.new('[:spinner] :msg', format: :bouncing_ball)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
spinner.
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
spinner.
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
`rev login
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
spinner.
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
spinner.
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
store[:
|
150
|
-
store[:
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
end
|
1
|
+
# rubocop: disable Metrics/AbcSize, Metrics/MethodLength, Metrics/ClassLength
|
2
|
+
require 'paint'
|
3
|
+
require 'thor'
|
4
|
+
require 'tty-spinner'
|
5
|
+
|
6
|
+
#
|
7
|
+
# An extension of our main module
|
8
|
+
#
|
9
|
+
# @author [brwnrclse]
|
10
|
+
#
|
11
|
+
module Reivt
|
12
|
+
#
|
13
|
+
# Rev's cli
|
14
|
+
#
|
15
|
+
# @author [brwnrclse]
|
16
|
+
#
|
17
|
+
class CLI < Thor
|
18
|
+
namespace :revit
|
19
|
+
|
20
|
+
map %w(--version -v) => :__print_version
|
21
|
+
desc '--version, -v', 'print the version'
|
22
|
+
def __print_version
|
23
|
+
puts VERSION
|
24
|
+
end
|
25
|
+
|
26
|
+
method_option :description, type: :string, aliases: '-d', lazy_default: '',
|
27
|
+
desc: 'A short summary of the changes'
|
28
|
+
method_option :list_files, type: :array, aliases: '-l',
|
29
|
+
desc: 'A list of files to add to the rev'
|
30
|
+
method_option :title, type: :string, aliases: '-t', lazy_default: '',
|
31
|
+
desc: 'A title for the rev'
|
32
|
+
desc 'create PATH', 'Make a new rev and populate with documents'
|
33
|
+
long_desc <<-LONGDESC
|
34
|
+
`Initiates a flow for creating a new rev. To bypass the prompts users can use the provided flags.
|
35
|
+
If using git the title, description and files will be retrieved from git via the git repo name, latest commit msg and latest commit file list respectively.
|
36
|
+
|
37
|
+
`revit create ./Bucket/repo` # Create a new rev from the provided path
|
38
|
+
`revit create ./Bucket/repo --title, -t "Test Repo"` # Create a new revo with a title of Test Repo
|
39
|
+
`revit create ./Bucket/repo --description, -d "A test repo."` # Create a new revo with a description of "a test repo"
|
40
|
+
`revit create ./Bucket/repo --list_files, -l ~/Bucket/oneoffs/help.js` # Create a new rev with a list of files, ignoring the current folder
|
41
|
+
LONGDESC
|
42
|
+
def create(path)
|
43
|
+
doc_set = Set.new
|
44
|
+
doc_ids = Set.new
|
45
|
+
paths = path.split
|
46
|
+
paths += options[:list_files] if options[:list_files]
|
47
|
+
rev_id = nil
|
48
|
+
spinner = TTY::Spinner.new('[:spinner] :msg', format: :bouncing_ball)
|
49
|
+
|
50
|
+
Reivt::Auth.logged_in
|
51
|
+
|
52
|
+
spinner.update(msg: 'Creating a rev...')
|
53
|
+
spinner.run do
|
54
|
+
rev_id = RevAPI.create_rev(options[:title], options[:description])
|
55
|
+
end
|
56
|
+
spinner.success(Paint['rev created', :green])
|
57
|
+
|
58
|
+
paths.each do |x|
|
59
|
+
type = File.exist?(x) ? File.ftype(x) : 'other'
|
60
|
+
|
61
|
+
if type == 'file'
|
62
|
+
spinner.update(msg: "#{Paint['Adding', nil, '#e3b505']} #{x}")
|
63
|
+
spinner.run do
|
64
|
+
doc_set.add(Util.doc_from_path(x))
|
65
|
+
end
|
66
|
+
spinner.success(Paint['document created', :green])
|
67
|
+
elsif type == 'directory'
|
68
|
+
spinner.update(msg: "#{Paint['Adding', nil, '#e3b505']} docs from " \
|
69
|
+
"#{Paint[path, '#2de1fc']}")
|
70
|
+
|
71
|
+
if Dir.entries(x).include?('.git')
|
72
|
+
spinner.run do
|
73
|
+
doc_set.merge(Util.docs_from_repo(x, spinner))
|
74
|
+
end
|
75
|
+
spinner.success(Paint['repo docs created', :green])
|
76
|
+
else
|
77
|
+
spinner.run do
|
78
|
+
doc_set.merge(Util.docs_from_dir(x))
|
79
|
+
end
|
80
|
+
spinner.success(Paint['dir docs created', :green])
|
81
|
+
end
|
82
|
+
else
|
83
|
+
spinner.error("#{Paint['Unsupported file type:']} #{path}")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
spinner.update(msg: 'Uploading docs to rev api')
|
88
|
+
spinner.run do
|
89
|
+
doc_set.each do |doc|
|
90
|
+
doc_id = RevAPI.create_doc(doc.blob, doc.content_type, doc.doc_name,
|
91
|
+
doc.has_diff, rev_id)
|
92
|
+
doc_ids.add(doc_id)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
spinner.success(Paint['docs uploaded to api', :green])
|
96
|
+
|
97
|
+
Reivt::LOGGER.info(
|
98
|
+
"Login at #{Paint['wver.vaemoi.co/home', :green]} to start your rev!"
|
99
|
+
)
|
100
|
+
rescue Errno::ECONNRESET, Errno::EINVAL, EOFError, Net::HTTPBadResponse,
|
101
|
+
Net::HTTPHeaderSyntaxError, Net::OpenTimeout, Net::ProtocolError,
|
102
|
+
Reivt::BaemptyException, Reivt::GraphQLDataException,
|
103
|
+
Reivt::GraphQLValidationException => e
|
104
|
+
|
105
|
+
Reivt::DEVLOGGER.error(e.message)
|
106
|
+
Reivt::LOGGER.error(e.message)
|
107
|
+
|
108
|
+
unless doc_ids.empty?
|
109
|
+
doc_ids.each do |id|
|
110
|
+
RevAPI.delete_doc(id)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
unless rev_id.nil?
|
115
|
+
RevAPI.delete_rev(rev_id) unless rev_id.nil?
|
116
|
+
end
|
117
|
+
Reivt::LOGGER.info('Done!')
|
118
|
+
end
|
119
|
+
|
120
|
+
desc 'login', 'Get an auth token for accessing the rev api'
|
121
|
+
long_desc <<-LONGDESC
|
122
|
+
Sends a request for a valid auth token (jwt) to use for accessing the API.
|
123
|
+
Refresh is handled automatically as along as the user keeps on using rev otherwise it'll expire after about a week.
|
124
|
+
|
125
|
+
`rev login --username brwnrclse`
|
126
|
+
|
127
|
+
`rev login -u brwnrclse`
|
128
|
+
LONGDESC
|
129
|
+
def login
|
130
|
+
Reivt::LOGGER.info('Login here for your token:')
|
131
|
+
Reivt::LOGGER.info(Paint[Auth.auth_code_url, :green])
|
132
|
+
|
133
|
+
auth_code = Thor::Shell::Basic.new.ask("\nEnter your auth code => ")
|
134
|
+
spinner = TTY::Spinner.new('[:spinner] :msg', format: :bouncing_ball)
|
135
|
+
|
136
|
+
spinner.update(msg: 'Logging in')
|
137
|
+
spinner.run do
|
138
|
+
begin
|
139
|
+
auth_token = Auth.auth_token(auth_code)
|
140
|
+
user_id = RevAPI.signin_user(auth_token[:auth0_id])
|
141
|
+
|
142
|
+
if user_id.nil?
|
143
|
+
spinner.update(msg: 'User not found! Creating...')
|
144
|
+
user_id = RevAPI.create_user(auth_token[:auth0_id])
|
145
|
+
spinner.success(Paint['User created', :green])
|
146
|
+
end
|
147
|
+
|
148
|
+
Reivt::REIVT_STORE.transaction do |store|
|
149
|
+
store[:access_token] = auth_token[:access_token].strip
|
150
|
+
store[:expires] = auth_token[:expires]
|
151
|
+
store[:auth0_id] = auth_token[:auth0_id].strip
|
152
|
+
store[:user_id] = user_id
|
153
|
+
end
|
154
|
+
spinner.success(Paint['Login successful :)', :green])
|
155
|
+
rescue Errno::ECONNRESET, Errno::EINVAL, EOFError,
|
156
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
157
|
+
Net::OpenTimeout, Net::ProtocolError,
|
158
|
+
Reivt::GraphQLDataException,
|
159
|
+
Reivt::GraphQLValidationException => e
|
160
|
+
|
161
|
+
Reivt::DEVLOGGER.error(e.message)
|
162
|
+
Reivt::DEVLOGGER.error(e.message)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/lib/reivt/document.rb
CHANGED
@@ -1,67 +1,67 @@
|
|
1
|
-
# An extension of our main module
|
2
|
-
#
|
3
|
-
# @author [brwnrclse]
|
4
|
-
#
|
5
|
-
module Reivt
|
6
|
-
# Blueprint for Document objects
|
7
|
-
#
|
8
|
-
# @author [brwnrclse]
|
9
|
-
#
|
10
|
-
# @!attribute [rw] blob
|
11
|
-
# @return [String] The contents of the file
|
12
|
-
#
|
13
|
-
# @!attribute [rw] content_type
|
14
|
-
# @return [String] The type of content within the file
|
15
|
-
#
|
16
|
-
# @!attribute [rw] doc_name
|
17
|
-
# @return [Array<DocumentClass>] The name of the file
|
18
|
-
#
|
19
|
-
# @!attribute [rw] has_diff
|
20
|
-
# @return [Boolean] Whether or not the file will have a diff
|
21
|
-
#
|
22
|
-
class Document
|
23
|
-
attr_accessor(:blob, :content_type, :doc_name, :name, :has_diff)
|
24
|
-
|
25
|
-
def initialize(blob, content_type, doc_name, has_diff = false)
|
26
|
-
@blob = blob
|
27
|
-
@content_type = content_type
|
28
|
-
@has_diff = has_diff
|
29
|
-
@doc_name = doc_name
|
30
|
-
end
|
31
|
-
|
32
|
-
# Allows Documents objects to be compared using .eql? using their contents
|
33
|
-
# and file name.
|
34
|
-
#
|
35
|
-
# @param other [Rev::Document] The Document to compare to
|
36
|
-
#
|
37
|
-
# @return [Boolean] True if equal
|
38
|
-
# False if not equa
|
39
|
-
#
|
40
|
-
def eql?(other)
|
41
|
-
self == other
|
42
|
-
end
|
43
|
-
|
44
|
-
# Allows Documents objects to be compared using hashes created from a
|
45
|
-
# logical and (&) between the files contents and name.
|
46
|
-
#
|
47
|
-
# @param other [Rev::Document] The Document to compare to
|
48
|
-
#
|
49
|
-
# @return [Fixnum] The & between file content and name
|
50
|
-
#
|
51
|
-
def hash
|
52
|
-
@blob.hash & @doc_name.hash
|
53
|
-
end
|
54
|
-
|
55
|
-
# Allows Documents objects to be compared using == using their contents
|
56
|
-
# and file name.
|
57
|
-
#
|
58
|
-
# @param other [Rev::Document] The Document to compare to
|
59
|
-
#
|
60
|
-
# @return [Boolean] True if equal
|
61
|
-
# False if not equa
|
62
|
-
#
|
63
|
-
def ==(other)
|
64
|
-
@blob == other.blob && @doc_name == other.doc_name
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
1
|
+
# An extension of our main module
|
2
|
+
#
|
3
|
+
# @author [brwnrclse]
|
4
|
+
#
|
5
|
+
module Reivt
|
6
|
+
# Blueprint for Document objects
|
7
|
+
#
|
8
|
+
# @author [brwnrclse]
|
9
|
+
#
|
10
|
+
# @!attribute [rw] blob
|
11
|
+
# @return [String] The contents of the file
|
12
|
+
#
|
13
|
+
# @!attribute [rw] content_type
|
14
|
+
# @return [String] The type of content within the file
|
15
|
+
#
|
16
|
+
# @!attribute [rw] doc_name
|
17
|
+
# @return [Array<DocumentClass>] The name of the file
|
18
|
+
#
|
19
|
+
# @!attribute [rw] has_diff
|
20
|
+
# @return [Boolean] Whether or not the file will have a diff
|
21
|
+
#
|
22
|
+
class Document
|
23
|
+
attr_accessor(:blob, :content_type, :doc_name, :name, :has_diff)
|
24
|
+
|
25
|
+
def initialize(blob, content_type, doc_name, has_diff = false)
|
26
|
+
@blob = blob
|
27
|
+
@content_type = content_type
|
28
|
+
@has_diff = has_diff
|
29
|
+
@doc_name = doc_name
|
30
|
+
end
|
31
|
+
|
32
|
+
# Allows Documents objects to be compared using .eql? using their contents
|
33
|
+
# and file name.
|
34
|
+
#
|
35
|
+
# @param other [Rev::Document] The Document to compare to
|
36
|
+
#
|
37
|
+
# @return [Boolean] True if equal
|
38
|
+
# False if not equa
|
39
|
+
#
|
40
|
+
def eql?(other)
|
41
|
+
self == other
|
42
|
+
end
|
43
|
+
|
44
|
+
# Allows Documents objects to be compared using hashes created from a
|
45
|
+
# logical and (&) between the files contents and name.
|
46
|
+
#
|
47
|
+
# @param other [Rev::Document] The Document to compare to
|
48
|
+
#
|
49
|
+
# @return [Fixnum] The & between file content and name
|
50
|
+
#
|
51
|
+
def hash
|
52
|
+
@blob.hash & @doc_name.hash
|
53
|
+
end
|
54
|
+
|
55
|
+
# Allows Documents objects to be compared using == using their contents
|
56
|
+
# and file name.
|
57
|
+
#
|
58
|
+
# @param other [Rev::Document] The Document to compare to
|
59
|
+
#
|
60
|
+
# @return [Boolean] True if equal
|
61
|
+
# False if not equa
|
62
|
+
#
|
63
|
+
def ==(other)
|
64
|
+
@blob == other.blob && @doc_name == other.doc_name
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/reivt/exception.rb
CHANGED
@@ -1,35 +1,48 @@
|
|
1
|
-
# An extension of our main module
|
2
|
-
#
|
3
|
-
# @author [brwnrclse]
|
4
|
-
#
|
5
|
-
module Reivt
|
6
|
-
# Custom errors for dealing with repos in revit
|
7
|
-
#
|
8
|
-
# @author [bwrnrclse]
|
9
|
-
#
|
10
|
-
class BaemptyException < IOError
|
11
|
-
def initialize(msg = '')
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
#
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
1
|
+
# An extension of our main module
|
2
|
+
#
|
3
|
+
# @author [brwnrclse]
|
4
|
+
#
|
5
|
+
module Reivt
|
6
|
+
# Custom errors for dealing with repos in revit
|
7
|
+
#
|
8
|
+
# @author [bwrnrclse]
|
9
|
+
#
|
10
|
+
class BaemptyException < IOError
|
11
|
+
def initialize(msg = 'Empty File/Repo!')
|
12
|
+
msg << "\n visit this url for more information: https://bitbucket.org/vaemoi/revit/wiki/Exceptions%20-%20Bare%20Repo"
|
13
|
+
super(msg)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Custom errors for dealing with graphql in revit
|
18
|
+
#
|
19
|
+
# @author [bwrnrclse]
|
20
|
+
#
|
21
|
+
class GraphQLDataException < IOError
|
22
|
+
def initialize(msg = 'GraphQL Data Exception')
|
23
|
+
msg << "\n visit this url for more information: https://bitbucket.org/vaemoi/revit/wiki/Exceptions%20-%20GraphQL%20Data%20Issue"
|
24
|
+
super(msg)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Custom errors for dealing with graphql in revit
|
29
|
+
#
|
30
|
+
# @author [bwrnrclse]
|
31
|
+
#
|
32
|
+
class GraphQLValidationException < IOError
|
33
|
+
def initialize(msg = 'GraphQL Validation Exception')
|
34
|
+
msg << "\n visit this url for more information: https://bitbucket.org/vaemoi/revit/wiki/Exceptions%20-%20GraphQL%20Validation%20Error"
|
35
|
+
super(msg)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Custom error for dealing with users who aren't logged in
|
40
|
+
#
|
41
|
+
# @author [firaga]
|
42
|
+
#
|
43
|
+
class LoginException < StandardError
|
44
|
+
def initialize(msg = 'LoginException - run revit login to login.')
|
45
|
+
super(msg)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|