Skip to content
Snippets Groups Projects
Commit 1e17c4e4 authored by Martin Lowe's avatar Martin Lowe :palm_tree:
Browse files

Iss #86 - Add support for enabling strictmode on GL ECA checks

Add ability to define root groups that will be validated against ECA
using strict mode which forces the commits to be validated as if it were
a project
parent d5428cc5
No related branches found
No related tags found
1 merge request!109Iss #86 - Add support for enabling strictmode on GL ECA checks
Pipeline #12728 failed
...@@ -6,6 +6,7 @@ require 'httparty' ...@@ -6,6 +6,7 @@ require 'httparty'
require 'multi_json' require 'multi_json'
WIKI_REGEX_MATCH = /.*\.wiki$/ WIKI_REGEX_MATCH = /.*\.wiki$/
HOST_URL='https://gitlab.eclipse.org' HOST_URL='https://gitlab.eclipse.org'
API_URL='https://api.eclipse.org'
# this should be removed as soon as Oniro is onside again # this should be removed as soon as Oniro is onside again
ALLOW_LIST_PROJECTS = ['/eclipse/oniro-core/meta-ts', ALLOW_LIST_PROJECTS = ['/eclipse/oniro-core/meta-ts',
'/eclipse/oniro-core/meta-ledge-sesure', '/eclipse/oniro-core/meta-ledge-sesure',
...@@ -21,6 +22,7 @@ ALLOW_LIST_PROJECTS = ['/eclipse/oniro-core/meta-ts', ...@@ -21,6 +22,7 @@ ALLOW_LIST_PROJECTS = ['/eclipse/oniro-core/meta-ts',
'/eclipse/oniro-core/meta-seco-intel', '/eclipse/oniro-core/meta-seco-intel',
'/eclipse/oniro-core/meta-zephyr' '/eclipse/oniro-core/meta-zephyr'
] ]
STRICT_MODE_ROOT_GROUPS = ['eclipse-research-labs/']
## Track whether forked project for error reporting (failing vs non-failing) ## Track whether forked project for error reporting (failing vs non-failing)
is_forked_project = false is_forked_project = false
...@@ -45,6 +47,11 @@ def process_commit(sha) ...@@ -45,6 +47,11 @@ def process_commit(sha)
} }
end 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) def nil_or_empty(o)
return o.nil? || o.empty? return o.nil? || o.empty?
end end
...@@ -134,14 +141,16 @@ diff_git_commits.each do |commit| ...@@ -134,14 +141,16 @@ diff_git_commits.each do |commit|
processed_git_data.push(process_commit(commit)) processed_git_data.push(process_commit(commit))
end end
is_strict_enforced = use_strict_mode(project_json_data['path_with_namespace'])
## Create the JSON payload ## Create the JSON payload
json_data = { json_data = {
:repoUrl => project_url, :repoUrl => project_url,
:provider => 'gitlab', :provider => 'gitlab',
:commits => processed_git_data :commits => processed_git_data,
:strictMode => is_strict_enforced
} }
## Generate request (use gsub to scrub any lingering \n constants) ## 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 => { :headers => {
'Content-Type' => 'application/json', 'Content-Type' => 'application/json',
'charset' => 'utf-8' 'charset' => 'utf-8'
...@@ -205,7 +214,7 @@ else ...@@ -205,7 +214,7 @@ else
puts "More information is available at https://api.eclipse.org/git/eca/status/#{parsed_response['fingerprint']}/ui" puts "More information is available at https://api.eclipse.org/git/eca/status/#{parsed_response['fingerprint']}/ui"
end end
## after parsing ## 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 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." 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 end
...@@ -213,7 +222,7 @@ else ...@@ -213,7 +222,7 @@ else
end end
end end
## If error, exit as status 1 ## 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." 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 elsif (response.code == 403) then
exit 1 exit 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment