Class: Octopolo::GitHub::IssueCreator
- Inherits:
-
Object
- Object
- Octopolo::GitHub::IssueCreator
- Includes:
- ConfigWrapper
- Defined in:
- lib/octopolo/github/issue_creator.rb
Direct Known Subclasses
Constant Summary collapse
- MissingAttribute =
Class.new(StandardError)
- NotYetCreated =
Class.new(StandardError)
- CannotCreate =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#data ⇒ Object
Public: The created resource’s details.
-
#number ⇒ Object
Public: The created issue’s number.
-
#options ⇒ Object
Returns the value of attribute options.
-
#repo_name ⇒ Object
for instantiating the issue creator.
Attributes included from ConfigWrapper
Class Method Summary collapse
-
.perform(repo_name, options) ⇒ Object
Public: Create a issue for the given repo with the given options.
Instance Method Summary collapse
-
#body ⇒ Object
Public: The body (primary copy) of the issue.
-
#body_edit_temp_name ⇒ Object
Public: Temporary file for body editing.
-
#body_locals ⇒ Object
Public: The local variables to pass into the template.
- #edit_body(body) ⇒ Object
-
#initialize(repo_name, options) ⇒ IssueCreator
constructor
Public: Create a issue for the given repo with the given options.
-
#jira_ids ⇒ Object
Public: Jira Issue IDs associated with the issue.
-
#jira_url ⇒ Object
Public: Jira Url associated with the issue.
-
#perform ⇒ Object
Public: Create the issue.
-
#pivotal_ids ⇒ Object
Public: The Pivotal Tracker story IDs associated with the issue.
-
#renderer_template ⇒ Object
Public: Rendering template for body property.
-
#title ⇒ Object
Public: Title of the issue.
Constructor Details
#initialize(repo_name, options) ⇒ IssueCreator
Public: Create a issue for the given repo with the given options
repo_name - Full name (“account/repo”) of the repo in question options - Hash of issue information
title: Title of the issue
20 21 22 23 |
# File 'lib/octopolo/github/issue_creator.rb', line 20 def initialize repo_name, self.repo_name = repo_name self. = end |
Instance Attribute Details
#data ⇒ Object
Public: The created resource’s details
53 54 55 |
# File 'lib/octopolo/github/issue_creator.rb', line 53 def data @data end |
#number ⇒ Object
Public: The created issue’s number
12 13 14 |
# File 'lib/octopolo/github/issue_creator.rb', line 12 def number @number end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/octopolo/github/issue_creator.rb', line 10 def @options end |
#repo_name ⇒ Object
for instantiating the issue creator
9 10 11 |
# File 'lib/octopolo/github/issue_creator.rb', line 9 def repo_name @repo_name end |
Class Method Details
.perform(repo_name, options) ⇒ Object
Public: Create a issue for the given repo with the given options
repo_name - Full name (“account/repo”) of the repo in question options - Hash of issue information
title: Title of the issue
Returns the IssueCreator instance
32 33 34 35 36 |
# File 'lib/octopolo/github/issue_creator.rb', line 32 def self.perform repo_name, new(repo_name, ).tap do |creator| creator.perform end end |
Instance Method Details
#body ⇒ Object
Public: The body (primary copy) of the issue
Returns a String
108 109 110 111 112 |
# File 'lib/octopolo/github/issue_creator.rb', line 108 def body output = Renderer.render renderer_template, body_locals output = edit_body(output) if [:editor] output end |
#body_edit_temp_name ⇒ Object
Public: Temporary file for body editing
Returns Name of temporary file
100 101 102 |
# File 'lib/octopolo/github/issue_creator.rb', line 100 def body_edit_temp_name 'octopolo_issue' end |
#body_locals ⇒ Object
Public: The local variables to pass into the template
134 135 136 137 138 139 140 |
# File 'lib/octopolo/github/issue_creator.rb', line 134 def body_locals { pivotal_ids: pivotal_ids, jira_ids: jira_ids, jira_url: jira_url, } end |
#edit_body(body) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/octopolo/github/issue_creator.rb', line 114 def edit_body(body) return body unless ENV['EDITOR'] # Open the file, write the contents, and close it tempfile = Tempfile.new([body_edit_temp_name, '.md']) tempfile.write(body) tempfile.close # Allow the user to edit the file system "#{ENV['EDITOR']} #{tempfile.path}" # Reopen the file, read the contents, and delete it tempfile.open output = tempfile.read tempfile.unlink output end |
#jira_ids ⇒ Object
Public: Jira Issue IDs associated with the issue
Returns an Array of Strings
79 80 81 |
# File 'lib/octopolo/github/issue_creator.rb', line 79 def jira_ids [:jira_ids] || [] end |
#jira_url ⇒ Object
Public: Jira Url associated with the issue
Returns Jira Url
86 87 88 |
# File 'lib/octopolo/github/issue_creator.rb', line 86 def jira_url config.jira_url end |
#perform ⇒ Object
Public: Create the issue
Returns an array with the first element being the issue’s number, the second being a Mash of the response from GitHub’s API
42 43 44 45 46 47 48 49 50 |
# File 'lib/octopolo/github/issue_creator.rb', line 42 def perform # labels option cannot be null due to https://github.com/octokit/octokit.rb/pull/538 result = GitHub.create_issue(repo_name, title, body, labels: []) # capture the information self.number = result.number self.data = result rescue => e raise CannotCreate, e. end |
#pivotal_ids ⇒ Object
Public: The Pivotal Tracker story IDs associated with the issue
Returns an Array of Strings
72 73 74 |
# File 'lib/octopolo/github/issue_creator.rb', line 72 def pivotal_ids [:pivotal_ids] || [] end |
#renderer_template ⇒ Object
Public: Rendering template for body property
Returns Name of template file
93 94 95 |
# File 'lib/octopolo/github/issue_creator.rb', line 93 def renderer_template Renderer::ISSUE_BODY end |
#title ⇒ Object
Public: Title of the issue
Returns a String with the title
65 66 67 |
# File 'lib/octopolo/github/issue_creator.rb', line 65 def title [:title] || raise(MissingAttribute) end |