Skip to content

Commit

Permalink
#567: Define skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 2, 2022
1 parent d39cfaf commit cab193a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .0pdd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ alerts:
suppress:
- on-found-puzzle
- on-lost-puzzle
- on-scope
format:
- title-length=250
tags:
- pdd
1 change: 1 addition & 0 deletions lib/lazylead/os.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class OS
# Please note, that this is not a raw stdout.
# The output will be modified by String#scrub! in order to avoid invalid byte sequence
# in UTF-8 (https://stackoverflow.com/a/24037885/6916890).
# @todo #/DEV Add support of multiline string literals, not just array of commands
def run(*cmd)
return "" if cmd.empty? || cmd.any?(&:nil?)
todo = cmd
Expand Down
28 changes: 28 additions & 0 deletions lib/lazylead/task/svn/touch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def initialize(log = Log.new)
@log = log
end

# @todo #567:DEV Add flag with branch prefixes that could be used for future filtration
# Right now method .locations returns all branches, potentially that won't be needed.
def run(_, postman, opts)
files = opts.slice("files", ",")
commits = touch(files, opts)
Expand All @@ -48,6 +50,8 @@ def run(_, postman, opts)

# Return all svn commits for a particular date range, which are touching
# somehow the critical files within the svn repo.
#
# @todo #567:DEV Add support for search over multiple branches (.locations)
def touch(files, opts)
xpath = files.map { |f| "contains(text(),\"#{f}\")" }.join(" or ")
svn_log(opts).xpath("//logentry[paths/path[#{xpath}]]")
Expand Down Expand Up @@ -91,6 +95,30 @@ def to_struct(hsh)
hsh.transform_values { |v| v.is_a?(Hash) ? to_struct(v) : v }
)
end

# Return for each file all his locations considering branches
# > locations('readme.md')
# branches/0.13.x/readme.md
# trunk/readme.md
#
# @todo #567/DEV Performance: improve the glob pattern to support multiple files.
# Right now in order to find all branches for a particular file we are using glob pattern
# - https://en.wikipedia.org/wiki/Glob_(programming)
# - https://stackoverflow.com/a/70950401/6916890
# - https://globster.xyz
# Right now for each file we initiate a separate search request, thus we need to think
# how to avoid this and send only one search request
def locations(opts)
opts.slice("files", ",").flat_map do |file|
raw = OS.new.run "svn ls --no-auth-cache ",
"--username #{opts.decrypt('svn_user', 'svn_salt')}",
"--password #{opts.decrypt('svn_password', 'svn_salt')}",
"--xml -R --search \"#{file}\" #{opts['svn_url']}"
Nokogiri.XML(raw, nil, "UTF-8")
.xpath("/lists/list/entry/name/text()")
.map { |f| f.to_s.strip }
end
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions test/lazylead/task/svn/touch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,18 @@ class TouchTest < Lazylead::Test
assert_email "[SVN] Important files have been changed!",
["3", "dgroup", "/189.md", "Add description for 189 issue"]
end

test "file location detected in all branches" do
skip "No svn credentials provided" unless env? "svn_touch_user",
"svn_touch_password"
skip "No internet connection to riouxsvn.com" unless ping? "riouxsvn.com"
assert_array %w[branches/0.13.x/readme.md trunk/readme.md],
Task::Svn::Touch.new.locations(
Opts.new("svn_url" => "https://svn.riouxsvn.com/touch4ll",
"svn_user" => ENV["svn_touch_user"],
"svn_password" => ENV["svn_touch_password"],
"files" => "readme.md")
)
end
end
end

0 comments on commit cab193a

Please sign in to comment.