diff --git a/src/api/app/models/gitlab_payload/merge_request.rb b/src/api/app/models/gitlab_payload/merge_request.rb index 73248d80c942..734607cad396 100644 --- a/src/api/app/models/gitlab_payload/merge_request.rb +++ b/src/api/app/models/gitlab_payload/merge_request.rb @@ -8,6 +8,8 @@ def payload target_branch: webhook_payload.dig(:object_attributes, :target_branch), action: webhook_payload.dig(:object_attributes, :action), project_id: webhook_payload.dig(:object_attributes, :source_project_id), - path_with_namespace: webhook_payload.dig(:project, :path_with_namespace)) + path_with_namespace: webhook_payload.dig(:project, :path_with_namespace), + target_repository_full_name: webhook_payload.dig(:project, :path_with_namespace), + source_repository_full_name: webhook_payload.dig(:source, :path_with_namespace)) end end diff --git a/src/api/app/models/gitlab_payload/push.rb b/src/api/app/models/gitlab_payload/push.rb index 34433be84e01..7ea3c25b2aee 100644 --- a/src/api/app/models/gitlab_payload/push.rb +++ b/src/api/app/models/gitlab_payload/push.rb @@ -7,6 +7,10 @@ def payload target_branch: webhook_payload[:ref].sub('refs/heads/', ''), # We need this for Workflows::YAMLDownloader#download_url path_with_namespace: webhook_payload.dig(:project, :path_with_namespace), + # We need this for Workflow::Step#branch_request_content_github + source_repository_full_name: webhook_payload.dig(:project, :path_with_namespace), + # We need this for SCMStatusReporter#call + target_repository_full_name: webhook_payload.dig(:project, :path_with_namespace), # We need this for SCMStatusReporter#call project_id: webhook_payload[:project_id], # We need this for SCMWebhookEventValidator#valid_push_event diff --git a/src/api/app/models/gitlab_payload/tag_push.rb b/src/api/app/models/gitlab_payload/tag_push.rb index 0b51990f187e..4ce8b67a077d 100644 --- a/src/api/app/models/gitlab_payload/tag_push.rb +++ b/src/api/app/models/gitlab_payload/tag_push.rb @@ -9,6 +9,8 @@ def payload target_branch: webhook_payload[:after], # We need this for Workflows::YAMLDownloader#download_url path_with_namespace: webhook_payload.dig(:project, :path_with_namespace), + source_repository_full_name: webhook_payload.dig(:project, :path_with_namespace), + target_repository_full_name: webhook_payload.dig(:project, :path_with_namespace), # We need this for SCMWebhookEventValidator#valid_push_event ref: webhook_payload[:ref], # We need this for Workflow::Step#branch_request_content_{github,gitlab} diff --git a/src/api/app/models/workflow/step.rb b/src/api/app/models/workflow/step.rb index f777a4f90645..2537bbbbf8b9 100644 --- a/src/api/app/models/workflow/step.rb +++ b/src/api/app/models/workflow/step.rb @@ -26,11 +26,7 @@ def target_project_name return nil unless scm_webhook.pull_request_event? - pr_subproject_name = if %w[github gitea].include?(scm_webhook.payload[:scm]) - scm_webhook.payload[:target_repository_full_name]&.tr('/', ':') - else - scm_webhook.payload[:path_with_namespace]&.tr('/', ':') - end + pr_subproject_name = scm_webhook.payload[:target_repository_full_name]&.tr('/', ':') "#{target_project_base_name}:#{pr_subproject_name}:PR-#{scm_webhook.payload[:pr_number]}" end diff --git a/src/api/app/models/workflow/step/branch_package_step.rb b/src/api/app/models/workflow/step/branch_package_step.rb index dcba9ecb2ea4..aa0b1567c0e6 100644 --- a/src/api/app/models/workflow/step/branch_package_step.rb +++ b/src/api/app/models/workflow/step/branch_package_step.rb @@ -105,6 +105,10 @@ def create_target_project project.store end + # FIXME: Just because the tar_scm service accepts different formats for the _branch_request file, we don't need to have code + # to generate those different formats. We can just generate one format, should be the gitlab format because it provides more + # flexibility regarding the URL. + # https://github.com/openSUSE/obs-service-tar_scm/blob/2319f50e741e058ad599a6890ac5c710112d5e48/TarSCM/tasks.py#L145 def branch_request_content case scm_webhook.payload[:scm] when 'github' @@ -118,9 +122,6 @@ def branch_request_content def branch_request_content_github { - # TODO: change to scm_webhook.payload[:action] - # when check_for_branch_request method in obs-service-tar_scm accepts other actions than 'opened' - # https://github.com/openSUSE/obs-service-tar_scm/blob/2319f50e741e058ad599a6890ac5c710112d5e48/TarSCM/tasks.py#L145 action: 'opened', pull_request: { head: { diff --git a/src/api/app/models/workflow/step/set_flags.rb b/src/api/app/models/workflow/step/set_flags.rb index 6a5486979ce0..c4afdf4d121b 100644 --- a/src/api/app/models/workflow/step/set_flags.rb +++ b/src/api/app/models/workflow/step/set_flags.rb @@ -59,11 +59,7 @@ def target_project_name(project_name:) return nil unless scm_webhook.pull_request_event? - pr_subproject_name = if scm_webhook.payload[:scm] == 'github' - scm_webhook.payload[:target_repository_full_name]&.tr('/', ':') - else - scm_webhook.payload[:path_with_namespace]&.tr('/', ':') - end + pr_subproject_name = scm_webhook.payload[:target_repository_full_name]&.tr('/', ':') "#{project_name}:#{pr_subproject_name}:PR-#{scm_webhook.payload[:pr_number]}" end diff --git a/src/api/app/services/workflows/yaml_to_workflows_service.rb b/src/api/app/services/workflows/yaml_to_workflows_service.rb index 76741fd21b9b..b014ce7d762d 100644 --- a/src/api/app/services/workflows/yaml_to_workflows_service.rb +++ b/src/api/app/services/workflows/yaml_to_workflows_service.rb @@ -35,8 +35,7 @@ def create_workflows end def parse_workflow_configuration(workflow_configuration) - target_repository_full_name = @scm_webhook.payload.values_at(:target_repository_full_name, :path_with_namespace).compact.first - scm_organization_name, scm_repository_name = target_repository_full_name.split('/') + scm_organization_name, scm_repository_name = @scm_webhook.payload.fetch(:target_repository_full_name).split('/') # The PR number is only present in webhook events for pull requests, so we have a default value in case someone doesn't use # this correctly. Here, we cannot inform users about this since we're processing the whole workflows file