forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-open-pull-requests-details.template.rb
executable file
·57 lines (49 loc) · 1.44 KB
/
github-open-pull-requests-details.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
#!/usr/bin/env ruby
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Show Open Pull Requests
# @raycast.mode fullOutput
# @raycast.description Display (detailed) GitHub pull requests
#
# Optional parameters:
# @raycast.packageName GitHub
# @raycast.icon images/github-logo.png
# @raycast.iconDark images/github-logo-iconDark.png
#
# Credits
# @raycast.author Faye Sipiano
# @raycast.authorURL https://github.com/FSipiano
require 'json'
require 'net/http'
require 'uri'
# Insert a personal access token (https://github.com/settings/tokens)
API_TOKEN = ''
if API_TOKEN.empty?
puts 'No API token provided'
exit(1)
end
uri = URI('https://api.github.com/graphql')
req = Net::HTTP::Post.new(uri)
req['Authorization'] = "token #{API_TOKEN}"
req.body = '{ "query": "query { viewer { pullRequests(first: 10 states: OPEN) { nodes { baseRepository { name } title number 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)
pull_requests = result['data']['viewer']['pullRequests']['nodes']
if pull_requests.length == 0
puts 'No open pull requests 🎉'
else
puts "You have #{pull_requests.length} open pull requests"
pull_requests.each do |pr|
puts "##{pr['number']} #{pr['title']} (#{pr['url']})"
end
end
else
puts 'Failed loading GitHub pull requests'
exit(1)
end