-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next attempt to pull Agents into gems #1366
Changes from all commits
0bd46b5
9c8ec30
f25b308
603f3e7
811f9c2
222f3a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require 'pp' | ||
require 'pp' | ||
HuginnAgent.require! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,33 @@ def load_dotenv | |
) | ||
end | ||
|
||
GEM_NAME = '[A-Za-z0-9\.\-\_]+'.freeze | ||
GEM_OPTIONS = '(.+?)\s*(?:,\s*(.+?)){0,1}'.freeze | ||
GEM_SEPARATOR = '\s*(?:,|\z)'.freeze | ||
GEM_REGULAR_EXPRESSION = /(#{GEM_NAME})(?:\(#{GEM_OPTIONS}\)){0,1}#{GEM_SEPARATOR}/ | ||
|
||
def parse_each_agent_gem(string) | ||
return unless string | ||
string.scan(GEM_REGULAR_EXPRESSION).each do |name, version, args| | ||
if version =~ /\w+:/ | ||
args = "#{version},#{args}" | ||
version = nil | ||
end | ||
yield [name, version, parse_gem_args(args)].compact | ||
end | ||
end | ||
|
||
private | ||
|
||
def parse_gem_args(args) | ||
return nil unless args | ||
options = {} | ||
args.scan(/(\w+):\s*(.+?)#{GEM_SEPARATOR}/).each do |key, value| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should not matter, the |
||
options[key.to_sym] = value | ||
end | ||
options | ||
end | ||
|
||
def sanity_check(env) | ||
return if ENV['CI'] == 'true' || !env.empty? | ||
puts warning | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'rails_helper' | ||
|
||
describe GemfileHelper do | ||
context 'parse_each_agent_gem' do | ||
VALID_STRINGS = [ | ||
['huginn_nlp_agents(~> 0.2.1)', [ | ||
['huginn_nlp_agents', '~> 0.2.1'] | ||
]], | ||
['huginn_nlp_agents(~> 0.2.1, git: http://github.com/dsander/huginn.git, branch: agents_in_gems)', | ||
[['huginn_nlp_agents', '~> 0.2.1', git: 'http://github.com/dsander/huginn.git', branch: 'agents_in_gems']] | ||
], | ||
['huginn_nlp_agents(~> 0.2.1, git: http://github.com/dsander/huginn.git, ref: 2342asdab) , huginn_nlp_agents(~> 0.2.1)', [ | ||
['huginn_nlp_agents', '~> 0.2.1', git: 'http://github.com/dsander/huginn.git', ref: '2342asdab'], | ||
['huginn_nlp_agents', '~> 0.2.1'] | ||
]], | ||
['huginn_nlp_agents(~> 0.2.1, path: /tmp/test)', [ | ||
['huginn_nlp_agents', '~> 0.2.1', path: '/tmp/test'] | ||
]], | ||
['huginn_nlp_agents', [ | ||
['huginn_nlp_agents'] | ||
]], | ||
['huginn_nlp_agents, test(0.1), test2(github: test2/huginn_test)', [ | ||
['huginn_nlp_agents'], | ||
['test', '0.1'], | ||
['test2', github: 'test2/huginn_test'] | ||
]], | ||
['huginn_nlp_agents(git: http://github.com/dsander/huginn.git, ref: 2342asdab)', [ | ||
['huginn_nlp_agents', git: 'http://github.com/dsander/huginn.git', ref: '2342asdab'] | ||
]], | ||
] | ||
|
||
it 'parses valid gem strings correctly' do | ||
VALID_STRINGS.each do |string, outcomes| | ||
GemfileHelper.parse_each_agent_gem(string) do |args| | ||
expect(args).to eq(outcomes.shift) | ||
end | ||
end | ||
end | ||
|
||
it 'does nothing when nil is passed' do | ||
expect { |b| GemfileHelper.parse_each_agent_gem(nil, &b) }.not_to yield_control | ||
end | ||
|
||
it 'does nothing when an empty string is passed' do | ||
expect { |b| GemfileHelper.parse_each_agent_gem('', &b) }.not_to yield_control | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be
\s*(?:,\s*|\z)
in case there are spaces after the comma?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not needed, spaces are not valid in the GEM_NAME expression they will be
.scan
will skip over them and start the next match when any character that is allowed in GEM_NAME is found. In the specs gem are separated with spaces.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay!