Sha256: a6c203fc2e7d40b7bbd9cb87f4455d1fe560ccf5273c5c16204f40225aa64ddc

Contents?: true

Size: 1.6 KB

Versions: 20

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require_relative 'base'

module Gitlab
  module Triage
    module Action
      class Issue < Base
        class Dry < Issue
          def act
            puts "The following issues would be created for the rule **#{policy.name}**:\n\n"

            super
          end

          private

          def perform(resource, issue)
            puts ">>>"
            puts "* Project: #{issue.destination || resource[policy.source_id_sym]}"
            puts "* Title: #{issue.title}"
            puts "* Description: #{issue.description}"
            puts ">>>"
          end
        end

        def act
          policy.resources.each do |resource|
            issue = policy.build_issue(resource)

            perform(resource, issue) if issue.valid?
          end
        end

        private

        def perform(resource, issue)
          network.post_api(build_post_url(resource, issue), post_issue_body(issue))
        end

        def build_post_url(resource, issue)
          # 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: issue.destination || resource[policy.source_id_sym],
            resource_type: 'issues'
          ).build

          puts Gitlab::Triage::UI.debug "post_issue_url: #{post_url}" if network.options.debug

          post_url
        end

        def post_issue_body(issue)
          {
            title: issue.title,
            description: issue.description
          }
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
gitlab-triage-1.44.1 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.44.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.43.2 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.43.1 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.43.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.42.2 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.42.1 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.42.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.41.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.40.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.30.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.29.0 lib/gitlab/triage/action/issue.rb
payping-gitlab-triage-0.1.3 lib/gitlab/triage/action/issue.rb
payping-gitlab-triage-0.1.2 lib/gitlab/triage/action/issue.rb
payping-gitlab-triage-0.1.1 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.28.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.27.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.26.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.25.0 lib/gitlab/triage/action/issue.rb
gitlab-triage-1.24.0 lib/gitlab/triage/action/issue.rb