stand 1.0.5.pre → 1.0.5.pre2

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: 1581405b5f4259517d6ce01e49419d2ceac48705
4
- data.tar.gz: f73bc828a150e6b6815ace3b68f945ef5c0ba0ce
3
+ metadata.gz: 918e4803f3d7d64990882e29154023325df9f2fe
4
+ data.tar.gz: f9707445e4e0f4b8ea7f03a2416b0506d8be4aee
5
5
  SHA512:
6
- metadata.gz: dda6e68db4d53394729f28f52d3294736b05338231b937643bdef12c1fde548a93921adb6ad93b16d0c3bdad3e3933c41b3e41e10fe506c43e812501ac6051e6
7
- data.tar.gz: dcf060afa8f9d5bf2733c6900afaab74c325e2a007c734b2746e85412c6b2174324d735dfb25e710ab92e04e79a1bcda60a8bc6e5aedda107d03d5d5fc690f82
6
+ metadata.gz: b6ab15680612878db88f41a02bf5fc3f516cc93a26bf726356ffeb4723be9139a42103536d428331f7abf6be87cdbe17af84efbc65aa0d4e8d9dbbfcca3e94c5
7
+ data.tar.gz: a60e52c06f6ecf24ced9c4f05690e1fad6fa41bc30a61755b2cf64d1d1ce6a4212108f3da6ee8ad5e9c55bc11f23f4adc721f68858b2fcab22eb409588ee3624
@@ -2,5 +2,10 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  require 'active_support/core_ext/time'
3
3
  require 'active_support/core_ext/numeric/time'
4
4
 
5
+ module Standup
6
+ BASE_NAME = 'standup'.freeze
7
+ end
8
+
9
+ require 'standup/cache'
5
10
  require 'standup/version'
6
11
  require 'standup/app'
@@ -11,7 +11,7 @@ module Standup
11
11
  DESCRIPTION = 'Fetchs data from gitlab to report what you have done'
12
12
 
13
13
  def initialize
14
- config.config_file_base_name = 'standup'
14
+ config.config_file_base_name = Standup::BASE_NAME
15
15
  config.describes_application app_name: NAME,
16
16
  app_version: Standup::VERSION,
17
17
  app_description: DESCRIPTION
@@ -22,14 +22,15 @@ module Standup
22
22
  config.add_command_line_section('Application Options') do |s|
23
23
  s.on :from, 'From specific day', argument: true
24
24
  s.on :to, 'To specific day', argument: true
25
- s.on :username, 'Username', argument: true
26
25
  end
27
26
  end
28
27
 
29
28
  def run
30
29
  settings = ConfigParser.new(config)
31
30
 
32
- ReportGenerator.new(settings).gitlab_report!
31
+ Standup::Cache.use_cassette("gitlab", re_record_interval: (settings.to_date - settings.from_date) / 10) do
32
+ ReportGenerator.new(settings).gitlab_report!
33
+ end
33
34
  end
34
35
  end
35
36
  end
@@ -0,0 +1,17 @@
1
+ require 'vcr'
2
+
3
+ module Standup
4
+ Cache = VCR
5
+ end
6
+
7
+ Standup::Cache.configure do |c|
8
+ c.cassette_library_dir = "#{File.expand_path('~')}/.#{Standup::BASE_NAME}/cache"
9
+ c.hook_into :webmock
10
+ c.default_cassette_options = {
11
+ re_record_interval: 1.day,
12
+ record: :new_episodes
13
+ }
14
+ c.ignore_request do |request|
15
+ request.method != :get
16
+ end
17
+ end
@@ -17,8 +17,7 @@ module Standup
17
17
  private
18
18
 
19
19
  def validate_config!
20
- fail 'Please provide a --username parameter' unless config[:username]
21
- fail 'Please provide a Gitlab access token in your configuration file' unless config['gitlab_access_token']
20
+ fail "Please provide a Gitlab access token in your configuration file 'gitlab_access_token missing'" unless config['gitlab_access_token']
22
21
  end
23
22
 
24
23
  def help_needed?
@@ -14,57 +14,81 @@ module Standup
14
14
  end
15
15
 
16
16
  def gitlab_report!
17
+ # Get authenticated user
18
+ config[:username] = Gitlab.user.username
19
+
17
20
  projects_query = {
18
- per_page: 10,
21
+ per_page: 20,
19
22
  membership: true,
20
23
  search: config['gitlab_project_search_pattern'],
21
24
  order_by: :last_activity_at,
22
25
  sort: :desc
23
26
  }
24
27
 
25
- mrs_query = {
28
+ created_mrs_query = {
26
29
  per_page: 100,
27
30
  state: :merged,
28
31
  order_by: :updated_at,
29
- sort: :desc
32
+ sort: :desc,
33
+ scope: 'created-by-me'
30
34
  }
35
+ assigned_mrs_query = created_mrs_query.dup
36
+ assigned_mrs_query[:scope] = 'assigned-to-me'
31
37
 
32
- issues_query = {
38
+ assigned_issues_query = {
33
39
  per_page: 100,
34
40
  state: :closed,
35
41
  order_by: :updated_at,
36
- sort: :desc
42
+ sort: :desc,
43
+ scope: 'assigned-to-me'
37
44
  }
38
45
 
39
46
  projects = Gitlab.projects(projects_query)
40
47
 
41
48
  projects.each do |project|
49
+ merged_mrs = []
50
+ closed_issues = []
51
+
52
+ if config[:verbose]
53
+ puts "Scanning project #{project.namespace.name}/#{project.name} (#{project.id})"
54
+ end
55
+
42
56
  begin
43
- merged_mrs = Gitlab.merge_requests(project.id, mrs_query)
44
- rescue Gitlab::Error::Forbidden
57
+ Gitlab.merge_requests(project.id, created_mrs_query).auto_paginate do |mr|
58
+ merged_mrs << mr
59
+ end
60
+ Gitlab.merge_requests(project.id, assigned_mrs_query).auto_paginate do |mr|
61
+ merged_mrs << mr
62
+ end
63
+ rescue Gitlab::Error::Forbidden => e
45
64
  # Don't seem to have acces to some MRs
46
- merged_mrs = []
65
+ if config[:verbose]
66
+ puts "Error while fetching merge requests from project #{project.name} (#{project.id}): #{e.inspect}"
67
+ end
47
68
  end
48
69
 
49
70
  begin
50
- closed_issues = Gitlab.issues(project.id, issues_query)
51
- rescue Gitlab::Error::Forbidden
52
- closed_issues = []
71
+ Gitlab.issues(project.id, assigned_issues_query).auto_paginate do |issue|
72
+ closed_issues << issue
73
+ end
74
+ rescue Gitlab::Error::Forbidden => e
75
+ if @settings.config[:verbose]
76
+ puts "Error while fetching issues from project #{project.name} (#{project.id}): #{e.inspect}"
77
+ end
53
78
  end
54
79
 
55
80
  merged_mrs.each do |mr|
56
- validate_state(project, mr, 'MR')
81
+ validate_result!(project, mr, 'MR')
57
82
  end
58
83
 
59
84
  closed_issues.each do |issue|
60
- validate_state(project, issue, 'ISSUE')
85
+ validate_result!(project, issue, 'ISSUE')
61
86
  end
62
87
  end
63
88
 
64
89
  puts Terminal::Table.new :title => 'DONE', :headings => [ 'PROJECT', 'TYPE', 'ID', 'TITLE' ], :rows => @result['done']
65
90
  puts "\n"
66
91
  puts Terminal::Table.new :title => 'REVIEWED', :headings => [ 'PROJECT', 'TYPE', 'ID', 'TITLE' ], :rows => @result['reviewed']
67
-
68
92
  end
69
93
 
70
94
  private
@@ -81,7 +105,7 @@ module Standup
81
105
  @settings.from_date
82
106
  end
83
107
 
84
- def validate_state(project, event, type='?')
108
+ def validate_result!(project, event, type='?')
85
109
  updated_at = Time.parse(event.updated_at)
86
110
  author = event.author.username
87
111
  assignee = event.assignee && event.assignee.username
@@ -96,7 +120,7 @@ module Standup
96
120
  end
97
121
 
98
122
  def configure_gitlab_client
99
- api_endpoint = config['gitlab_endpoint'] || 'https://gitlab.com/api/v3'.freeze
123
+ api_endpoint = config['gitlab_endpoint'] || 'https://gitlab.com/api/v4'.freeze
100
124
 
101
125
  Gitlab.configure do |c|
102
126
  c.endpoint = api_endpoint
@@ -1,3 +1,3 @@
1
1
  module Standup
2
- VERSION = '1.0.5.pre'
2
+ VERSION = '1.0.5.pre2'
3
3
  end
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency 'activesupport'
24
24
  s.add_dependency 'gitlab'
25
25
  s.add_dependency 'terminal-table'
26
+ s.add_dependency 'vcr', '>= 3.0'
26
27
 
27
28
  s.add_development_dependency 'pry'
28
29
  s.add_development_dependency 'guard'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stand
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5.pre
4
+ version: 1.0.5.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Bonaud
@@ -68,6 +68,20 @@ dependencies:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: vcr
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '3.0'
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '3.0'
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: pry
73
87
  requirement: !ruby/object:Gem::Requirement
@@ -294,6 +308,7 @@ files:
294
308
  - bin/standup
295
309
  - lib/standup.rb
296
310
  - lib/standup/app.rb
311
+ - lib/standup/cache.rb
297
312
  - lib/standup/config_parser.rb
298
313
  - lib/standup/report_generator.rb
299
314
  - lib/standup/version.rb