twigg-pivotal 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f07dcc042abc61c5a3f8750f8b7e20fa112896f7
4
+ data.tar.gz: e0978716cdf21a3c8ad34d47f44a22584a58c4bc
5
+ SHA512:
6
+ metadata.gz: fa28afa37578ed7171c69c9ba4f7c3cd8d1c6d2022396ac2b7614981f1c25568c890d4f2a5675d70bb290ce2f46da7dbe2843d793b8a195806f75596e90085eb
7
+ data.tar.gz: 131bf3ee3e512c6630427babef0805ff9e8b46676f472ea9a5d6286b39f45394cac26a214c9ae68864f189d1c4917b75a99a361c1f151a0dbe5026b6ac014373
@@ -0,0 +1,10 @@
1
+ require 'twigg'
2
+ require 'twigg/command'
3
+
4
+ module Twigg
5
+ autoload :Pivotal, 'twigg-pivotal/pivotal'
6
+
7
+ class Command
8
+ autoload :Pivotal, 'twigg-pivotal/command/pivotal'
9
+ end
10
+ end
@@ -0,0 +1,53 @@
1
+ module Twigg
2
+ class Command
3
+ class Pivotal < Command
4
+ include Util
5
+ SUB_SUBCOMMANDS = ['stats']
6
+
7
+ def initialize(*args)
8
+ super
9
+ @sub_subcommand = @args.shift
10
+ ignore @args
11
+
12
+ unless SUB_SUBCOMMANDS.include?(@sub_subcommand)
13
+ Help.new('pivotal').run!
14
+ end
15
+ end
16
+
17
+ def run
18
+ send @sub_subcommand
19
+ end
20
+
21
+ private
22
+
23
+ # Shows a list of open stories, grouped by status.
24
+ def stats
25
+ groups = ::Twigg::Pivotal::Status.status
26
+
27
+ groups.each do |current_state, stories|
28
+ header = pluralize stories.size,
29
+ "#{current_state} story",
30
+ "#{current_state} stories"
31
+ puts header
32
+
33
+ stories.each do |story|
34
+ print "[#{story.story_type}] #{story.name}"
35
+ if story.owned_by
36
+ puts " [#{story.owned_by['initials']}]"
37
+ else
38
+ puts
39
+ end
40
+ end
41
+
42
+ puts
43
+ end
44
+
45
+ puts '', 'Totals'
46
+ groups.each do |current_state, stories|
47
+ puts number_with_delimiter(stories.size) + " #{current_state}"
48
+ end
49
+ puts
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ module Twigg
2
+ module Pivotal
3
+ autoload :Project, 'twigg-pivotal/pivotal/project'
4
+ autoload :Resource, 'twigg-pivotal/pivotal/resource'
5
+ autoload :Status, 'twigg-pivotal/pivotal/status'
6
+ autoload :Story, 'twigg-pivotal/pivotal/story'
7
+ autoload :VERSION, 'twigg-pivotal/pivotal/version'
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ module Twigg
2
+ module Pivotal
3
+ # Models the project resource in Pivotal Tracker.
4
+ class Project < Resource
5
+ attr_reader :pivotal_id, :name
6
+
7
+ class << self
8
+ # Returns an array of all projects accessible with the configured access
9
+ # token.
10
+ def projects
11
+ results = get 'projects', fields: 'name', paginate: false
12
+ results.map { |project| new(project) }
13
+ end
14
+ end
15
+
16
+ def initialize(json)
17
+ raise ArgumentError unless @pivotal_id = json['id']
18
+ raise ArgumentError unless @name = json['name']
19
+ end
20
+
21
+ # Returns the open stories for this project.
22
+ def stories
23
+ Story.stories(@pivotal_id)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,57 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module Twigg
6
+ module Pivotal
7
+ class Resource
8
+ class << self
9
+ private
10
+ PIVOTAL_BASE = 'https://www.pivotaltracker.com/services/v5'
11
+
12
+ def get(resource, paginate: true, **params)
13
+ results = []
14
+ offset = paginate ? 0 : nil
15
+ params = default_params.merge(params)
16
+ done = false
17
+
18
+ begin
19
+ returned = 0
20
+ url = "#{PIVOTAL_BASE}/#{resource}"
21
+ query = params_to_query(paginate ? params.merge(offset: offset) : params)
22
+ url << "?#{URI.encode query}"
23
+
24
+ response = RestClient.get url, headers
25
+ json = JSON[response]
26
+
27
+ if paginate
28
+ pagination = json['pagination']
29
+ returned = pagination['returned']
30
+ offset += returned
31
+
32
+ if results.size + returned == pagination['total']
33
+ done = true
34
+ end
35
+ end
36
+
37
+ results.concat(json['data'])
38
+ end until returned == 0 || done
39
+
40
+ results
41
+ end
42
+
43
+ def default_params
44
+ { envelope: true }
45
+ end
46
+
47
+ def headers
48
+ { 'X-TrackerToken' => Config.pivotal.token }
49
+ end
50
+
51
+ def params_to_query(params)
52
+ params.map { |key, value| "#{key}=#{value}" }.join('&')
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,17 @@
1
+ module Twigg
2
+ module Pivotal
3
+ # This module provides an overview summary of Pivotal Tracker status.
4
+ #
5
+ # This is the main entry point for external callers, such as the `twigg`
6
+ # command-line app and the Twigg web app.
7
+ module Status
8
+ class << self
9
+ def status
10
+ projects = Project.projects
11
+ stories = projects.flat_map(&:stories)
12
+ stories.group_by(&:current_state)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ module Twigg
2
+ module Pivotal
3
+ # Models the story resource in Pivotal Tracker.
4
+ class Story < Resource
5
+ attr_reader :pivotal_id, :current_state, :story_type, :name, :url,
6
+ :owned_by
7
+
8
+ class << self
9
+ # Returns an array of all open stories for the project identified by
10
+ # `project_id`.
11
+ def stories(project_id)
12
+ raise ArgumentError, "'project_id' is required" unless project_id
13
+
14
+ results = get "projects/#{project_id}/stories",
15
+ filter: 'state:started,finished,delivered,rejected',
16
+ fields: 'current_state,story_type,name,url,owned_by'
17
+
18
+ results.map { |story| new(story) }
19
+ end
20
+ end
21
+
22
+ def initialize(json)
23
+ raise ArgumentError unless @pivotal_id = json['id']
24
+ raise ArgumentError unless @current_state = json['current_state']
25
+ raise ArgumentError unless @story_type = json['story_type']
26
+ raise ArgumentError unless @name = json['name']
27
+ raise ArgumentError unless @url = json['url']
28
+
29
+ # optional (some stories don't have owners)
30
+ @owned_by = json['owned_by']
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ module Twigg
2
+ module Pivotal
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: twigg-pivotal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Causes Engineering
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: twigg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.4
83
+ description: Twigg provides stats for activity in Git repositories. This is the adapter
84
+ that enables Twigg to report on activity occurring inside Pivotal Tracker.
85
+ email:
86
+ - eng@causes.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - lib/twigg-pivotal/command/pivotal.rb
92
+ - lib/twigg-pivotal/pivotal/project.rb
93
+ - lib/twigg-pivotal/pivotal/resource.rb
94
+ - lib/twigg-pivotal/pivotal/status.rb
95
+ - lib/twigg-pivotal/pivotal/story.rb
96
+ - lib/twigg-pivotal/pivotal/version.rb
97
+ - lib/twigg-pivotal/pivotal.rb
98
+ - lib/twigg-pivotal.rb
99
+ homepage: https://github.com/causes/twigg
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: 2.0.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 2.0.3
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: Pivotal integration for Twigg repo statistics tool
123
+ test_files: []