Generate the base resource URL from the resource object
We're generating URL in a lot of different places. We should have a central way to generate URLs.
In lib/gitlab/triage/action/comment.rb
we have:
def build_post_url(resource)
url_builder_opts = {
network_options: network.options,
source: policy.source,
source_id: resource[policy.source_id_sym],
resource_type: policy.type,
resource_id: resource_id(resource),
sub_resource_type: sub_resource_type
}
# POST /(groups|projects)/:id/(epics|issues|merge_requests)/:iid/notes
post_url = UrlBuilders::UrlBuilder.new(url_builder_opts).build
puts Gitlab::Triage::UI.debug "post_url: #{post_url}" if network.options.debug
post_url
end
And this should look something like:
def build_post_url(resource)
# POST /(groups|projects)/:id/(epics|issues|merge_requests)/:iid/notes
post_url = "#{resource.url}/#{sub_resource_type}"
puts Gitlab::Triage::UI.debug "post_url: #{post_url}" if network.options.debug
post_url
end
In lib/gitlab/triage/action/comment_on_summary.rb
we have:
def build_post_url
# POST /projects/:id/issues/:issue_iid/notes
post_url = UrlBuilders::UrlBuilder.new(
network_options: network.options,
source_id: summary['project_id'],
resource_type: policy.type,
resource_id: summary['iid'],
sub_resource_type: sub_resource_type
).build
puts Gitlab::Triage::UI.debug "post_url: #{post_url}" if network.options.debug
post_url
end
And this should look something like:
def build_post_url
# POST /projects/:id/issues/:issue_iid/notes
post_url = "#{resource.url}/#{sub_resource_type}"
puts Gitlab::Triage::UI.debug "post_url: #{post_url}" if network.options.debug
post_url
end
In lib/gitlab/triage/action/summarize.rb
we have:
def post_issue_url
# POST /projects/:id/issues
# https://docs.gitlab.com/ee/api/issues.html#new-issue
post_url = UrlBuilders::UrlBuilder.new(
network_options: network.options,
source_id: destination,
resource_type: 'issues'
).build
puts Gitlab::Triage::UI.debug "post_issue_url: #{post_url}" if network.options.debug
post_url
end
And this should look something like:
def post_issue_url
# POST /projects/:id/issues
# https://docs.gitlab.com/ee/api/issues.html#new-issue
post_url = resource.url # This is probably more tricky as we don't have an actual resource here
puts Gitlab::Triage::UI.debug "post_issue_url: #{post_url}" if network.options.debug
post_url
end
This was inspired from https://gitlab.com/gitlab-org/gitlab-triage/-/merge_requests/207#note_572895190