github_repo_statistics 2.2.19 → 2.2.21

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
  SHA256:
3
- metadata.gz: cd943ea94b333a76e1f0996523684e8fb8120fb9a8843cc616507b0947abba5c
4
- data.tar.gz: 82269628bf2e56aa72145843bd34f0cf70d9bc0084107f8504706a7af087d439
3
+ metadata.gz: 22715ee89ab9a04e544646b19dd848c758661fd16583844d71a11dbe44428b5f
4
+ data.tar.gz: 52f34b4a141f1408f50c1615d55785e28d7a6ce1052d7e18ff714a9d108bc570
5
5
  SHA512:
6
- metadata.gz: 366fb57664251fe8aa708e6e2c1af6cebbab3299d0757a8e6a8bfd242d1e7421343dd3410efe124a88cc95a6060071c6430ca111382632d671c9fa6a4095f0cd
7
- data.tar.gz: e1aec28c13d79b17da825803ea0d11875939d129fc475a004ab4b0e37edc1761bbbcc2f33006cc3b4685a9f82af95db6ae9186ea39505353d7fd6c22ef8afc7f
6
+ metadata.gz: bbc8035a098fc62d186f2c4db8345d334f137f7df0e7d3ef660ae42e506d4930df8f22d1eea36894041b058f49718fb9139cec3ba73d72184e9371696fa2352f
7
+ data.tar.gz: ded920b5c06400ed83b02b5da34a61663398e76214c86c74e7713bd49cd249eb6eb9d7f1446af6127c9e7465520f68e6d1a4257475abbe8cd7ad5be2b555340c
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,7 +178,10 @@ class GithubRepoStatistics
178
178
  end
179
179
 
180
180
  def git_commit_info(file:, start_date:, end_date:)
181
- `git log --pretty=format:"%s" --since="#{start_date}" --until="#{end_date}" --follow -- "#{file}"`
181
+ puts "File: #{file}, Start: #{start_date}, End: #{end_date}, Now: #{Time.now}" if @debug
182
+ res = `git log --pretty=format:"%s" --since="#{start_date}" --until="#{end_date}" --follow -- "#{file}"`
183
+ puts res if @debug
184
+ res
182
185
  end
183
186
 
184
187
  def analyze_changed_files(uniq_code_files_with_changes:, start_date:, end_date:)
@@ -192,6 +195,7 @@ class GithubRepoStatistics
192
195
  filename = File.basename(file)
193
196
  commit_count = git_commit_count(file:, start_date:, end_date:).to_i
194
197
  git_log = git_commit_info(file:, start_date:, end_date:).split("\n")
198
+ puts git_log if @debug
195
199
  teams = git_log.map do |team|
196
200
  team.match(/#{TEAM_REGEX}/)[0].upcase
197
201
  end.reject { |e| EXCLUSIONS&.include?(e) }
@@ -349,9 +353,9 @@ class GithubRepoStatistics
349
353
 
350
354
  return unless @steps.positive?
351
355
 
352
- system("git checkout `git rev-list -1 --before='#{(@begin_time - duration_in_days).strftime('%B %d %Y')}' HEAD`",
356
+ system("git checkout `git rev-list -1 --before='#{(@begin_time - 115).strftime('%B %d %Y')}' HEAD`",
353
357
  %i[out err] => File::NULL)
354
- @begin_time -= duration_in_days
358
+ @begin_time -= 115
355
359
  contribution_message
356
360
  end
357
361
  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.21'
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.21
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