diff options
Diffstat (limited to 'lib/jive/issue.rb')
| -rw-r--r-- | lib/jive/issue.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/jive/issue.rb b/lib/jive/issue.rb new file mode 100644 index 0000000..4796a47 --- /dev/null +++ b/lib/jive/issue.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +module Jive + class Issue + class << self + def what_type? + Jive.prompt?( + Jive.root + .join("lib/jive/templates") + .glob("*.md") + .map { |x| x.basename.to_s.gsub(".md", "") } + ) + end + + def create!(name:, type:, repo: Repo.current) + new(repo: repo, name: name, type: type) + end + + def for(type, repo: Repo.current) + dir_for(type, repo: repo).glob("*.md").map do |x| + name = x.basename.to_s.gsub(".md", "") + new(repo: repo, name: name, type: type) + end + end + + def dir_for(type, repo: Repo.current) + Jive.home + .join(repo.uri.host) + .join(repo.nwo) + .join(type) + end + end + + def initialize(name:, type:, repo: Repo.current) + @repo = repo + @type = type + @name = name + end + + def file_name + "#{name.gsub(/[^a-z0-9\-_]+/i, "-").downcase}.md" + end + + def edit(editor: ENV["EDITOR"]) + Jive.shell.execute([editor, issue.to_s]) + end + + private + + attr_reader :repo, :name, :type + + def issue + @issue ||= + begin + dir = self.class.dir_for(type, repo: repo) + Jive.shell.execute([:mkdir, "-p", dir]) + dir.join(file_name).tap do |file| + file.write(template_for(type).read) unless file.exist? + end + end + end + + def template_for(type) + Jive.root.join("lib/jive/templates/#{type}.md") + end + end +end |
