jira-issues 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 322df4367f03226fb4bfac0fabc66197fc33ab4e
4
- data.tar.gz: 74dfa00b4635f5065c7560f8f06f6cc5c8e5f547
3
+ metadata.gz: 6ac4afdb2cc56f61a1f12717a7d643a5e2d135bc
4
+ data.tar.gz: 88a514d9859c5683232bb6b8f6e5a4ce91f769f8
5
5
  SHA512:
6
- metadata.gz: a0fb3f8fc5fce3b53f438ee4aa6b85fcd9cb8d579938038ca6fa2d9d04835080e96b878bdf1824e7d38d3ff58fe4d374aa4da20856322db2f8ae0d4201a95a53
7
- data.tar.gz: 81375b7242c38eff7c01b2e8ec74ad19d3cb235cbacdaf93601aaaac74c345cf2b9ab397eda5305151d23d635fb85cb976486363b1b8cff4f4893bdc46070e19
6
+ metadata.gz: fffa6c6735e33fbf6eb556c3ece84d739f7a4e3b36a5f221368ec2b5c9ba8891331429df6ed3cacbdf2571fc87420c692e128298745069f06c80a6ee1049cb31
7
+ data.tar.gz: e5cc4dc59f8d13e7bf32c700343ba7f94ac9ebf07c4486feb73ef57a896369dc4d43f8a3ce8323b5ad5c10dee9c7734a37083ac567a2eada28b37694cba9192f
@@ -0,0 +1,7 @@
1
+ require 'jira_issues/jira_adapter'
2
+ require 'jira_issues/jira_workflow'
3
+ require 'jira_issues/jira_query'
4
+ require 'jira_issues/jira_issues_stats'
5
+ require 'jira_issues/jira_issues_navigator'
6
+ require 'jira_issues/jira_issue_mapper'
7
+ require 'jira_issues/jql_lib'
@@ -0,0 +1,32 @@
1
+ require 'jira-ruby'
2
+
3
+ module JiraIssues
4
+ class JiraAdapter
5
+ def create_task(task)
6
+ issue = client.Issue.build
7
+ issue.save(task.print)
8
+ end
9
+
10
+ def available?
11
+ response = client.get('/')
12
+ response.code == '200'
13
+ end
14
+
15
+ def jql(jql_query, fields)
16
+ client.Issue.jql(jql_query, fields)
17
+ end
18
+
19
+ private
20
+
21
+ def client
22
+ @client = JIRA::Client.new(
23
+ username: ENV['JIRA_USERNAME'],
24
+ password: ENV['JIRA_PASSWORD'],
25
+ site: ENV['JIRA_URL'],
26
+ context_path: '',
27
+ auth_type: :basic,
28
+ read_timeout: 120
29
+ )
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ module JiraIssues
2
+ class JiraIssueMapper
3
+ # WIP
4
+ # ATM mapper serialises issue to JSON
5
+ # We might consider using objects
6
+
7
+ def call(issue)
8
+ status = decode_status(issue)
9
+ {
10
+ key: issue.key,
11
+ type: issue.issuetype.name,
12
+ priority: issue.priority.name,
13
+ status: status,
14
+ #description: i.description,
15
+ summary: issue.summary,
16
+ created_date: issue.created,
17
+ closed_date: issue.resolutiondate
18
+ }
19
+ end
20
+
21
+ private
22
+
23
+ def decode_status(issue)
24
+ JiraIssues::JiraWorkflow.issue_status_for_name(project_key(issue),issue.status.name)
25
+ end
26
+
27
+ def project_key(issue)
28
+ issue.key.split('-').first
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,50 @@
1
+ module JiraIssues
2
+ class JiraIssuesNavigator
3
+ include JiraIssues::JiraIssueStats
4
+
5
+ def initialize(issues)
6
+ @issues = issues
7
+ end
8
+
9
+ def issues
10
+ @issues
11
+ end
12
+
13
+ def all
14
+ JiraIssuesNavigator.new @issues
15
+ end
16
+
17
+ def open
18
+ JiraIssuesNavigator.new @issues.select {|i| i[:status] == JiraWorkflow::OPEN}
19
+ end
20
+
21
+ def blocked
22
+ JiraIssuesNavigator.new @issues.select {|i| i[:status] == JiraWorkflow::BLOCKED}
23
+ end
24
+
25
+ def in_progress
26
+ JiraIssuesNavigator.new @issues.select {|i| i[:status] == JiraWorkflow::IN_PROGRESS}
27
+ end
28
+
29
+ def closed
30
+ JiraIssuesNavigator.new @issues.select {|i| i[:status] == JiraWorkflow::CLOSED}
31
+ end
32
+
33
+ def with_status(status: selected_status)
34
+ JiraIssuesNavigator.new @issues.select {|i| i[:status] == @issue_states[selected_status]}
35
+ end
36
+
37
+ #aliases
38
+ def todo
39
+ open
40
+ end
41
+
42
+ def done
43
+ closed
44
+ end
45
+
46
+ def ip
47
+ in_progress
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,11 @@
1
+ module JiraIssues
2
+ module JiraIssueStats
3
+ def created_by_week
4
+ @issues.map { |i| { key: i[:key], week_created: Date.parse(i[:created_date]).beginning_of_week } }.group_by { |x| x[:week_created] }.map { |k, v| [k, v.count] }.to_h.sort
5
+ end
6
+
7
+ def closed_by_week
8
+ @issues.select { |i| !i[:closed_date].nil? }.map { |i| { key: i[:key], week_closed: Date.parse(i[:closed_date]).beginning_of_week } }.group_by { |x| x[:week_closed]}.map { |k, v| [k, v.count] }.to_h.sort
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ # @author Filip Jakubowski
2
+ module JiraIssues
3
+ class JiraQuery
4
+ # Creates new Query object
5
+ # and sets the maximum number of issues returned by Query
6
+ # @param max_results [Integer] maximum number of issues returned by query
7
+ def initialize(max_results = 1000)
8
+ @query_max_results = max_results
9
+ end
10
+
11
+ # Handles a JQL Request and returns JiraIssueavigator for that query
12
+ # @param query [String]
13
+ # @return [JiraIssueNavigator] with those requests
14
+ def jql_query(query)
15
+ result = adapter.jql(query, fields:[:description, :summary, :created, :status, :issuetype, :priority, :resolutiondate], max_results: @query_max_results)
16
+ JiraIssuesNavigator.new(result.map{|i| JiraIssueMapper.new.call(i) })
17
+ end
18
+
19
+ private
20
+ # Provides adapter that connects to JIRA
21
+ # @return [JiraAdapter] with those requests
22
+ def adapter
23
+ @adapter ||= JiraIssues::JiraAdapter.new
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,26 @@
1
+ #@author Filip Jakubowski
2
+ module JiraIssues
3
+ class JiraWorkflow
4
+ OPEN = 'Open'
5
+ IN_PROGRESS = 'InProgress'
6
+ BLOCKED = 'Blocked'
7
+ CLOSED = 'Closed'
8
+ # This is WIP
9
+ # This class should be able to map and unify:
10
+ # - statuses
11
+ # - workflows
12
+ # - transitions
13
+ # ATM - we will work onlu on defailt issue names
14
+
15
+ def self.issue_status_for_name(project_key, status_name)
16
+ {
17
+ 'Backlog' => OPEN,
18
+ 'Open' => OPEN,
19
+ 'Blocked' => BLOCKED,
20
+ 'In Progress' => IN_PROGRESS,
21
+ 'Done' => CLOSED,
22
+ 'Closed' => CLOSED
23
+ }.fetch(status_name)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ module JiraIssues
2
+ class JqlLib
3
+ def self.my_issues
4
+ "assignee = currentUser()"
5
+ end
6
+
7
+ def self.issues_for_user(user)
8
+ "assignee = #{user}"
9
+ end
10
+ end
11
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,11 @@
1
1
  require 'rspec'
2
2
  require 'jira_issues'
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
7
+ require 'simplecov'
8
+ SimpleCov.start
9
+
10
+ require 'codecov'
11
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-issues
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filip Jakubowski-Drzrwiecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-29 00:00:00.000000000 Z
11
+ date: 2017-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jira-ruby
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.4.3
19
+ version: '1.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.4.3
26
+ version: '1.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 12.3.0
33
+ version: '12.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 12.3.0
40
+ version: '12.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.7.0
47
+ version: '3.7'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.7.0
54
+ version: '3.7'
55
55
  description: Jira Issues gem that supports quering and filtering data for external
56
56
  reporting and integrations.
57
57
  email:
@@ -60,6 +60,14 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
+ - lib/jira_issues.rb
64
+ - lib/jira_issues/jira_adapter.rb
65
+ - lib/jira_issues/jira_issue_mapper.rb
66
+ - lib/jira_issues/jira_issues_navigator.rb
67
+ - lib/jira_issues/jira_issues_stats.rb
68
+ - lib/jira_issues/jira_query.rb
69
+ - lib/jira_issues/jira_workflow.rb
70
+ - lib/jira_issues/jql_lib.rb
63
71
  - spec/jira_issues_spec.rb
64
72
  - spec/spec_helper.rb
65
73
  homepage: https://github.com/filipjakubowski