forked from sketchplugins/plugin-directory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add
executable file
·60 lines (51 loc) · 1.39 KB
/
add
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
#!/usr/bin/env ruby
require 'json'
require 'octokit'
if ARGV[0].nil?
puts "Usage: #{File.basename(__FILE__)} username/reponame"
exit
end
# First, update the local repo to avoid conflicts later on
# (use git-up if it's installed)
if `which git-up`.empty?
`git pull --rebase`
else
`git up`
end
plugin_url = ARGV[0]
# Generate the new plugin hash
owner = plugin_url.split("/")[0]
name = plugin_url.split("/")[1]
client = Octokit::Client.new
repo = client.repo(plugin_url)
user = client.user(owner)
new_plugin = {
:description => repo.description,
:name => name,
:owner => owner,
:author => user.name,
:lastUpdated => repo.updated_at
}
# Load the JSON file with all the plugins
file = File.read('plugins.json')
json_data = JSON.parse(file)
# make sure we're not adding an existing plugin
if json_data.select{ |item| item['name'] == name && item['owner'] == owner }.count == 0
# Add plugin & save file
json_data.push(new_plugin)
File.open("plugins.json","w") do |f|
f.write(JSON.pretty_generate(json_data, :indent => " "))
end
puts "We now have #{json_data.length} plugins on the list"
# Update README
system("rake")
system("git add .")
log_msg = "Added #{owner}/#{name}"
if ARGV[1]
log_msg += ". Closes ##{ARGV[1]}"
end
system("git commit -m '#{log_msg}'")
else
puts "Plugin was already on the list"
puts "We have #{json_data.length} plugins on the list"
end