forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-review-requests.template.rb
executable file
·71 lines (60 loc) · 1.87 KB
/
github-review-requests.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
71
#!/usr/bin/env ruby
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Show Review Requests
# @raycast.mode inline
# @raycast.description Display number of Pull Requests requesting your review
#
# Optional parameters:
# @raycast.packageName GitHub
# @raycast.icon images/github-logo.png
# @raycast.iconDark images/github-logo-iconDark.png
#
# Conditional parameters:
# @raycast.refreshTime 5m
#
# Credits
# @raycast.author Vince Picone
# @raycast.authorURL https://github.com/vpicone
require 'json'
require 'net/http'
require 'uri'
# Insert a personal access token (https://github.com/settings/tokens)
# No additional permissions are required, leave all the options unchecked
API_TOKEN = ''
if API_TOKEN.empty?
puts 'No API token provided'
exit(1)
end
RED = 31
GREEN = 32
YELLOW = 33
uri = URI('https://api.github.com/graphql')
req = Net::HTTP::Post.new(uri)
req['Authorization'] = "token #{API_TOKEN}"
req.body = '{ "query": "query {search(query:\"type:pr is:open user-review-requested:@me\",type:ISSUE,first:10){issueCount edges{node{...on PullRequest{number title url}}}}}" }'
req_options = {
use_ssl: uri.scheme == 'https'
}
res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(req)
end
if res.code == '200'
result = JSON.parse(res.body)
review_requests = result['data']['search']['edges']
review_requests_count = result['data']['search']['issueCount']
if review_requests_count == 0
message = "No open review requests 🎉"
puts "\e[#{GREEN}m#{message}\e[0m"
else
color = (review_requests_count <= 5) ? YELLOW : RED
message = "You have #{review_requests_count} open review requests"
puts "\e[#{color}m#{message}\e[0m"
review_requests.each do |pr|
puts "##{pr['node']['number']} #{pr['node']['title']} (#{pr['node']['url']})"
end
end
else
puts 'Failed loading GitHub review requests'
exit(1)
end