forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-repository-stars.template.rb
executable file
·70 lines (50 loc) · 1.48 KB
/
github-repository-stars.template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
# How to use this script?
# It's a template which needs further setup. Duplicate the file,
# remove `.template.` from the filename, set an API token and
# specify your repository.
# Parameters
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Repository Statistics
# @raycast.mode inline
# @raycast.refreshTime 1h
# Optional parameters:
# @raycast.packageName GitHub
# @raycast.icon ⭐️
# Documentation:
# @raycast.description Show statistics of your GitHub repository.
# @raycast.author Thomas Paul Mann
# @raycast.authorURL https://github.com/thomaspaulmann
# Configuration
# Insert a token with access to your repository (https://github.com/settings/tokens)
$api_token = ""
# Slug of the owner and repository
$repository = "raycast/script-commands"
# Main program
require "json"
require "net/http"
require "uri"
if $api_token.empty?
puts "No API token provided"
exit(1)
end
uri = URI("https://api.github.com/repos/#{$repository}")
req = Net::HTTP::Get.new(uri)
req["Authorization"] = "token #{$api_token}"
req_options = {
use_ssl: uri.scheme == "https",
}
res = Net::HTTP.start(uri.hostname, uri.port, req_options) { |http|
http.request(req)
}
if res.code == "200"
result = JSON.parse(res.body)
stars = result["stargazers_count"]
forks = result["forks_count"]
subscribers = result["subscribers_count"]
puts "#{stars} Stars, #{forks} Forks and #{subscribers} Watchers"
else
puts "Failed loading GitHub repository"
exit(1)
end