Class: Copyist::Jira
- Inherits:
-
Object
- Object
- Copyist::Jira
- Defined in:
- lib/copyist/jira.rb
Defined Under Namespace
Classes: IssueTicket
Instance Attribute Summary collapse
-
#basic_auth ⇒ Object
Returns the value of attribute basic_auth.
-
#global_labels ⇒ Object
Returns the value of attribute global_labels.
-
#label_identifire ⇒ Object
Returns the value of attribute label_identifire.
-
#parent_identifire ⇒ Object
Returns the value of attribute parent_identifire.
-
#skip_identifires ⇒ Object
Returns the value of attribute skip_identifires.
-
#template_file_path ⇒ Object
Returns the value of attribute template_file_path.
-
#title_identifire ⇒ Object
Returns the value of attribute title_identifire.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Jira
constructor
A new instance of Jira.
- #run ⇒ Object
- #tickets_from_markdown ⇒ Object
Constructor Details
#initialize(argv) ⇒ Jira
Returns a new instance of Jira.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/copyist/jira.rb', line 10 def initialize(argv) @source_md_file_path = argv env_path = ENV["ENVFILE_PATH"] Dotenv.load(env_path) if env_path && !env_path.empty? if ENV["JIRA_USER_NAME"].empty? || ENV["JIRA_PROJECT_NAME"].empty? raise "set JIRA_USER_NAME and JIRA_PROJECT_NAME to env" end raise "set TITLE_IDENTIFIRE to env" if ENV["TITLE_IDENTIFIRE"].empty? raise "set JIRA_PARENT_PROJECT_IDENTIFIRE to env" if ENV["JIRA_PARENT_PROJECT_IDENTIFIRE"].empty? @parent_identifire = "#{ENV["JIRA_PARENT_PROJECT_IDENTIFIRE"]} " @title_identifire = "#{ENV["TITLE_IDENTIFIRE"]} " @skip_identifires = ENV["SKIP_IDENTIFIRES"]&.size&.nonzero? ? Regexp.new("^#{ENV["SKIP_IDENTIFIRES"].split(",").join(" |")}") : nil @label_identifire = ENV["LABEL_IDENTIFIRE"]&.size&.nonzero? ? "#{ENV["LABEL_IDENTIFIRE"]} " : nil @global_labels = ENV["GLOBAL_LABELS"]&.size&.nonzero? ? ENV["GLOBAL_LABELS"] : nil @template_file_path = ENV["TEMPLATE_FILE_PATH"]&.size&.nonzero? ? ENV["TEMPLATE_FILE_PATH"] : nil @basic_auth = Base64.urlsafe_encode64("#{ENV["JIRA_USER_NAME"]}:#{ENV["JIRA_API_TOKEN"]}") end |
Instance Attribute Details
#basic_auth ⇒ Object
Returns the value of attribute basic_auth.
7 8 9 |
# File 'lib/copyist/jira.rb', line 7 def basic_auth @basic_auth end |
#global_labels ⇒ Object
Returns the value of attribute global_labels.
7 8 9 |
# File 'lib/copyist/jira.rb', line 7 def global_labels @global_labels end |
#label_identifire ⇒ Object
Returns the value of attribute label_identifire.
7 8 9 |
# File 'lib/copyist/jira.rb', line 7 def label_identifire @label_identifire end |
#parent_identifire ⇒ Object
Returns the value of attribute parent_identifire.
7 8 9 |
# File 'lib/copyist/jira.rb', line 7 def parent_identifire @parent_identifire end |
#skip_identifires ⇒ Object
Returns the value of attribute skip_identifires.
7 8 9 |
# File 'lib/copyist/jira.rb', line 7 def skip_identifires @skip_identifires end |
#template_file_path ⇒ Object
Returns the value of attribute template_file_path.
7 8 9 |
# File 'lib/copyist/jira.rb', line 7 def template_file_path @template_file_path end |
#title_identifire ⇒ Object
Returns the value of attribute title_identifire.
7 8 9 |
# File 'lib/copyist/jira.rb', line 7 def title_identifire @title_identifire end |
Instance Method Details
#run ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/copyist/jira.rb', line 34 def run puts "make subtasks to JIRA from markdown" tickets_from_markdown.each do |ticket| response = request_to_jira(ticket) puts response. end puts "process finished" rescue StandardError => e puts ["fatal error.", "-------", e.backtrace, "------"].flatten.join("\n") end |
#tickets_from_markdown ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/copyist/jira.rb', line 47 def tickets_from_markdown tickets = [] get_markdown.each do |line| next if skip_identifires && line.match?(skip_identifires) if line.match?(/^#{title_identifire}/) tickets << IssueTicket.new(line.gsub(/#{title_identifire}|\*|\*\*|`/, ""), [], [], nil) elsif line.match?(/^#{parent_identifire}/) tickets&.last&.parent = line.gsub(/#{parent_identifire}|\*|\*\*|`/, "") elsif label_identifire && line.match?(/^#{label_identifire}/) (tickets&.last&.labels || []) << line.gsub(label_identifire, "").chomp.split(",").map(&:strip) else (tickets&.last&.description || []) << line end end tickets.each { |i| i.description = make_description(i.description) } tickets end |