Created
March 5, 2018 03:48
-
-
Save stilist/a934e6be00beeee317a7aa096a943477 to your computer and use it in GitHub Desktop.
Extract Subversion log data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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