MergeRequestInsight 0.1.0
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 +7 -0
- data/CHANGELOG.md +5 -0
- data/MergeRequestInsight.gemspec +26 -0
- data/README.md +44 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/MergeRequestInsight/version.rb +5 -0
- data/lib/MergeRequestInsight.rb +112 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2943afaf1ac5f88994e8da2645dea44c433937a43f762ad332ed45cce0ea9762
|
4
|
+
data.tar.gz: fc3085faa6aab15eec3209d51c4381b347988c0173bd92c9e92ba29d30c3a805
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 87f4fada0dc69908e08d204437f4e80cdc27099d205755750f7a1150fe9ca343ec73c3820c050d8f972657cb3d70dafef2f76350116432f7d0d29442dbc336ee
|
7
|
+
data.tar.gz: 1e378bb75e2788bd5241b03578d0b4dc8e7ebad6e19a0d15a9a647da7c4107a174acbf20d84ffd569b940b3bafc17be82aab39d4ee4edfae230af77ab50345b1
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative "lib/MergeRequestInsight/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "MergeRequestInsight"
|
5
|
+
spec.version = MergeRequestInsight::VERSION
|
6
|
+
spec.authors = ["gabesx"]
|
7
|
+
spec.email = ["judgement_sanctuary@yahoo.com"]
|
8
|
+
|
9
|
+
spec.summary = "A tool to provide insights into merge requests for better code review management."
|
10
|
+
spec.description = "MergeRequestInsight helps developers and team leads manage code reviews more effectively by providing detailed insights into merge requests, such as code complexity and potential bottlenecks. It integrates seamlessly into existing workflows, making the code review process more efficient and productive."
|
11
|
+
spec.homepage = "https://github.com/gabesx/Merge-Request-Insight"
|
12
|
+
spec.required_ruby_version = ">= 2.5.0"
|
13
|
+
|
14
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/gabesx/Merge-Request-Insight"
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/gabesx/Merge-Request-Insight/blob/master/CHANGELOG.md"
|
18
|
+
|
19
|
+
# Explicitly specify files, excluding .gem files
|
20
|
+
spec.files = Dir.glob("{bin,lib}/**/*", File::FNM_DOTMATCH) + Dir.glob("*.{md,gemspec,yml}")
|
21
|
+
spec.files.reject! { |file| file.end_with?('.gem') || file.include?('.git') || file.include?('tmp') }
|
22
|
+
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# merge-request-insight
|
2
|
+
merge-request-insight is a Ruby gem that provides detailed analytics on GitLab merge requests, including status, authorship, and code changes. It simplifies tracking project contributions and codebase evolution, ideal for developers and project managers aiming for enhanced workflow visibility.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```
|
9
|
+
gem 'merge_request_insight', git: 'https://github.com/gabesx/merge-request-insight.git'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
````bundle install````
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
```gem install merge_request_insight```
|
19
|
+
|
20
|
+
## Configuration
|
21
|
+
Before using MergeRequestInsight, configure it with your GitLab access token and project ID. It's recommended to manage your access token securely, avoiding hard-coding it within your scripts. You can use environment variables or other secure methods to set your token and project ID.
|
22
|
+
|
23
|
+
```
|
24
|
+
# Environment variables for access token and project ID
|
25
|
+
ENV['GITLAB_ACCESS_TOKEN'] = 'your_access_token'
|
26
|
+
ENV['GITLAB_PROJECT_ID'] = 'your_project_id'
|
27
|
+
```
|
28
|
+
|
29
|
+
Usage
|
30
|
+
Here's how to use merge-request-insight to fetch and process merge requests for a specified project:
|
31
|
+
|
32
|
+
```
|
33
|
+
require 'merge_request_insight'
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
Contributions are warmly welcomed and greatly appreciated! Here's how you can contribute:
|
38
|
+
|
39
|
+
1. Fork the repo on GitHub.
|
40
|
+
2. Clone your forked repository to your local machine.
|
41
|
+
3. Create a new feature branch (git checkout -b my-new-feature).
|
42
|
+
4. Make your changes and commit them (git commit -am 'Add some feature').
|
43
|
+
5. Push to the branch (git push origin my-new-feature).
|
44
|
+
6. Create a new Pull Request on GitHub.
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "MergeRequestInsight"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "MergeRequestInsight/version"
|
4
|
+
|
5
|
+
module MergeRequestInsight
|
6
|
+
class Error < StandardError; end
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
require 'httparty'
|
10
|
+
require 'date'
|
11
|
+
|
12
|
+
GITLAB_API_URL = 'https://gitlab.com/api/v4'
|
13
|
+
PROJECT_ID = ENV['GITLAB_PROJECT_ID']
|
14
|
+
ACCESS_TOKEN = ENV['GITLAB_ACCESS_TOKEN']
|
15
|
+
|
16
|
+
def fetch_merge_requests(project_id)
|
17
|
+
headers = { 'PRIVATE-TOKEN': ACCESS_TOKEN }
|
18
|
+
merge_requests = []
|
19
|
+
page = 1
|
20
|
+
|
21
|
+
loop do
|
22
|
+
puts "Fetching merge requests, page: #{page}"
|
23
|
+
response = HTTParty.get("#{GITLAB_API_URL}/projects/#{project_id}/merge_requests",
|
24
|
+
headers: headers,
|
25
|
+
query: { state: 'all', scope: 'all', per_page: 100, page: page })
|
26
|
+
break unless response.success?
|
27
|
+
|
28
|
+
merge_requests.concat(response.parsed_response)
|
29
|
+
break if response.headers['x-next-page'].to_s.empty?
|
30
|
+
|
31
|
+
page += 1
|
32
|
+
end
|
33
|
+
|
34
|
+
merge_requests
|
35
|
+
end
|
36
|
+
|
37
|
+
def fetch_merge_request_changes(project_id, merge_request_iid)
|
38
|
+
headers = { 'PRIVATE-TOKEN': ACCESS_TOKEN }
|
39
|
+
response = HTTParty.get("#{GITLAB_API_URL}/projects/#{project_id}/merge_requests/#{merge_request_iid}/changes",
|
40
|
+
headers: headers)
|
41
|
+
return [] unless response.success?
|
42
|
+
|
43
|
+
changes_response = response.parsed_response
|
44
|
+
file_changes = []
|
45
|
+
total_added = 0
|
46
|
+
total_removed = 0
|
47
|
+
|
48
|
+
# Process each change
|
49
|
+
if changes_response['changes']
|
50
|
+
changes_response['changes'].each do |change|
|
51
|
+
added_lines = change['diff'].scan(/^\+/).count
|
52
|
+
removed_lines = change['diff'].scan(/^-/).count
|
53
|
+
total_added += added_lines
|
54
|
+
total_removed += removed_lines
|
55
|
+
|
56
|
+
file_change = {
|
57
|
+
file_path: change['old_path'],
|
58
|
+
added_lines: added_lines,
|
59
|
+
removed_lines: removed_lines
|
60
|
+
}
|
61
|
+
file_changes << file_change
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
{ file_changes: file_changes, total_added: total_added, total_removed: total_removed }
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_detailed_mr_info(project_id)
|
69
|
+
merge_requests = fetch_merge_requests(project_id)
|
70
|
+
merge_requests.map do |mr|
|
71
|
+
puts "Processing MR IID: #{mr['iid']}"
|
72
|
+
changes_data = fetch_merge_request_changes(project_id, mr['iid'])
|
73
|
+
{
|
74
|
+
author: mr['author']['username'],
|
75
|
+
iid: mr['iid'],
|
76
|
+
start_time: mr['created_at'],
|
77
|
+
state: mr['state'],
|
78
|
+
file_changes: changes_data[:file_changes],
|
79
|
+
total_added: changes_data[:total_added],
|
80
|
+
total_removed: changes_data[:total_removed],
|
81
|
+
merged_time: mr['merged_at'],
|
82
|
+
branch_name: mr['source_branch']
|
83
|
+
}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
begin
|
88
|
+
detailed_info = get_detailed_mr_info(PROJECT_ID)
|
89
|
+
detailed_info.each do |info|
|
90
|
+
puts "Merge Request Information"
|
91
|
+
puts "-------------------------"
|
92
|
+
puts "MR IID: #{info[:iid]}"
|
93
|
+
puts "Branch: #{info[:branch_name]}"
|
94
|
+
puts "Author: #{info[:author]}"
|
95
|
+
puts "Start Time: #{info[:start_time]}"
|
96
|
+
puts "State: #{info[:state]}"
|
97
|
+
puts "Merged Time: #{info[:merged_time]}"
|
98
|
+
puts "\nTotal Added Lines: #{info[:total_added]}"
|
99
|
+
puts "Total Removed Lines: #{info[:total_removed]}"
|
100
|
+
puts "\nFile Changes:"
|
101
|
+
info[:file_changes].each do |change|
|
102
|
+
puts "\tFile: #{change[:file_path]}"
|
103
|
+
puts "\t\t+ Added Lines: #{change[:added_lines]}"
|
104
|
+
puts "\t\t- Removed Lines: #{change[:removed_lines]}"
|
105
|
+
end
|
106
|
+
puts "\n-----------------------------------\n\n"
|
107
|
+
end
|
108
|
+
rescue StandardError => e
|
109
|
+
puts "An error occurred: #{e.message}"
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: MergeRequestInsight
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gabesx
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: MergeRequestInsight helps developers and team leads manage code reviews
|
14
|
+
more effectively by providing detailed insights into merge requests, such as code
|
15
|
+
complexity and potential bottlenecks. It integrates seamlessly into existing workflows,
|
16
|
+
making the code review process more efficient and productive.
|
17
|
+
email:
|
18
|
+
- judgement_sanctuary@yahoo.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- CHANGELOG.md
|
24
|
+
- MergeRequestInsight.gemspec
|
25
|
+
- README.md
|
26
|
+
- bin/console
|
27
|
+
- bin/setup
|
28
|
+
- lib/MergeRequestInsight.rb
|
29
|
+
- lib/MergeRequestInsight/version.rb
|
30
|
+
homepage: https://github.com/gabesx/Merge-Request-Insight
|
31
|
+
licenses: []
|
32
|
+
metadata:
|
33
|
+
allowed_push_host: https://rubygems.org
|
34
|
+
homepage_uri: https://github.com/gabesx/Merge-Request-Insight
|
35
|
+
source_code_uri: https://github.com/gabesx/Merge-Request-Insight
|
36
|
+
changelog_uri: https://github.com/gabesx/Merge-Request-Insight/blob/master/CHANGELOG.md
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.5.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.1.6
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: A tool to provide insights into merge requests for better code review management.
|
56
|
+
test_files: []
|