diff --git a/jira.rb b/jira.rb index 8be62bf..9fcaa21 100644 --- a/jira.rb +++ b/jira.rb @@ -29,6 +29,23 @@ def self.add_remote_link(issue, label, url) ) end + def self.create_issue(summary:, project:, fields: {}) + options = fields.merge( + 'summary' => summary, + 'project' => { + 'key' => project + }, + 'issuetype' => { + 'id' => '3', + } + ) + + issue = api.Issue.build + issue.save(fields: options) + issue.fetch + issue + end + def self.active_sprints api.Agile.get_sprints(config.board, state: 'active') end @@ -46,6 +63,7 @@ def self.api site: config.site, context_path: '', auth_type: :basic, + ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE, }) end diff --git a/kansync.rb b/kansync.rb index 188e50d..6654474 100755 --- a/kansync.rb +++ b/kansync.rb @@ -133,6 +133,16 @@ def execute FixBz.new(profile: profile_object, bz_id: bz_id, fixed_in: version).run end end + + subcommand 'bz_to_jira', 'Clone BZ issue to Jira' do + option ['-b', '--bz-id'], 'BZ_ID', 'Bugzilla id', required: true + option ['-t', '--title'], 'TITLE', 'Override title text', required: false + + def execute + require_relative 'subcommands/clone_bz_to_jira' + CloneBzToJira.new(profile: profile_object, bz_id: bz_id, project: 'TFMRHCLOUD').run(summary: title) + end + end end end @@ -140,5 +150,3 @@ def execute # TODO need a separate script to help with new iteration setup # TODO scripts may need custom configuration per profile, e.g. email mapping # TODO README with links to APIs, docker image, sql converting trick - -#09-7487410 \ No newline at end of file diff --git a/subcommands/clone_bz_to_jira.rb b/subcommands/clone_bz_to_jira.rb new file mode 100644 index 0000000..b3980de --- /dev/null +++ b/subcommands/clone_bz_to_jira.rb @@ -0,0 +1,20 @@ +require_relative 'link_jira_to_bz' + +class CloneBzToJira + attr_accessor :bz_id, :project, :profile + + def initialize(profile:, bz_id:, project:) + @profile = profile + @bz_id = bz_id + @project = project + end + + def run(summary: nil) + bz = Bugzilla.get_issue(bz_id)['bugs'].first + summary ||= bz['summary'] + + issue = Jira.create_issue(project: project, summary: summary) + + LinkJiraToBz.new(profile: profile, jira_id: issue.key, bz_id: bz_id).run + end +end