-
Notifications
You must be signed in to change notification settings - Fork 687
/
add
executable file
·70 lines (56 loc) · 1.68 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
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
require 'json'
require 'octokit'
require './lib/plugin-directory-utils'
GITHUB_AUTH_TOKEN = `git config com.bohemiancoding.qa.token`.strip
USERNAME = `git config github.user`.strip
# TODO: add to Rakefile
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(:access_token => GITHUB_AUTH_TOKEN)
repo = client.repo(plugin_url)
user = client.user(owner)
new_plugin = {
:title => titlefy(name),
:description => repo.description,
:author => user.name || owner,
:owner => owner,
:name => 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
existing_plugin = json_data.select{ |item| item['name'] == name && item['owner'] == owner }
if existing_plugin.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"
system("git add plugins.json")
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, so let's update it"
existing_plugin[0]
end
puts "We have #{json_data.length} plugins on the list"