Created
February 16, 2019 17:14
-
-
Save Bowenislandsong/8c95275b7a317d8ccc0e957a3d358570 to your computer and use it in GitHub Desktop.
Creating Taiga Project with invitation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creating projects in Taiga from a list | |
# Add people from the list to their projects | |
# by Bowen Song | |
# Input List File Format: | |
# <Project name> | <Member username/email> | |
# $ pip install PyGithub | |
# use Normal Access | |
# Taiga API tends to throttle | |
from taiga import TaigaAPI | |
import csv | |
import time | |
api = TaigaAPI() | |
# ---------------------------- Input information here and run the script below -------------------------- | |
api.auth( | |
username='', | |
password='' | |
) | |
listpath = "./test.txt" | |
admins = ["emails"] | |
# ---------------------------- Now Run the code, remeber the libraries, if we failed to add people, there will be a txt file with their information -------------------------- | |
# Read List file | |
proj = [] | |
member = [] | |
with open(listpath, 'r') as f: | |
reader = csv.reader(f, delimiter=' ') | |
for row in reader: | |
if len(row) == 2: | |
proj.append(row[0]) | |
member.append(row[1]) | |
def create_project(my_api,Name,des): | |
return my_api.projects.create(Name, des,is_private=False) | |
def add_member(project,email): | |
try: | |
project.add_membership(email, project.roles[4].id,username=email) | |
time.sleep(3) | |
except Exception as e: | |
print(e) | |
print email | |
# sort them into a map | |
sortedlist = {} | |
for i in range(len(proj)): | |
if proj[i] not in sortedlist: | |
sortedlist[proj[i]] = [member[i]] | |
else: | |
sortedlist[proj[i]].append(member[i]) | |
# create repositories | |
for p_name in proj: | |
tmp_proj = create_project(api,p_name,"Description") | |
time.sleep(3) | |
for admin in admins: | |
add_member(tmp_proj,admin) | |
for onemember in sortedlist[p_name]: | |
add_member(tmp_proj,onemember) | |
# # print out the members failed to be added | |
# newf = open("missed people.txt", 'a') | |
# newf.write("# <Project name> | <Member username> \n") | |
# for person in failedList: | |
# print("we have missed: "+person[0] + " " + person[1]) | |
# newf.write(person[0] + " " + person[1]+"\n") | |
# newf.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment