Skip to content
Snippets Groups Projects

Add hotfix for oniro to replace known bad email

Merged Martin Lowe requested to merge (removed):malowe/master/oniro-hotfix into master
Files
2
+ 59
0
#!/usr/bin/env ruby
# encoding: UTF-8
## Simplified version of eca.rb, made to help debug what is being output by
require 'json'
require 'httparty'
require 'multi_json'
## Process the commit into a hash object that will be posted to the ECA validation service
def process_commit(sha)
commit_parents_raw = `git show -s --format='%P' #{sha}`
commit_parents = commit_parents_raw.split(/\s/)
return {
:author => {
:name => `git show -s --format='%an' #{sha}`.force_encoding("utf-8"),
:mail => `git show -s --format='%ae' #{sha}`.force_encoding("utf-8"),
},
:committer => {
:name => `git show -s --format='%cn' #{sha}`.force_encoding("utf-8"),
:mail => `git show -s --format='%ce' #{sha}`.force_encoding("utf-8"),
},
:body => `git show -s --format='%B' #{sha}`.force_encoding("utf-8"),
:subject => `git show -s --format='%s' #{sha}`.force_encoding("utf-8"),
:hash => `git show -s --format='%H' #{sha}`,
:parents => commit_parents
}
end
## Read in the arguments passed from GitLab and split them to an arg array
stdin_raw = ARGF.read;
stdin_args = stdin_raw.split(/\s+/)
## Set the vars for the commit hashes of current pre-receive event
previous_head_commit = stdin_args[0]
new_head_commit = stdin_args[1]
## Get all new commits for branch, relative to itself for existing branch, relative to tree for new
diff_git_commits_raw = ''
if (previous_head_commit =~ /0+/) then
## This isn't perfect as its relative to fork, but should be huge improvement
diff_git_commits_raw = `git rev-list #{new_head_commit} --not --branches=*`
else
diff_git_commits_raw = `git rev-list #{old_head_commit}...#{new_head_commit}`
end
diff_git_commits = diff_git_commits_raw.split(/\n/)
processed_git_data = []
diff_git_commits.each do |commit|
processed_git_data.push(process_commit(commit))
end
## Create the JSON payload
json_data = {
:repoUrl => '',
:provider => 'gitlab',
:commits => processed_git_data
}
puts MultiJson.dump(json_data).gsub(/(\\n|\\r)/, '')
Loading