Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 51 lines (37 sloc) 1.22 kB
4aeb4b3 @coreyhaines Plenty of confusion since either fakeweb or github is being a pain
coreyhaines authored
1 $:.unshift(File.dirname(__FILE__))
a6ca254 @qrush Shuffling some requires around
qrush authored
2
3 require 'rubygems'
4 require 'httparty'
5 require 'json'
6
4c63ec5 @qrush Act like a grownup gem
qrush authored
7 require 'enforcer/repository'
493248e @coreyhaines Making binding work and figuring out more of the DSL
coreyhaines authored
8
9 class Enforcer
469fdde @qrush Adding some docs about postreceive urls, bumping to 0.1.0
qrush authored
10 VERSION = "0.1.0"
4c63ec5 @qrush Act like a grownup gem
qrush authored
11
7356ea1 @coreyhaines Adding api key
coreyhaines authored
12 def initialize(account_name, api_key)
d3f87e9 @coreyhaines Added account name to enforcer
coreyhaines authored
13 @account_name = account_name
7356ea1 @coreyhaines Adding api key
coreyhaines authored
14 @api_key = api_key
4aeb4b3 @coreyhaines Plenty of confusion since either fakeweb or github is being a pain
coreyhaines authored
15 end
493248e @coreyhaines Making binding work and figuring out more of the DSL
coreyhaines authored
16
22d72fd @qrush Making the DSL a bit more compact
qrush authored
17 def project(project_name, *collaborators)
18 return if collaborators.nil?
493248e @coreyhaines Making binding work and figuring out more of the DSL
coreyhaines authored
19
acd1e51 @qrush Adding some debug info so it's easy to figure out what's happening
qrush authored
20 STDOUT.puts "Enforcing settings for #{project_name}"
56ff3dc @qrush Cleaned up the github api immensely
qrush authored
21 repo = Repository.new(@account_name, @api_key, project_name)
22
23 existing_collaborators = repo.list
0c80b05 @coreyhaines Removing people too that don't belong
coreyhaines authored
24
251de9b @qrush Adding some better error checking in
qrush authored
25 if existing_collaborators.nil?
26 STDOUT.puts ">> Can't find existing collaborators for this project"
27 return
28 end
29
22d72fd @qrush Making the DSL a bit more compact
qrush authored
30 { :add => collaborators - existing_collaborators,
31 :remove => existing_collaborators - collaborators}.each_pair do |action, group|
32 group.each do |collaborator|
56ff3dc @qrush Cleaned up the github api immensely
qrush authored
33 repo.send(action, collaborator)
34 end
0c80b05 @coreyhaines Removing people too that don't belong
coreyhaines authored
35 end
36 end
18d8237 @qrush Adding postreceive hooks, thanks to tekkub's gist
qrush authored
37
498f783 @qrush Setting multiple hook urls
qrush authored
38 def postreceive(project_name, *urls)
39 STDOUT.puts "Enforcing post-receive urls for #{project_name}"
40
18d8237 @qrush Adding postreceive hooks, thanks to tekkub's gist
qrush authored
41 repo = Repository.new(@account_name, @api_key, project_name)
498f783 @qrush Setting multiple hook urls
qrush authored
42
43 repo.postreceive(urls)
18d8237 @qrush Adding postreceive hooks, thanks to tekkub's gist
qrush authored
44 end
493248e @coreyhaines Making binding work and figuring out more of the DSL
coreyhaines authored
45 end
4aeb4b3 @coreyhaines Plenty of confusion since either fakeweb or github is being a pain
coreyhaines authored
46
7356ea1 @coreyhaines Adding api key
coreyhaines authored
47 def Enforcer(account_name, api_key, &block)
48 enforcer = Enforcer.new(account_name, api_key)
d3f87e9 @coreyhaines Added account name to enforcer
coreyhaines authored
49 enforcer.instance_eval(&block)
4aeb4b3 @coreyhaines Plenty of confusion since either fakeweb or github is being a pain
coreyhaines authored
50 end
Something went wrong with that request. Please try again.