gitlab project user権限管理表を作る
希望:gitlab project user権限管理表
目の前のプロジェクトがユーザー管理表が作る,自分が統計で時間がかかります、ちょっとpythonを利用して
import json
import requests
import csv
#gitlab person access token
TOKEN = ""
GITLABURL = "https://gitlab.com"
##gitlab project ID
PROJECTID = ""
getallmemberApi = "api/v4/projects/{}/members/all".format(PROJECTID)
def GiveRequestInfo():
headers = {"PRIVATE-TOKEN":TOKEN}
url = "{}/{}".format(GITLABURL,getallmemberApi)
content = requests.get(url,headers=headers)
return content
def handdate(data):
for line in data.json():
createName = line.get("created_by", line["username"])
if not isinstance(createName, str):
createName = createName.get("created_by")
yield {
"username": line["username"],
"name": line["name"],
"access_level": line["access_level"],
"created_at": line["created_at"],
"createdby": createName
}
def writecsv():
filename = "{}.csv".format(PROJECTID)
with open(filename, "w") as f:
fieldnames = ["username", "name", "access_level", "created_at", "createdby"]
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
while True:
content = yield
writer.writerow(content)
if __name__ == "__main__":
a = GiveRequestInfo()
contest = handdate(a)
writer = writecsv()
next(writer)
for line in contest:
writer.send(line)
writer.close()