gitmarshal 1.1.0 → 1.3.0

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: 9d1136a825070f9c33c0a3288175c2d1df3bc56c861a2c4612d1e91728b54eff
4
- data.tar.gz: 27de3ae232d1d9e8694cb3433f3a3f74853a67a1a5b34987ff9995a872e96b53
3
+ metadata.gz: 9bc50deb927f02f10f347bbd1bc95f5d20c072418b802a5092793b2366766e98
4
+ data.tar.gz: '06686a6845fa97a86fd42097ed14e8770c047a65a36c56be3487fc6eb88b0cc7'
5
5
  SHA512:
6
- metadata.gz: d223482bd2ff8d5b20d62bb98402f974073ab02ca98f845df36b0dea27ab5d2c8c863d90d61c450b5d21430e3ff3e906006a117056cf26bfd1aabcec0dbd9cab
7
- data.tar.gz: 967f16553443e6ba49828f2cbabfb8b267784e3b02279540b8c420fc41be227e7eec5d6a79682b798c5990025df8e24c1d0a135b41aebf900bd0a6d7a327ae6f
6
+ metadata.gz: 98df05341cf9c9bdda1bfbf7164ddb08642c2d5d38563c9e9c5edc92e98fce97421d2caae599b396b78c681660313029afeebfac3b96ef003e624871675dd54f
7
+ data.tar.gz: b57340f5c83b753e6d95af988236a5120d199e5912fa7ee07ae666ea9fbaf4e463815b65584c8d38bcc2dc14c529baedff75d6e621b387d7ad71b20c06446cc1
data/README.md CHANGED
@@ -1,9 +1,23 @@
1
- # GitMarshal
2
- [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Maintainability](https://api.codeclimate.com/v1/badges/a9c81f4f449374df1e0c/maintainability)](https://codeclimate.com/github/nagstler/gitmarshal/maintainability) [![CI Build](https://github.com/nagstler/gitmarshal/actions/workflows/gem-push.yml/badge.svg?branch=main)](https://github.com/nagstler/gitmarshal/actions/workflows/gem-push.yml)
1
+ <h1 align="center">
2
+ GitMarshal
3
+ </h1>
3
4
 
5
+ <p align="center">
4
6
  GitMarshal is a command-line interface (CLI) to extract and display various statistics about GitHub repositories. The metrics it retrieves include the number of commits, pull requests, issues, stars, and contributors.
5
-
6
7
  Whether you're a developer interested in the activity of a repository or a manager tracking the progress of your project, GitMarshal provides an easy way to fetch this data directly from your command line.
8
+ </p>
9
+
10
+
11
+ <p align="center">
12
+ <a href="https://badge.fury.io/rb/gitmarshal"><img src="https://badge.fury.io/rb/gitmarshal.svg" alt="Gem Version"></a>
13
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License"></a>
14
+ <a href="https://codeclimate.com/github/nagstler/gitmarshal/maintainability"><img src="https://api.codeclimate.com/v1/badges/a9c81f4f449374df1e0c/maintainability" alt="Maintainability"></a>
15
+ <a href="https://github.com/nagstler/gitmarshal/actions/workflows/gem-push.yml"><img src="https://github.com/nagstler/gitmarshal/actions/workflows/gem-push.yml/badge.svg?branch=main" alt="CI Build"></a>
16
+ </p>
17
+
18
+
19
+
20
+
7
21
 
8
22
  ## :sparkles: Features
9
23
 
@@ -28,22 +42,42 @@ Whether you're a developer interested in the activity of a repository or a manag
28
42
  - [License](#license)
29
43
 
30
44
  ## Prerequisites
45
+ ### 1. Verify Ruby Installation
31
46
 
32
- Before installing GitMarshal, make sure you have Ruby installed in your system. If you're unsure, you can check this by running the following command in your terminal:
47
+ Before installing GitMarshal, ensure Ruby (version 2.5 or later) is installed on your system. Check your Ruby version using:
33
48
 
34
49
  ```bash
35
50
  ruby -v
36
51
  ```
37
52
 
38
- If Ruby is installed, you should see its version. GitMarshal requires Ruby version 2.5 or later.
53
+ ### 2. Install Ruby (If Not Installed)
54
+
55
+ If Ruby is not installed or the version is below 2.5, follow the instructions below to install or upgrade Ruby:
56
+ #### Ubuntu
57
+
58
+ ```bash
59
+ sudo apt-get update
60
+ sudo apt-get install ruby-full
61
+ ```
62
+
63
+ #### MacOS
64
+
65
+ ```bash
66
+ brew install ruby
67
+ ```
68
+
69
+ #### Windows
39
70
 
40
- In addition to Ruby, you will need a GitHub access token to use GitMarshal. Here's how you can generate one:
41
- 1. Visit the following URL: [https://github.com/settings/tokens/new](https://github.com/settings/tokens/new)
42
- 2. Enter a Note (this can be anything, e.g., "For GitMarshal").
43
- 3. Under "Select scopes", check the "repo" option.
44
- 4. Click on "Generate token" at the bottom.
71
+ Follow the instructions on the [Ruby Installer download page](https://rubyinstaller.org/downloads/) .
72
+ ### 3. Generate GitHub Access Token
45
73
 
46
- Remember to save the generated token as you will need it during the configuration step.
74
+ To use GitMarshal, generate a GitHub access token:
75
+ 1. Visit [GitHub Tokens New](https://github.com/settings/tokens/new)
76
+ 2. Enter a Note (e.g., "For GitMarshal").
77
+ 3. Check the "repo" option under "Select scopes".
78
+ 4. Click "Generate token" and save the generated token for configuration.
79
+
80
+ Now, with Ruby installed and a GitHub token generated, you are ready to install and configure GitMarshal.
47
81
 
48
82
  ## Installation
49
83
 
@@ -52,6 +86,7 @@ GitMarshal can be installed directly as a Ruby gem. To do so, simply run the fol
52
86
  ```bash
53
87
  gem install gitmarshal
54
88
  ```
89
+
55
90
  This command will download and install the GitMarshal gem onto your system.
56
91
 
57
92
  ## Configuration
@@ -76,6 +111,8 @@ To fetch and display a summary of all your GitHub repositories, run:
76
111
  gitmarshal
77
112
  ```
78
113
 
114
+ ![list-all](https://github.com/nagstler/gitmarshal/assets/1298480/e9f25862-dca6-42e2-9089-25859fe3fab0)
115
+
79
116
  This will provide you with a comprehensive list of your repositories and will show the number of issues, stars, and forks for each repository.
80
117
 
81
118
  ### Fetch Metrics for a Specific Repository
@@ -86,17 +123,32 @@ To fetch and display overall metrics for a specific repository, use:
86
123
  gitmarshal repo-name
87
124
  ```
88
125
 
126
+ ![repo-metrics](https://github.com/nagstler/gitmarshal/assets/1298480/d30e9a1c-9c63-4d28-824e-4c73a95997a7)
127
+
89
128
  Replace `repo-name` with the name of the repository for which you wish to fetch metrics.
90
129
 
91
- ### Fetch Today's Metrics for a Specific Repository
130
+ ### Available Options
131
+
132
+ #### `-t`
133
+
134
+ Fetch Today's Metrics
135
+
136
+ ```bash
137
+ gitmarshal repo-name -t
138
+ ```
139
+
140
+ ![today](https://github.com/nagstler/gitmarshal/assets/1298480/45b62c48-4c01-46e7-9180-5f6b63046df9)
141
+
142
+
143
+ #### `-ch`
92
144
 
93
- To fetch and display metrics for a specific repository for today only, use:
145
+ Fetch Commit History
94
146
 
95
147
  ```bash
96
- gitmarshal repo-name --today
148
+ gitmarshal repo-name -ch
97
149
  ```
98
150
 
99
- Replace `repo-name` with the name of the repository for which you wish to fetch today's metrics.
151
+ ![ch](https://github.com/nagstler/gitmarshal/assets/1298480/ae690aab-9625-410a-812f-73a736e13949)
100
152
 
101
153
  ### Help Command
102
154
 
data/gitmarshal.gemspec CHANGED
@@ -3,19 +3,19 @@
3
3
  require_relative "lib/gitmarshal/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "gitmarshal"
7
- spec.version = Gitmarshal::VERSION
8
- spec.authors = ["Nagendra Dhanakeerthi"]
9
- spec.email = ["nagendra.dhanakeerthi@gmail.com"]
6
+ spec.name = "gitmarshal"
7
+ spec.version = Gitmarshal::VERSION
8
+ spec.authors = ["Nagendra Dhanakeerthi"]
9
+ spec.email = ["nagendra.dhanakeerthi@gmail.com"]
10
10
 
11
- spec.summary = "Command-line tool for fetching and displaying GitHub repository metrics"
12
- spec.description = <<-DESC
11
+ spec.summary = "Command-line tool for fetching and displaying GitHub repository metrics"
12
+ spec.description = <<-DESC
13
13
  GitMarshal is a command-line tool that allows developers to fetch and display various metrics
14
14
  about GitHub repositories. It provides insights into issues, stargazers, forks, commits,
15
15
  pull requests, and more.
16
16
  DESC
17
- spec.homepage = "https://github.com/nagstler/gitmarshal"
18
- spec.license = "MIT"
17
+ spec.homepage = "https://github.com/nagstler/gitmarshal"
18
+ spec.license = "MIT"
19
19
  spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
20
20
 
21
21
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
@@ -31,14 +31,14 @@ Gem::Specification.new do |spec|
31
31
  spec.add_dependency "json", "~> 2.5"
32
32
  spec.add_dependency "thor", "~> 1.1"
33
33
  spec.add_dependency "terminal-table", "~> 3.0.0"
34
- spec.add_dependency 'colorize', '~> 0.8'
35
- spec.add_dependency 'octokit', '~> 4.0'
36
- spec.add_dependency 'faraday-retry', '~> 2.0'
34
+ spec.add_dependency "colorize", "~> 0.8"
35
+ spec.add_dependency "octokit", "~> 4.0"
36
+ spec.add_dependency "faraday-retry", "~> 2.0"
37
37
 
38
38
  # Development Dependencies
39
39
  spec.add_development_dependency "rspec", "~> 3.10"
40
40
  spec.add_development_dependency "rubocop", "~> 1.22"
41
-
41
+
42
42
  spec.post_install_message = <<-MSG
43
43
 
44
44
  #################################################################
@@ -58,5 +58,4 @@ Enjoy using GitMarshal!
58
58
  #################################################################
59
59
 
60
60
  MSG
61
-
62
61
  end
@@ -1,12 +1,14 @@
1
1
  require "thor"
2
2
  require "terminal-table"
3
3
  require "colorize"
4
+ require "unicode_plot"
4
5
  require_relative "github_fetcher"
5
6
 
6
7
  module GitMarshal
7
8
  class CLI < Thor
8
9
  class_option :help, type: :boolean, aliases: "-h", desc: "Display usage information"
9
10
  class_option :today, type: :boolean, aliases: "-t", desc: 'Display today\'s repository metrics instead of overall metrics'
11
+ class_option :commit_history, type: :boolean, aliases: "-ch", desc: "Display the commit history of the repository"
10
12
 
11
13
  desc "repos", "Prints a summary of the authenticated user's GitHub repositories"
12
14
 
@@ -27,7 +29,7 @@ module GitMarshal
27
29
  ]
28
30
  end
29
31
 
30
- table = Terminal::Table.new :title => "Repositories".colorize(:green).bold,
32
+ table = Terminal::Table.new :title => "Repositories".colorize(:blue).bold,
31
33
  :headings => ["Name", "Issues", "Stargazers", "Forks"].map { |i| i.colorize(:magenta).bold },
32
34
  :rows => rows
33
35
 
@@ -40,20 +42,21 @@ module GitMarshal
40
42
 
41
43
  def help(*)
42
44
  rows = []
43
- rows << ["gitmarshal", "List all repositories of the authenticated user"]
44
- rows << ["gitmarshal repo-name", "Show the overall metrics of the given repository"]
45
- rows << ["gitmarshal repo-name --today", "Show today's metrics of the given repository"]
46
-
45
+ rows << ["gitmarshal", " ", "Display all repositories associated with the authenticated user."]
46
+ rows << ["gitmarshal repo-name", " ", "Display the overall metrics for the specified repository."]
47
+ rows << ["gitmarshal repo-name", "-t", "Display the current day's metrics for the specified repository."]
48
+ rows << ["gitmarshal repo-name", "-ch", "Display the commit history grouped by days for the given repository."]
49
+
47
50
  table = Terminal::Table.new :rows => rows
48
- table.title = "GitMarshal Commands".colorize(:green).bold
49
- table.headings = ['Command', 'Description'].map { |i| i.colorize(:magenta).bold }
51
+ table.title = "GitMarshal Commands".colorize(:blue).bold
52
+ table.headings = ["Command", "Options", "Description"].map { |i| i.colorize(:magenta).bold }
50
53
  table.style = { :border_x => "=", :border_i => "x", :alignment => :left }
51
54
  puts table
52
55
  end
53
56
 
54
57
  private
55
58
 
56
- def metrics(repo_name, today_option = false)
59
+ def metrics(repo_name, today_option = false, commit_history_option = false)
57
60
  fetcher = GithubFetcher.new
58
61
  user = fetcher.fetch_user
59
62
 
@@ -69,6 +72,19 @@ module GitMarshal
69
72
  end
70
73
  # Display today's metrics in a table
71
74
  display_table("Today's Repository Metrics", rows)
75
+ elsif commit_history_option
76
+ commit_history = fetcher.fetch_commit_history(user, repo_name)
77
+
78
+ # Prepare table rows for commit history
79
+ rows = commit_history.map do |date, commit_count|
80
+ [date, commit_count]
81
+ end
82
+
83
+ # Sort rows by date in descending order
84
+ rows.sort_by! { |row| -Date.parse(row.first).to_time.to_i }
85
+
86
+ # Display commit history in a table
87
+ display_commit_history_table(rows)
72
88
  else
73
89
  rows = prepare_table_rows(repo)
74
90
  # Display latest commit
@@ -88,6 +104,21 @@ module GitMarshal
88
104
  text.gsub(/(.{1,#{max_width}})(\s+|\Z)/, "\\1\n")
89
105
  end
90
106
 
107
+ def display_commit_history_table(rows)
108
+ # Limit to last 30 days
109
+ rows = rows.last(30)
110
+
111
+ if rows.size == 0
112
+ puts "No data found for commits in the last 30 days."
113
+ else
114
+ dates = rows.map { |row| row[0] }
115
+ commit_counts = rows.map { |row| row[1] }
116
+
117
+ plot = UnicodePlot.barplot(dates, commit_counts, title: "Commit History")
118
+ puts plot.render
119
+ end
120
+ end
121
+
91
122
  def prepare_table_rows_for_today(repo)
92
123
  [
93
124
  ["Repository Name", repo["name"]],
@@ -133,8 +164,9 @@ module GitMarshal
133
164
 
134
165
  def method_missing(method, *args, &_block)
135
166
  if method =~ /[-a-zA-Z0-9_.]+/
136
- today_option = args.include?("--today")
137
- metrics(method.to_s, today_option)
167
+ today_option = args.include?("-t") ? args.include?("-t") : args.include?("--today")
168
+ commit_history_option = args.include?("-ch") ? args.include?("-ch") : args.include?("--commit-history")
169
+ metrics(method.to_s, today_option, commit_history_option)
138
170
  else
139
171
  super
140
172
  end
@@ -23,6 +23,16 @@ class GithubFetcher
23
23
  end
24
24
  end
25
25
 
26
+ def fetch_commit_history(user, repo_name)
27
+ commit_history = {}
28
+ since_date = (Date.today - 30).to_s
29
+ Octokit.commits_since("#{user}/#{repo_name}", since_date).each do |commit|
30
+ date = commit.commit.committer.date.to_date.to_s
31
+ commit_history[date] = commit_history.fetch(date, 0) + 1
32
+ end
33
+ commit_history
34
+ end
35
+
26
36
  def fetch_today_repo_metrics(user, repo_name)
27
37
  {
28
38
  "name" => repo_name,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitmarshal
4
- VERSION = "1.1.0"
4
+ VERSION = "1.3.0"
5
5
  end
data/lib/gitmarshal.rb CHANGED
@@ -4,6 +4,6 @@ require_relative "gitmarshal/version"
4
4
 
5
5
  module Gitmarshal
6
6
  class Error < StandardError; end
7
-
8
- GITHUB_TOKEN = ENV['GITHUB_TOKEN']
7
+
8
+ GITHUB_TOKEN = ENV["GITHUB_TOKEN"]
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitmarshal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nagendra Dhanakeerthi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-24 00:00:00.000000000 Z
11
+ date: 2023-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json