Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit a2006f3

Browse files
committed
add to team and org method
1 parent f39209f commit a2006f3

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

add-to-org.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,37 @@
4747

4848
# Create a new Octokit Client
4949
Octokit.auto_paginate = true
50-
client = Octokit::Client.new :access_token => TOKEN
50+
@client = Octokit::Client.new :access_token => TOKEN
51+
52+
# If the team doesn't exist yet, create it
53+
# otherwise, get the team_id from the list
54+
# Once we have the team_id we can add people to it
55+
# regardless of them being a member of the organization yet
56+
def add_to_team_and_org(team_name, username, org)
57+
58+
team_id = nil
59+
team_list = @client.org_teams(org)
60+
61+
team_list.each do |team|
62+
if team.name == team_name
63+
team_id = team.id
64+
end
65+
end
66+
67+
if team_id.nil?
68+
# TODO: what ways can this fail that we need to rescue for?
69+
response = @client.create_team(org, {:name => team_name})
70+
team_id = response.id
71+
puts "Team '#{team_name}' created at https://github.com/orgs/#{org}/teams" unless team_id.nil?
72+
end
73+
74+
# Add username to team_id
75+
@client.add_team_membership(team_id, username)
76+
puts "#{username} added to #{team_name}."
77+
end
5178

5279
if !team_name.nil?
5380
add_to_team_and_org(team_name, username, org)
5481
else
5582
#add_to_org(username, org)
5683
end
57-

0 commit comments

Comments
 (0)