diff --git a/src/main/rb/debug.rb b/src/main/rb/debug.rb index fa20b3d06c6bf2038ee8b69e5dbfe0df70bb6d05..8ea4a43d7bd5baeb84a540158a90f9a90c852e94 100644 --- a/src/main/rb/debug.rb +++ b/src/main/rb/debug.rb @@ -35,13 +35,43 @@ stdin_args = stdin_raw.split(/\s+/) previous_head_commit = stdin_args[0] new_head_commit = stdin_args[1] +## Get the project ID from env var, extracting from pattern 'project-###' +project_id = ENV['GL_REPOSITORY'][8..-1] +project_path = ENV['GL_PROJECT_PATH'] +## When pushing group wikis, project_path may be empty +if (project_path.nil?) then + puts "Cannot retrieve project path, likely a group. Skipping validation" + exit 0 +end +## Check if current repo is a project wiki (no project ID and ends in .wiki) +if (project_id.nil? && project_path =~ WIKI_REGEX_MATCH) then + puts "Repository is a project wiki and not bound by ECA, skipping" + exit 0 +end + +## Get data about project from API +project_response = HTTParty.get("http://localhost/api/v4/projects/#{project_id}") +## Format data to be able to easily read and process it +project_json_data = MultiJson.load(project_response.body) +if (project_json_data.nil? || project_json_data.class.name == 'Array') then + puts "Couldn't load project data, assumed non-tracked project and skipping validation." + exit 0 +end +## Get the web URL, checking if project is a fork to get original project URL +if (!project_json_data['forked_from_project'].nil?) then + puts "Non-Eclipse project repository detected: ECA validation will be skipped.\n\nNote that any issues with sign off or committer access will be flagged upon merging into the main project repository." + exit 0 +else + project_url = project_json_data['web_url'] +end + ## 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}` + diff_git_commits_raw = `git rev-list #{previous_head_commit}...#{new_head_commit}` end diff_git_commits = diff_git_commits_raw.split(/\n/) @@ -52,7 +82,7 @@ end ## Create the JSON payload json_data = { - :repoUrl => '', + :repoUrl => project_url, :provider => 'gitlab', :commits => processed_git_data } diff --git a/src/main/rb/eca.rb b/src/main/rb/eca.rb index 4435f1ae8aa1166b280697271e3b7df38ec7f1e7..1d3d20d05612e47802ab9c435f924d3d82fc5574 100644 --- a/src/main/rb/eca.rb +++ b/src/main/rb/eca.rb @@ -50,6 +50,11 @@ new_head_commit = stdin_args[1] ## Get the project ID from env var, extracting from pattern 'project-###' project_id = ENV['GL_REPOSITORY'][8..-1] project_path = ENV['GL_PROJECT_PATH'] +## When pushing group wikis, project_path may be empty +if (project_path.nil?) then + puts "Cannot retrieve project path, likely a group. Skipping validation" + exit 0 +end ## Check if current repo is a project wiki (no project ID and ends in .wiki) if (project_id.nil? && project_path =~ WIKI_REGEX_MATCH) then puts "Repository is a project wiki and not bound by ECA, skipping"