This repository was archived by the owner on Feb 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Expand file tree Collapse file tree 1 file changed +28
-2
lines changed Original file line number Diff line number Diff line change 4747
4848# Create a new Octokit Client
4949Octokit . 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
5279if !team_name . nil?
5380 add_to_team_and_org ( team_name , username , org )
5481else
5582 #add_to_org(username, org)
5683end
57-
You can’t perform that action at this time.
0 commit comments