github_repo_statistics 2.2.19 → 2.2.20

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
  SHA256:
3
- metadata.gz: cd943ea94b333a76e1f0996523684e8fb8120fb9a8843cc616507b0947abba5c
4
- data.tar.gz: 82269628bf2e56aa72145843bd34f0cf70d9bc0084107f8504706a7af087d439
3
+ metadata.gz: 41a049be21c83dce57e60dc938dff6824d47a007a98a28292667ce56118450bc
4
+ data.tar.gz: a78b853dd82721c83dd10fe17db33f199f084143264c8f0fe991a252b645d7f3
5
5
  SHA512:
6
- metadata.gz: 366fb57664251fe8aa708e6e2c1af6cebbab3299d0757a8e6a8bfd242d1e7421343dd3410efe124a88cc95a6060071c6430ca111382632d671c9fa6a4095f0cd
7
- data.tar.gz: e1aec28c13d79b17da825803ea0d11875939d129fc475a004ab4b0e37edc1761bbbcc2f33006cc3b4685a9f82af95db6ae9186ea39505353d7fd6c22ef8afc7f
6
+ metadata.gz: 7296fd692ec8d1fca369a8b4eef1ef7839b1c5ba6ec1f924d7eca834df8ab01eb590223314669006c9bf00b55e99c35f2d7089bd70900108ab1a0f2c91de22b9
7
+ data.tar.gz: 5066e055e2ba835d681df98e3cf7e988c48c96480541c418e28ff97f6b7bea7a7194e873f6e8dd69da36e20244b8f5b54abdb724f909774edd8f574bf9feb704
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github_repo_statistics (2.2.15)
4
+ github_repo_statistics (2.2.19)
5
5
  date
6
6
  faraday-retry
7
7
  google-cloud-bigquery
@@ -178,6 +178,7 @@ class GithubRepoStatistics
178
178
  end
179
179
 
180
180
  def git_commit_info(file:, start_date:, end_date:)
181
+ puts "File: #{file}, Start: #{start_date}, End: #{end_date}, Now: #{Time.now}" if @debug
181
182
  `git log --pretty=format:"%s" --since="#{start_date}" --until="#{end_date}" --follow -- "#{file}"`
182
183
  end
183
184
 
@@ -192,6 +193,7 @@ class GithubRepoStatistics
192
193
  filename = File.basename(file)
193
194
  commit_count = git_commit_count(file:, start_date:, end_date:).to_i
194
195
  git_log = git_commit_info(file:, start_date:, end_date:).split("\n")
196
+ puts git_log if @debug
195
197
  teams = git_log.map do |team|
196
198
  team.match(/#{TEAM_REGEX}/)[0].upcase
197
199
  end.reject { |e| EXCLUSIONS&.include?(e) }
@@ -349,9 +351,9 @@ class GithubRepoStatistics
349
351
 
350
352
  return unless @steps.positive?
351
353
 
352
- system("git checkout `git rev-list -1 --before='#{(@begin_time - duration_in_days).strftime('%B %d %Y')}' HEAD`",
354
+ system("git checkout `git rev-list -1 --before='#{(@begin_time - 115).strftime('%B %d %Y')}' HEAD`",
353
355
  %i[out err] => File::NULL)
354
- @begin_time -= duration_in_days
356
+ @begin_time -= 115
355
357
  contribution_message
356
358
  end
357
359
  end
@@ -12,16 +12,15 @@ class ReleaseMergeReport
12
12
  def report
13
13
  branch_counts = count_merged_pull_requests_per_branch
14
14
  grouped_branch_counts = group_branch_counts(branch_counts)
15
- require 'pry'
16
- binding.pry
17
-
15
+ # require 'pry'
16
+ # binding.pry
18
17
  # Print the grouped branch counts
19
18
  puts 'Branches with Merged Pull Requests:'
20
19
  grouped_branch_counts.each do |branch, count|
21
20
  puts "#{branch}: #{count}"
22
21
  end
23
22
 
24
- ENV['BQ_CREDENTIALS'] = `cat /Users/serghei.moret/.config/gcloud/application_default_credentials.json`
23
+ # ENV['BQ_CREDENTIALS'] = `cat /Users/serghei.moret/.config/gcloud/application_default_credentials.json`
25
24
 
26
25
  export_to_bigquery(grouped_branch_counts) if ENV['BQ_CREDENTIALS']
27
26
 
@@ -35,7 +34,7 @@ class ReleaseMergeReport
35
34
  client.auto_paginate = true
36
35
 
37
36
  tags = client.tags(@repo)
38
- branch_counts = Hash.new(0)
37
+ branch_info = Hash.new { |hash, key| hash[key] = { count: 0, teams: [], tribes: []} }
39
38
 
40
39
  tags.each do |tag|
41
40
  next if !tag.name.match?(/^(v23|v24)\./) && !tag.name.match?(/^(23|24)\./)
@@ -50,31 +49,46 @@ class ReleaseMergeReport
50
49
  pull_requests = client.pull_requests(@repo, state: 'closed', sort: 'updated', direction: 'desc', base: branch_name)
51
50
  .select { |pr| pr.merged_at }
52
51
 
53
- branch_counts[branch_name] = pull_requests.size
52
+ pull_requests.each do |pr|
53
+ branch_info[branch_name][:count] += 1
54
+
55
+ # Extract team identifiers from the pull request labels
56
+ teams = pr.labels.map { |label| label.name.match(/^squad:\s*(.*)$/i)&.captures }.compact.flatten
57
+ tribes = pr.labels.map { |label| label.name.match(/^tribe:\s*(.*)$/i)&.captures }.compact.flatten
58
+ branch_info[branch_name][:teams].push(teams)
59
+ branch_info[branch_name][:tribes].push(tribes)
60
+ end
61
+ branch_info[branch_name][:count] = 0 if branch_info[branch_name].nil?
54
62
  end
55
63
 
56
- branch_counts
64
+ branch_info
57
65
  end
58
66
 
59
- def group_branch_counts(branch_counts)
60
- patch_counts = Hash.new(0)
61
- hotfix_counts = Hash.new { |hash, key| hash[key] = Hash.new(0) }
67
+ def group_branch_counts(branch_info)
68
+ patch_counts = Hash.new { |hash, key| hash[key] = { count: 0, teams: [], tribes: []} }
69
+ hotfix_counts = Hash.new { |hash, key| hash[key] = { count: 0, teams: [], tribes: []} }
62
70
 
63
- branch_counts.each do |branch, count|
71
+ branch_info.each do |branch, info|
64
72
  major_minor_version, patch_version = branch.match(/^#{@branch_prefix}(\d+\.\d+)(?:\.(\d+))?/)&.captures
65
73
 
66
74
  if patch_version.nil?
67
75
  # Branch is a patch version
68
- patch_counts[major_minor_version] += count
69
- elsif count > 0
76
+ patch_counts[major_minor_version][:count] += info[:count]
77
+ patch_counts[major_minor_version][:teams] += info[:teams]
78
+ patch_counts[major_minor_version][:tribes] += info[:tribes]
79
+
80
+
81
+ elsif info[:count] > 0
70
82
  # Branch is a hotfix version
71
- hotfix_counts[major_minor_version][patch_version] += count
83
+ hotfix_counts[major_minor_version][:count] += info[:count]
84
+ hotfix_counts[major_minor_version][:teams] += info[:teams]
85
+ hotfix_counts[major_minor_version][:tribes] += info[:tribes]
72
86
  end
73
87
  end
74
88
 
75
89
  # Sum up the counts for hotfix versions within the same major and minor version
76
- hotfix_counts.each do |major_minor_version, hotfixes|
77
- hotfix_counts[major_minor_version] = hotfixes.values.sum
90
+ hotfix_counts.each do |major_minor_version, hotfix_info|
91
+ hotfix_counts[major_minor_version][:count] = hotfix_info[:count]
78
92
  end
79
93
 
80
94
  { patch_versions: patch_counts, hotfix_versions: hotfix_counts }
@@ -92,20 +106,55 @@ class ReleaseMergeReport
92
106
 
93
107
  date = DateTime.now
94
108
 
95
- branch_counts.each do |branch, count|
109
+ branch_counts[:patch_versions].each do |branch, count|
110
+ # Construct JSON string for teams
111
+ teams_json = count[:teams].map { |team| "'#{team}'" }.join(',')
112
+ tribes_json = count[:tribes].map { |tribes| "'#{tribes}'" }.join(',')
113
+
114
+ # Construct the SQL query
96
115
  query = <<~SQL
97
- MERGE INTO release_merges AS target
98
- USING (SELECT '#{branch}' AS release, '#{@repo}' AS platform) AS source
99
- ON target.release = source.release AND target.platform = source.platform
100
- WHEN MATCHED THEN
101
- UPDATE SET
102
- target.merge_count = #{count},
103
- target.timestamp = '#{date}'
104
- WHEN NOT MATCHED THEN
105
- INSERT (release, merge_count, platform, timestamp)
106
- VALUES ('#{branch}', #{count}, '#{@repo}', '#{date}');
116
+ MERGE INTO release_merges AS target
117
+ USING (SELECT '#{branch}' AS release, '#{@repo}' AS platform) AS source
118
+ ON target.release = source.release AND target.platform = source.platform
119
+ WHEN MATCHED THEN
120
+ UPDATE SET
121
+ target.merge_count = #{count[:count]},
122
+ target.timestamp = '#{date}',
123
+ target.contributors = ARRAY[#{teams_json}],
124
+ target.contributors_tribe = ARRAY[#{tribes_json}]
125
+ WHEN NOT MATCHED THEN
126
+ INSERT (release, merge_count, platform, timestamp, contributors, contributors_tribe)
127
+ VALUES ('#{branch}', #{count[:count]}, '#{@repo}', '#{date}', ARRAY[#{teams_json}], ARRAY[#{tribes_json}]);
107
128
  SQL
129
+
130
+ # Execute the query
131
+ dataset.query(query)
132
+
133
+ # Update the date
108
134
  date -= 7
135
+ end
136
+
137
+ branch_counts[:hotfix_versions].each do |branch, count|
138
+ # Construct JSON string for teams
139
+ teams_json = count[:teams].map { |team| "'#{team}'" }.join(',')
140
+ tribes_json = count[:tribes].map { |tribes| "'#{tribes}'" }.join(',')
141
+
142
+ # Construct the SQL query
143
+ query = <<~SQL
144
+ MERGE INTO release_merges AS target
145
+ USING (SELECT '#{branch}' AS release, '#{@repo}' AS platform) AS source
146
+ ON target.release = source.release AND target.platform = source.platform
147
+ WHEN MATCHED THEN
148
+ UPDATE SET
149
+ target.hotfix_count = #{count[:count]},
150
+ target.contributors_hotfixes = ARRAY[#{teams_json}],
151
+ target.contributors_hotfixes_tribe = ARRAY[#{tribes_json}]
152
+ WHEN NOT MATCHED THEN
153
+ INSERT (release, hotfix_count, platform, contributors_hotfixes, contributors_hotfixes_tribe )
154
+ VALUES ('#{branch}', #{count[:count]}, '#{@repo}', ARRAY[#{teams_json}], ARRAY[#{tribes_json}]);
155
+ SQL
156
+
157
+ # Execute the query
109
158
  dataset.query(query)
110
159
  end
111
160
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class GithubRepoStatistics
4
- VERSION = '2.2.19'
4
+ VERSION = '2.2.20'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_repo_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.19
4
+ version: 2.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serghei Moret
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-08 00:00:00.000000000 Z
11
+ date: 2024-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: date