create_ticket 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4603d519ab737c1403dfb2398ed2d0fc63603817
4
- data.tar.gz: 73690dfb7101b39200b40d1f7c32334075307f7a
3
+ metadata.gz: b0b70a06a98627c5931b90389ac2b5651ffd6a9e
4
+ data.tar.gz: f5b8363d2791be53cce0449130c6ae2169670102
5
5
  SHA512:
6
- metadata.gz: 458f88080e178570ad8a86244158c6d6ee10c4d7c5ab4220449e085bb59434cf61ee92960fde28d3eae1c91a731a68d387f26686e22200d08c22677c918b7d60
7
- data.tar.gz: f45a547fc2d3ca8d49afba27ed4b069aa289f2c5812632711d7d7d30c300a6aa3eb40ab1eec15a4fe6aaf8b92038442bbfe5dcb5138071282e6d8caa0d0b5324
6
+ metadata.gz: e0c2c94c5960be16abc3beb7d2d4fe56f55127547bbb760067e3b9b1cbf26d27f4bb0953c4976c23e77d606f6427e471ed71c677dbced9790b8c1a4e80469b34
7
+ data.tar.gz: a5404444e86549be7a2239eac9bb95e7abd3fe500774351bf68d7da726866f1ca60ab0c668692a409b7f02c701d565d9dce4bb67856f72e8964b660be46f69a2
data/.rubocop.yml CHANGED
@@ -1 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
+
3
+ Metrics/MethodLength:
4
+ Max: 13
5
+
6
+ Style/Documentation:
7
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,24 +1,13 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2017-09-20 16:07:56 -0500 using RuboCop version 0.50.0.
3
+ # on 2017-10-05 11:18:01 -0500 using RuboCop version 0.50.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 2
9
+ # Offense count: 1
10
10
  # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
11
11
  # URISchemes: http, https
12
12
  Metrics/LineLength:
13
- Max: 96
14
-
15
- # Offense count: 1
16
- Style/Documentation:
17
- Enabled: false
18
-
19
- # Offense count: 1
20
- # Configuration parameters: EnforcedStyle, SupportedStyles.
21
- # SupportedStyles: module_function, extend_self
22
- Style/ModuleFunction:
23
- Exclude:
24
- - 'lib/create_ticket.rb'
13
+ Max: 95
data/README.md CHANGED
@@ -27,6 +27,8 @@ Or install it yourself as:
27
27
  export JIRA_ASSIGNEE=`whoami`
28
28
  export JIRA_ISSUE_TYPE=Story
29
29
 
30
+ export JIRA_CUSTOMFIELD_12345="If you have a required custom field, you can set them like this."
31
+
30
32
  create_ticket
31
33
 
32
34
  ## Development
@@ -4,19 +4,41 @@ require 'create_ticket'
4
4
 
5
5
  class CreateTicket
6
6
  class CLI
7
- def conf
8
- {
9
- jira_url: ENV.fetch('JIRA_URL'),
10
- project: ENV.fetch('JIRA_PROJECT'),
11
- jira_token: ENV.fetch('JIRA_TOKEN'),
12
- template_filename: ENV.fetch('TEMPLATE_FILENAME'),
13
- assignee: ENV.fetch('JIRA_ASSIGNEE'),
14
- issue_type: ENV.fetch('JIRA_ISSUE_TYPE')
15
- }
7
+ def jira_url
8
+ ENV.fetch('JIRA_URL')
9
+ end
10
+
11
+ def project
12
+ ENV.fetch('JIRA_PROJECT')
13
+ end
14
+
15
+ def jira_token
16
+ ENV.fetch('JIRA_TOKEN')
17
+ end
18
+
19
+ def template_filename
20
+ ENV.fetch('TEMPLATE_FILENAME')
21
+ end
22
+
23
+ def assignee
24
+ ENV.fetch('JIRA_ASSIGNEE')
25
+ end
26
+
27
+ def issue_type
28
+ ENV.fetch('JIRA_ISSUE_TYPE')
29
+ end
30
+
31
+ def custom_fields
32
+ ENV.select { |k, _| k.start_with? 'JIRA_CUSTOMFIELD' }.to_a
33
+ .map { |k, v| [k.downcase.sub(/^jira_/, ''), v] }.to_h
34
+ end
35
+
36
+ def duedate
37
+ ENV['JIRA_DUEDATE']
16
38
  end
17
39
 
18
40
  def run!
19
- CreateTicket.new(conf).create_ticket!
41
+ CreateTicket.new(self).create_ticket!
20
42
  end
21
43
  end
22
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class CreateTicket
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/create_ticket.rb CHANGED
@@ -7,17 +7,19 @@ require 'json'
7
7
  require 'erb'
8
8
 
9
9
  class CreateTicket
10
- attr_reader :jira_url, :project, :jira_token, :template_filename, :assignee, :issue_type
10
+ extend Forwardable
11
+
12
+ attr_reader :conf
11
13
 
12
14
  def initialize(conf)
13
- @jira_url = conf.fetch(:jira_url)
14
- @project = conf.fetch(:project)
15
- @jira_token = conf.fetch(:jira_token)
16
- @template_filename = conf.fetch(:template_filename)
17
- @assignee = conf.fetch(:assignee)
18
- @issue_type = conf.fetch(:issue_type)
15
+ conf = OpenStruct.new(conf) if conf.is_a? Hash
16
+ @conf = conf
19
17
  end
20
18
 
19
+ def_delegators :conf,
20
+ :jira_url, :project, :jira_token, :template_filename,
21
+ :assignee, :issue_type, :duedate, :custom_fields
22
+
21
23
  def template
22
24
  @template ||= File.open(template_filename).read
23
25
  end
@@ -35,20 +37,32 @@ class CreateTicket
35
37
  req.url '/rest/api/2/issue'
36
38
  req.body = jira_ticket_json
37
39
  end
38
- key = JSON.parse(response.body).fetch('key')
39
- puts "#{jira_url}/browse/#{key}"
40
+ begin
41
+ key = JSON.parse(response.body).fetch('key')
42
+ puts "#{jira_url}/browse/#{key}"
43
+ rescue KeyError, JSON::ParserError
44
+ puts 'Could not create a JIRA ticket.'
45
+ puts 'Response from server:'
46
+ puts response.body
47
+ exit 1
48
+ end
49
+ end
50
+
51
+ def fields
52
+ {
53
+ project: { key: project },
54
+ issuetype: { name: issue_type },
55
+ summary: summary,
56
+ description: description,
57
+ assignee: { name: assignee },
58
+ reporter: { name: assignee },
59
+ duedate: duedate
60
+ }.merge(custom_fields)
40
61
  end
41
62
 
42
63
  def jira_ticket_json
43
64
  {
44
- fields: {
45
- project: { key: project },
46
- issuetype: { name: issue_type },
47
- summary: summary,
48
- description: description,
49
- assignee: { name: assignee },
50
- reporter: { name: assignee }
51
- }
65
+ fields: fields
52
66
  }.to_json
53
67
  end
54
68
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: create_ticket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Marek-Spartz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-29 00:00:00.000000000 Z
11
+ date: 2017-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  version: '0'
154
154
  requirements: []
155
155
  rubyforge_project:
156
- rubygems_version: 2.5.1
156
+ rubygems_version: 2.6.13
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: Create JIRA tickets