Skip to content
Snippets Groups Projects

Double quotes break in commits JSON parsing #27

Merged Martin Lowe requested to merge github/fork/autumnfound/malowe/master/27 into master
1 file
+ 15
5
Compare changes
  • Side-by-side
  • Inline
+ 15
5
@@ -45,11 +45,21 @@ git_commits.each do |commit|
## Get parents separately to post-process string into array format
commit_parents_raw = `git show -s --format='%P' #{commit}`
commit_parents = commit_parents_raw.split(/\s/)
## Process Git data into JSON for each commit found
git_data = `git show -s --format='{"author": {"name":"%an","mail":"%ae"},"committer":{"name":"%cn","mail":"%ce"},"body":"%B","subject":"%s","hash":"%H", "parents":["#{commit_parents.join("\", \"")}"]}' #{commit}`
## Strip new lines as they FUBAR JSON parsers
git_data = git_data.force_encoding("utf-8").gsub(/[\n\r\t]/, ' ')
processed_git_data.push(MultiJson.load(git_data.force_encoding("utf-8")))
git_commit = {
:author => {
:name => `git show -s --format='%an' #{commit}`.force_encoding("utf-8"),
:mail => `git show -s --format='%ae' #{commit}`.force_encoding("utf-8"),
},
:committer => {
:name => `git show -s --format='%cn' #{commit}`.force_encoding("utf-8"),
:mail => `git show -s --format='%ce' #{commit}`.force_encoding("utf-8"),
},
:body => `git show -s --format='%B' #{commit}`.force_encoding("utf-8"),
:subject => `git show -s --format='%s' #{commit}`.force_encoding("utf-8"),
:hash => `git show -s --format='%H' #{commit}`,
:parents => commit_parents
}
processed_git_data.push(git_commit)
end
## Get the project ID from env var, extracting from pattern 'project-###'
Loading