Class: Blend::Client::GithubClient
- Defined in:
- lib/blend/client/github_client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #add_hook(repo, name, config) ⇒ Object
- #add_team_member(team, user) ⇒ Object
- #add_team_repo(team, repo) ⇒ Object
- #create_team(team) ⇒ Object
- #find_team_from_name(name) ⇒ Object
-
#initialize(client) ⇒ GithubClient
constructor
A new instance of GithubClient.
- #list_collaborators(repo) ⇒ Object
- #list_hooks(repo) ⇒ Object
- #list_repos(filter = nil) ⇒ Object
- #list_team(team) ⇒ Object
- #list_team_members(team) ⇒ Object
- #list_team_repos(team) ⇒ Object
- #list_teams ⇒ Object
- #remove_team_member(team, user) ⇒ Object
- #remove_team_repo(team, repo) ⇒ Object
- #repo_create(team, name) ⇒ Object
Constructor Details
#initialize(client) ⇒ GithubClient
Returns a new instance of GithubClient.
6 7 8 |
# File 'lib/blend/client/github_client.rb', line 6 def initialize( client ) @client = client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/blend/client/github_client.rb', line 4 def client @client end |
Instance Method Details
#add_hook(repo, name, config) ⇒ Object
47 48 49 |
# File 'lib/blend/client/github_client.rb', line 47 def add_hook( repo, name, config ) @client.repos.hooks.create *repo.split( /\// ), name: name, config: config end |
#add_team_member(team, user) ⇒ Object
79 80 81 82 83 |
# File 'lib/blend/client/github_client.rb', line 79 def add_team_member( team, user ) find_team_from_name( team ).each do |x| return @client.orgs.teams.add_member x.id, user end end |
#add_team_repo(team, repo) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/blend/client/github_client.rb', line 91 def add_team_repo( team, repo ) user,name = repo.split( /\// ) find_team_from_name( team ).each do |x| return @client.orgs.teams.add_repo x.id, user, name end end |
#create_team(team) ⇒ Object
75 76 77 |
# File 'lib/blend/client/github_client.rb', line 75 def create_team( team ) @client.orgs.teams.create "sublimeguile", { name: team, permission: "push" } end |
#find_team_from_name(name) ⇒ Object
55 56 57 |
# File 'lib/blend/client/github_client.rb', line 55 def find_team_from_name( name ) list_teams.select { |x| x['name'] == name } end |
#list_collaborators(repo) ⇒ Object
39 40 41 |
# File 'lib/blend/client/github_client.rb', line 39 def list_collaborators( repo ) @client.repos.collaborators.list *repo.split( /\// ) end |
#list_hooks(repo) ⇒ Object
43 44 45 |
# File 'lib/blend/client/github_client.rb', line 43 def list_hooks( repo ) @client.repos.hooks.list( *repo.split( /\// ) ) end |
#list_repos(filter = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/blend/client/github_client.rb', line 10 def list_repos( filter = nil ) return @repos if @repos && filter.nil? repos = [] @client.repos.list( org: "sublimeguile" ).each_page do |page| page.each do |r| repos << r end end if filter repos = repos.select { |x| x['name'] =~ /#{filter}/ } end repos = repos.sort do |a,b| a['name'] <=> b['name'] end @repos = repos if filter.nil? repos end |
#list_team(team) ⇒ Object
59 60 61 |
# File 'lib/blend/client/github_client.rb', line 59 def list_team( team ) find_team_from_name( team ).first end |
#list_team_members(team) ⇒ Object
69 70 71 72 73 |
# File 'lib/blend/client/github_client.rb', line 69 def list_team_members( team ) find_team_from_name(team).each do |x| return @client.orgs.teams.list_members x.id end end |
#list_team_repos(team) ⇒ Object
63 64 65 66 67 |
# File 'lib/blend/client/github_client.rb', line 63 def list_team_repos( team ) find_team_from_name(team).each do |x| return @client.orgs.teams.repos x.id end end |
#list_teams ⇒ Object
51 52 53 |
# File 'lib/blend/client/github_client.rb', line 51 def list_teams @client.orgs.teams.list "sublimeguile" end |
#remove_team_member(team, user) ⇒ Object
85 86 87 88 89 |
# File 'lib/blend/client/github_client.rb', line 85 def remove_team_member( team, user) find_team_from_name( team ).each do |x| return @client.orgs.teams.remove_member x.id, user end end |
#remove_team_repo(team, repo) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/blend/client/github_client.rb', line 98 def remove_team_repo( team, repo ) user,name = repo.split( /\// ) find_team_from_name( team ).each do |x| return @client.orgs.teams.remove_repo x.id, user, name end end |
#repo_create(team, name) ⇒ Object
32 33 34 35 36 |
# File 'lib/blend/client/github_client.rb', line 32 def repo_create( team, name ) require 'pp' pp @client.repos.create org: "sublimeguile", name: name, public: false, private: true add_team_repo( team, "sublimeguile/#{name}" ) end |