diff --git a/src/main/rb/eca.rb b/src/main/rb/eca.rb index b39e5c5720b1493c3b6e189a82daace639f17e69..f1a45ab4d7508b9ba6262c3df8f8dea4ded1483e 100644 --- a/src/main/rb/eca.rb +++ b/src/main/rb/eca.rb @@ -6,6 +6,7 @@ require 'httparty' require 'multi_json' WIKI_REGEX_MATCH = /.*\.wiki$/ HOST_URL='https://gitlab.eclipse.org' +API_URL='https://api.eclipse.org' # this should be removed as soon as Oniro is onside again ALLOW_LIST_PROJECTS = ['/eclipse/oniro-core/meta-ts', '/eclipse/oniro-core/meta-ledge-sesure', @@ -21,6 +22,7 @@ ALLOW_LIST_PROJECTS = ['/eclipse/oniro-core/meta-ts', '/eclipse/oniro-core/meta-seco-intel', '/eclipse/oniro-core/meta-zephyr' ] +STRICT_MODE_ROOT_GROUPS = ['eclipse-research-labs/'] ## Track whether forked project for error reporting (failing vs non-failing) is_forked_project = false @@ -45,6 +47,11 @@ def process_commit(sha) } end +## Take in a project namespace, and see if it starts with any of the targeted root groups. +def use_strict_mode(project_namespace) + return STRICT_MODE_ROOT_GROUPS.any? { |root_group| project_namespace.start_with?(root_group) } +end + def nil_or_empty(o) return o.nil? || o.empty? end @@ -134,14 +141,16 @@ diff_git_commits.each do |commit| processed_git_data.push(process_commit(commit)) end +is_strict_enforced = use_strict_mode(project_json_data['path_with_namespace']) ## Create the JSON payload json_data = { :repoUrl => project_url, :provider => 'gitlab', - :commits => processed_git_data + :commits => processed_git_data, + :strictMode => is_strict_enforced } ## Generate request (use gsub to scrub any lingering \n constants) -response = HTTParty.post("https://api.eclipse.org/git/eca", :body => MultiJson.dump(json_data).gsub(/(\\n|\\r)/, ''), +response = HTTParty.post("#{API_URL}/git/eca", :body => MultiJson.dump(json_data).gsub(/(\\n|\\r)/, ''), :headers => { 'Content-Type' => 'application/json', 'charset' => 'utf-8' @@ -205,7 +214,7 @@ else puts "More information is available at https://api.eclipse.org/git/eca/status/#{parsed_response['fingerprint']}/ui" end ## after parsing - if (!parsed_response.nil? && parsed_response['trackedProject'] == false) then + if (!parsed_response.nil? && parsed_response['trackedProject'] == false && !is_strict_enforced) then if (contained_warnings_errors) then puts "Errors or warnings were encountered while validating sign-off in current request for non-project repository.\n\nValidation is currently not required for non-project repositories, continuing." end @@ -213,7 +222,7 @@ else end end ## If error, exit as status 1 -if (response.code == 403 && is_forked_project) then +if (response.code == 403 && is_forked_project && !is_strict_enforced) then puts "Errors detected, but commits will be allowed for forked repository. Commit errors reported in this push will block merge into origin repository until resolved." elsif (response.code == 403) then exit 1