ghamma 0.1.0 → 0.1.1

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: a18af8838cf36204f7921d5342381a90d5af1de2df8e0132a2802774250a63ae
4
- data.tar.gz: 121780f2d92b3047915a97e8d132587ef72ccb42a87a5bde6ade7af2aa85fbb0
3
+ metadata.gz: ad500d312e1ec3068bcebd224b215cc53cefb71c70ec88f765d3dda38c1605fa
4
+ data.tar.gz: 26265dd2d7e18b24d6649d535b2546c42ea41404238e15117f65045621da1f31
5
5
  SHA512:
6
- metadata.gz: 1eebb5729dadc195e2d15d5e117a607228e650f0b20f50b161c037c9bf7b291c0dba50e4934785fc88f6445e9895fc08efc1f126f7993879d7f565cfc7ccf598
7
- data.tar.gz: cc6a75f3542ee2c81f6aa600b1361561867b802b64aa6794417ad122abc959971832de89662bfbeacc95d35b0e66111c2cf26a2f41c4988bd8faabd6ccd2070e
6
+ metadata.gz: c7cd7a72afe17f051550b28fd8b3de74227d38c1ef02e24a62242d355efcff1bf183103188b365201cec19e2506d1a2c3d6cbfb7c3e288e78abd612d08fc1174
7
+ data.tar.gz: 3749db0be1011a9998684e5f9d66a1d990a97233e892581655136b576916e3becee978bc17002b3617b2536401339ba0ed4ce6c0d107e5c5a65035f0f3f997af
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
- - Under development
3
+ ## [0.1.1] - 2023-06-01
4
+
5
+ - Actually make the gem executable
6
+
7
+ ## [0.1.0] - 2023-06-01
8
+
9
+ - Initial gem bundling
data/Gemfile CHANGED
@@ -4,9 +4,3 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in ghamma.gemspec
6
6
  gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "test-unit", "~> 3.0"
11
-
12
- gem "standard", "~> 1.3"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ghamma (0.1.0)
4
+ ghamma (0.1.1)
5
5
  http
6
6
 
7
7
  GEM
@@ -75,12 +75,13 @@ GEM
75
75
 
76
76
  PLATFORMS
77
77
  arm64-darwin-22
78
+ x86_64-linux
78
79
 
79
80
  DEPENDENCIES
80
81
  ghamma!
81
- rake (~> 13.0)
82
- standard (~> 1.3)
83
- test-unit (~> 3.0)
82
+ rake
83
+ standard
84
+ test-unit
84
85
 
85
86
  BUNDLED WITH
86
87
  2.4.12
data/exe/ghamma ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ghamma'
4
+
5
+ Ghamma::Cli.new.print_workflow_duration_metrics
data/lib/ghamma/cli.rb ADDED
@@ -0,0 +1,80 @@
1
+ require "csv"
2
+ require "http"
3
+
4
+ module Ghamma
5
+ class Cli
6
+
7
+ BASE_URL = "https://api.github.com".freeze
8
+ OWNER = ARGV[0].freeze
9
+ REPOSITORY = ARGV[1].freeze
10
+
11
+ def api_url(resource)
12
+ "#{BASE_URL}#{resource}"
13
+ end
14
+
15
+ def get(resource, params = {})
16
+ response = HTTP
17
+ .auth("Bearer #{ENV["GH_TOKEN"]}")
18
+ .get(api_url(resource), params: params)
19
+ .body
20
+ JSON.parse(response)
21
+ end
22
+
23
+ def fetch_workflows
24
+ response = get "/repos/#{OWNER}/#{REPOSITORY}/actions/workflows"
25
+ response["workflows"].map { |json| {id: json["id"], name: json["name"]} }.tap do |workflows|
26
+ puts "Found #{workflows.size} workflows"
27
+ end
28
+ end
29
+
30
+ def fetch_workflows_with_runs
31
+ fetch_workflows.map do |workflow|
32
+ response = get "/repos/#{OWNER}/#{REPOSITORY}/actions/workflows/#{workflow[:id]}/runs",
33
+ {per_page: 100, status: "success", exclude_pull_requests: true, created: ">2023-05-01"}
34
+ puts "Fetched runs for #{workflow[:name]}"
35
+
36
+ next if response["total_count"].zero?
37
+
38
+ {
39
+ id: workflow[:id],
40
+ name: workflow[:name],
41
+ runs: response["workflow_runs"].map { |json| {id: json["id"], date: json["created_at"]} }
42
+ }
43
+ end.compact
44
+ end
45
+
46
+ def fetch_workflow_duration_metrics
47
+ fetch_workflows_with_runs.map do |workflow|
48
+ runs_with_timing = workflow[:runs].map do |workflow_run|
49
+ response = get "/repos/#{OWNER}/#{REPOSITORY}/actions/runs/#{workflow_run[:id]}/timing"
50
+
51
+ {
52
+ duration: response["run_duration_ms"],
53
+ date: workflow_run[:date]
54
+ }
55
+ end
56
+
57
+ puts "Fetched timings for #{workflow[:name]}"
58
+
59
+ {
60
+ name: workflow[:name],
61
+ runs: runs_with_timing
62
+ }
63
+ end
64
+ end
65
+
66
+ def print_workflow_duration_metrics
67
+ fetch_workflow_duration_metrics.each do |workflow_metrics|
68
+ puts workflow_metrics[:name]
69
+ metrics_table = CSV.generate do |csv|
70
+ csv << ["Date", "Duration"]
71
+ workflow_metrics[:runs].each do |metric_datum|
72
+ csv << [metric_datum[:date], metric_datum[:duration]]
73
+ end
74
+ end
75
+ puts metrics_table
76
+ puts
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ghamma
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/ghamma.rb CHANGED
@@ -1,83 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "ghamma/cli"
3
4
  require_relative "ghamma/version"
4
5
 
5
6
  module Ghamma
6
7
  class Error < StandardError; end
7
-
8
- require "csv"
9
- require "http"
10
-
11
- BASE_URL = "https://api.github.com".freeze
12
- OWNER = ARGV[0].freeze
13
- REPOSITORY = ARGV[1].freeze
14
-
15
- def api_url(resource)
16
- "#{BASE_URL}#{resource}"
17
- end
18
-
19
- def get(resource, params = {})
20
- response = HTTP
21
- .auth("Bearer #{ENV["GH_TOKEN"]}")
22
- .get(api_url(resource), params: params)
23
- .body
24
- JSON.parse(response)
25
- end
26
-
27
- def fetch_workflows
28
- response = get "/repos/#{OWNER}/#{REPOSITORY}/actions/workflows"
29
- response["workflows"].map { |json| {id: json["id"], name: json["name"]} }.tap do |workflows|
30
- puts "Found #{workflows.size} workflows"
31
- end
32
- end
33
-
34
- def fetch_workflows_with_runs
35
- fetch_workflows.map do |workflow|
36
- response = get "/repos/#{OWNER}/#{REPOSITORY}/actions/workflows/#{workflow[:id]}/runs",
37
- {per_page: 100, status: "success", exclude_pull_requests: true, created: ">2023-05-01"}
38
- puts "Fetched runs for #{workflow[:name]}"
39
-
40
- next if response["total_count"].zero?
41
-
42
- {
43
- id: workflow[:id],
44
- name: workflow[:name],
45
- runs: response["workflow_runs"].map { |json| {id: json["id"], date: json["created_at"]} }
46
- }
47
- end.compact
48
- end
49
-
50
- def fetch_workflow_duration_metrics
51
- fetch_workflows_with_runs.map do |workflow|
52
- runs_with_timing = workflow[:runs].map do |workflow_run|
53
- response = get "/repos/#{OWNER}/#{REPOSITORY}/actions/runs/#{workflow_run[:id]}/timing"
54
-
55
- {
56
- duration: response["run_duration_ms"],
57
- date: workflow_run[:date]
58
- }
59
- end
60
-
61
- puts "Fetched timings for #{workflow[:name]}"
62
-
63
- {
64
- name: workflow[:name],
65
- runs: runs_with_timing
66
- }
67
- end
68
- end
69
-
70
- metrics = fetch_workflow_duration_metrics
71
-
72
- metrics.each do |workflow_metrics|
73
- puts workflow_metrics[:name]
74
- metrics_table = CSV.generate do |csv|
75
- csv << ["Date", "Duration"]
76
- workflow_metrics[:runs].each do |metric_datum|
77
- csv << [metric_datum[:date], metric_datum[:duration]]
78
- end
79
- end
80
- puts metrics_table
81
- puts
82
- end
83
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghamma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Rowan
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: standard
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,10 +52,25 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description:
42
70
  email:
43
71
  - trowan812@gmail.com
44
- executables: []
72
+ executables:
73
+ - ghamma
45
74
  extensions: []
46
75
  extra_rdoc_files: []
47
76
  files:
@@ -53,7 +82,9 @@ files:
53
82
  - LICENSE.txt
54
83
  - README.md
55
84
  - Rakefile
85
+ - exe/ghamma
56
86
  - lib/ghamma.rb
87
+ - lib/ghamma/cli.rb
57
88
  - lib/ghamma/version.rb
58
89
  - sig/ghamma.rbs
59
90
  homepage: https://github.com/tony-rowan/ghamma