Skip to content

Instantly share code, notes, and snippets.

@stilist
Created March 5, 2018 03:48
Show Gist options
  • Save stilist/a934e6be00beeee317a7aa096a943477 to your computer and use it in GitHub Desktop.
Save stilist/a934e6be00beeee317a7aa096a943477 to your computer and use it in GitHub Desktop.
Extract Subversion log data
require 'fileutils'
require 'json'
# LOG = ARGF.read.freeze
LOG = File.read('log.txt')
COMMIT_PATTERN = /
\A
r(?<revision>\d+)
\s\|\s
(?<author>\w+)
\s\|\s
(?<date>\d{4}-\d{2}-\d{2})\s
(?<time>\d{2}:\d{2}:\d{2})\s
(?<tz>[\-\+]\d{4})
\s.+?
\s\|\s
\d+\slines?\n*
(?<message>.+)?
\Z
/mx
raw_commits = LOG.split(/\-{72}/)
.reject { |commit| commit.strip == '' }
commits = raw_commits.map do |raw_commit|
commit = raw_commit.strip.match(COMMIT_PATTERN)
{
author: commit[:author],
date: "#{commit[:date]}T#{commit[:time]}#{commit[:tz]}",
message: commit[:message],
revision: commit[:revision],
}
end
project = File.basename(FileUtils.pwd)
File.open("#{project}.json", 'w') { |f| f.write(JSON.dump(commits)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment