LoginSignup
0
0

More than 1 year has passed since last update.

gitlab project user整理

Last updated at Posted at 2023-04-03

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()

結果は以下になります

gitlabupdate.jpg

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0