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.
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
- spinner.update(msg: 'Creating a rev...')
51
- spinner.run do
52
- rev_id = RevAPI.create_rev(options[:title], options[:description])
53
- end
54
- spinner.success(Paint['rev created', :green])
55
-
56
- paths.each do |x|
57
- type = File.exist?(x) ? File.ftype(x) : 'other'
58
-
59
- if type == 'file'
60
- spinner.update(msg: "#{Paint['Adding', nil, '#e3b505']} #{x}")
61
- spinner.run do
62
- doc_set.add(Util.doc_from_path(x))
63
- end
64
- spinner.success(Paint['document created', :green])
65
- elsif type == 'directory'
66
- spinner.update(msg: "#{Paint['Adding', nil, '#e3b505']} docs from " \
67
- "#{Paint[path, '#2de1fc']}")
68
-
69
- if Dir.entries(x).include?('.git')
70
- spinner.run do
71
- doc_set.merge(Util.docs_from_repo(x, spinner))
72
- end
73
- spinner.success(Paint['repo docs created', :green])
74
- else
75
- spinner.run do
76
- doc_set.merge(Util.docs_from_dir(x))
77
- end
78
- spinner.success(Paint['dir docs created', :green])
79
- end
80
- else
81
- spinner.error("#{Paint['Unsupported file type:']} #{path}")
82
- end
83
- end
84
-
85
- spinner.update(msg: 'Uploading docs to rev api')
86
- spinner.run do
87
- doc_set.each do |doc|
88
- doc_id = RevAPI.create_doc(doc.blob, doc.content_type, doc.doc_name,
89
- doc.has_diff, rev_id)
90
- doc_ids.add(doc_id)
91
- end
92
- end
93
- spinner.success(Paint['docs uploaded to api', :green])
94
-
95
- Reivt::LOGGER.info(
96
- "Login at #{Paint['wver.vaemoi.co/home', :green]} to start your rev!"
97
- )
98
- rescue Errno::ECONNRESET, Errno::EINVAL, EOFError, Net::HTTPBadResponse,
99
- Net::HTTPHeaderSyntaxError, Net::OpenTimeout, Net::ProtocolError,
100
- Reivt::BaemptyException, Reivt::GraphQLDataException,
101
- Reivt::GraphQLValidationException => e
102
-
103
- Reivt::DEVLOGGER.error(e.message)
104
- Reivt::LOGGER.error(e.message)
105
-
106
- unless doc_ids.empty?
107
- doc_ids.each do |id|
108
- RevAPI.delete_doc(id)
109
- end
110
- end
111
-
112
- unless rev_id.nil?
113
- RevAPI.delete_rev(rev_id) unless rev_id.nil?
114
- end
115
- Reivt::LOGGER.info('Done!')
116
- end
117
-
118
- desc 'login', 'Get an auth token for accessing the rev api'
119
- long_desc <<-LONGDESC
120
- Sends a request for a valid auth token (jwt) to use for accessing the API.
121
- Refresh is handled automatically as along as the user keeps on using rev otherwise it'll expire after about a week.
122
-
123
- `rev login --username brwnrclse`
124
-
125
- `rev login -u brwnrclse`
126
- LONGDESC
127
- def login
128
- Reivt::LOGGER.info('Login here for your token:')
129
- Reivt::LOGGER.info(Paint[Auth.auth_code_url, :green])
130
-
131
- auth_code = Thor::Shell::Basic.new.ask("\nEnter your auth code => ")
132
- spinner = TTY::Spinner.new('[:spinner] :msg', format: :bouncing_ball)
133
-
134
- spinner.update(msg: 'Logging in')
135
- spinner.run do
136
- begin
137
- auth_token = Auth.auth_token(auth_code)
138
- user_id = RevAPI.signin_user(auth_token[:auth0_id])
139
-
140
- if user_id.nil?
141
- spinner.update(msg: 'User not found! Creating...')
142
- user_id = RevAPI.create_user(auth_token[:auth0_id])
143
- spinner.success(Paint['User created', :green])
144
- end
145
-
146
- Reivt::REIVT_STORE.transaction do |store|
147
- store[:access_token] = auth_token[:access_token].strip
148
- store[:expires] = auth_token[:expires]
149
- store[:auth0_id] = auth_token[:auth0_id].strip
150
- store[:user_id] = user_id
151
- end
152
- spinner.success(Paint['Login successful :)', :green])
153
- rescue Errno::ECONNRESET, Errno::EINVAL, EOFError,
154
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
155
- Net::OpenTimeout, Net::ProtocolError,
156
- Reivt::GraphQLDataException,
157
- Reivt::GraphQLValidationException => e
158
-
159
- Reivt::DEVLOGGER.error(e.message)
160
- Reivt::DEVLOGGER.error(e.message)
161
- end
162
- end
163
- end
164
- end
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
@@ -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
@@ -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
- super(msg)
13
- end
14
- end
15
-
16
- # Custom errors for dealing with graphql in revit
17
- #
18
- # @author [bwrnrclse]
19
- #
20
- class GraphQLDataException < IOError
21
- def initialize(msg = '')
22
- super(msg)
23
- end
24
- end
25
-
26
- # Custom errors for dealing with graphql in revit
27
- #
28
- # @author [bwrnrclse]
29
- #
30
- class GraphQLValidationException < IOError
31
- def initialize(msg = '')
32
- super(msg)
33
- end
34
- end
35
- end
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