Skip to content
Snippets Groups Projects
Commit 0c1c2329 authored by kazix's avatar kazix
Browse files

poprawki w interakcji z uzytkownikiem

parent d66d6486
No related branches found
No related tags found
3 merge requests!3Master to Main,!2Master,!1Master
from re import I # from re import I
import gitlab import gitlab
import requests import requests
import json import json
from json2html import * from json2html import *
import argparse
import os
from dotenv import load_dotenv
# pobieranie listy projektów parser = argparse.ArgumentParser(description="Get Project, License and Owners from gitlab")
# testowe parser.add_argument("--production", action='store_true', help="Use for Production")
# headers = {'PRIVATE-TOKEN': 'glpat-hQFB1vBzz9rQzq8wuhcG'} parser.add_argument("--developer", action='store_true', help="Use for Developer")
# gl = gitlab.Gitlab(url='https://k8s-gitlab.software.geant.org', private_token='glpat-hQFB1vBzz9rQzq8wuhcG') args = parser.parse_args()
# gl_user = 'https://k8s-gitlab.software.geant.org/api/v4/users'
# gl_proj = 'https://k8s-gitlab.software.geant.org/api/v4/projects'
# gl_license = 'repository/files/LICENSE?ref='
# gl_branch = 'repository/branches'
# projects = gl.projects.list()
# (all=True)
load_dotenv()
# produkcyjne try:
headers = {'PRIVATE-TOKEN': 'glpat-P6orz6-t2f3n1BoVDrnr'} if args.production:
gl = gitlab.Gitlab(url='https://gitlab.geant.org', private_token='glpat-P6orz6-t2f3n1BoVDrnr') token = os.getenv('PRODUCTION_TOKEN')
gl_user = 'https://gitlab.geant.org/api/v4/users' print('produkcyjny')
gl_proj = 'https://gitlab.geant.org/api/v4/projects' headers = {'PRIVATE-TOKEN': token}
gl_license = 'repository/files/LICENSE?ref=' gl = gitlab.Gitlab(url='https://gitlab.geant.org', private_token=token)
gl_branch = 'repository/branches' gl_user = 'https://gitlab.geant.org/api/v4/users'
projects = gl.projects.list(all=True) gl_proj = 'https://gitlab.geant.org/api/v4/projects'
gl_license = 'repository/files/LICENSE?ref='
j_project = {} gl_branch = 'repository/branches'
j_project['projects'] = {} projects = gl.projects.list(all=True)
for project in projects: elif args.developer:
print('Project ID: ', project.attributes['id']) token = os.getenv('DEVELOPER_TOKEN')
print('Project Name: ', project.attributes['name_with_namespace']) print('testowy')
# print('branch', project.attributes['default_branch']) headers = {'PRIVATE-TOKEN': token}
print('status', project.attributes['visibility']) gl = gitlab.Gitlab(url='https://k8s-gitlab.software.geant.org', private_token=token)
print('aktywny', project.attributes['last_activity_at']) gl_user = 'https://k8s-gitlab.software.geant.org/api/v4/users'
print('grupa', project.attributes['namespace']['name']) gl_proj = 'https://k8s-gitlab.software.geant.org/api/v4/projects'
x = project.attributes['id'] gl_license = 'repository/files/LICENSE?ref='
check_b = gl_proj + '/' + str(x) gl_branch = 'repository/branches'
check_b_response = requests.get(check_b, headers=headers) projects = gl.projects.list(all=True)
check_b_data = check_b_response.text
check_b_answer = json.loads(check_b_data)
if "default_branch" in check_b_answer:
branch = project.attributes['default_branch']
# x = project.attributes['id']
c_link = gl_proj + '/' + str(x) + '/' + gl_license + branch
c_response = requests.get(c_link, headers=headers)
c_data = c_response.text
c_answer = json.loads(c_data)
if "message" in c_answer:
print("License file: ", c_answer['message'])
lic = c_answer['message']
if "file_name" in c_answer:
print("License file: ", c_answer['file_name'])
lic = c_answer['file_name']
print('branch', project.attributes['default_branch'])
else: else:
lic = 'No created repository' print("No variable, exit")
sep = 'T' exit()
full_act = project.attributes['last_activity_at']
last_act = full_act.split(sep, 1)[0] # pobieranie listy projektów
# print("ostatnia aktywnosc: ", last_act)
tmp = { # # testowe
'project_id': project.attributes['id'], # headers = {'PRIVATE-TOKEN': 'glpat-hQFB1vBzz9rQzq8wuhcG'}
'project_name': project.attributes['name_with_namespace'], # gl = gitlab.Gitlab(url='https://k8s-gitlab.software.geant.org', private_token='glpat-hQFB1vBzz9rQzq8wuhcG')
'project_group': project.attributes['namespace']['name'], # gl_user = 'https://k8s-gitlab.software.geant.org/api/v4/users'
'project_status': project.attributes['visibility'], # gl_proj = 'https://k8s-gitlab.software.geant.org/api/v4/projects'
'project_license': lic, # gl_license = 'repository/files/LICENSE?ref='
'project_last_activity': last_act # gl_branch = 'repository/branches'
} # projects = gl.projects.list()
j_project['projects'][x] = {} # # (all=True)
j_project['projects'][x] = tmp
j_project['projects'][x]['owners'] = {}
link = (project.attributes['_links']['members'] + '/all') # produkcyjne
response = requests.get(link, headers=headers) # headers = {'PRIVATE-TOKEN': 'glpat-P6orz6-t2f3n1BoVDrnr'}
data = response.text # gl = gitlab.Gitlab(url='https://gitlab.geant.org', private_token='glpat-P6orz6-t2f3n1BoVDrnr')
owners = json.loads(data) # gl_user = 'https://gitlab.geant.org/api/v4/users'
for owner in owners: # gl_proj = 'https://gitlab.geant.org/api/v4/projects'
if owner['access_level'] == 50: # gl_license = 'repository/files/LICENSE?ref='
print('User ID: ', owner['id']) # gl_branch = 'repository/branches'
print('User Name: ', owner['name']) # projects = gl.projects.list(all=True)
print('Access level: ', owner['access_level'])
y = owner['id'] j_project = {}
j_project['projects'][x]['owners'][y] = {} j_project['projects'] = {}
user = gl.users.get(y) for project in projects:
emails = user.emails.list() # print('Project ID: ', project.attributes['id'])
if user.email == user.commit_email: # print('Project Name: ', project.attributes['name_with_namespace'])
user_tmp = { # # print('branch', project.attributes['default_branch'])
'owner_id': owner['id'], # print('status', project.attributes['visibility'])
'owner_name': owner['name'], # print('aktywny', project.attributes['last_activity_at'])
'owner_mail': user.email, # print('grupa', project.attributes['namespace']['name'])
} x = project.attributes['id']
else: check_b = gl_proj + '/' + str(x)
user_tmp = { check_b_response = requests.get(check_b, headers=headers)
'owner_id': owner['id'], check_b_data = check_b_response.text
'owner_name': owner['name'], check_b_answer = json.loads(check_b_data)
'owner_mail': user.email, if "default_branch" in check_b_answer:
'owner_mail_commit': user.commit_email branch = project.attributes['default_branch']
} # x = project.attributes['id']
j_project['projects'][x]['owners'][y] = user_tmp c_link = gl_proj + '/' + str(x) + '/' + gl_license + branch
print(8*"-") c_response = requests.get(c_link, headers=headers)
c_data = c_response.text
c_answer = json.loads(c_data)
if "message" in c_answer:
# print("License file: ", c_answer['message'])
lic = c_answer['message']
if "file_name" in c_answer:
# print("License file: ", c_answer['file_name'])
lic = c_answer['file_name']
# print('branch', project.attributes['default_branch'])
else:
lic = 'No created repository'
sep = 'T'
full_act = project.attributes['last_activity_at']
last_act = full_act.split(sep, 1)[0]
# print("ostatnia aktywnosc: ", last_act)
tmp = {
'project_id': project.attributes['id'],
'project_name': project.attributes['name_with_namespace'],
'project_group': project.attributes['namespace']['name'],
'project_status': project.attributes['visibility'],
'project_license': lic,
'project_last_activity': last_act
}
j_project['projects'][x] = {}
j_project['projects'][x] = tmp
j_project['projects'][x]['owners'] = {}
link = (project.attributes['_links']['members'] + '/all')
response = requests.get(link, headers=headers)
data = response.text
owners = json.loads(data)
for owner in owners:
if owner['access_level'] == 50:
# print('User ID: ', owner['id'])
# print('User Name: ', owner['name'])
# print('Access level: ', owner['access_level'])
y = owner['id']
j_project['projects'][x]['owners'][y] = {}
user = gl.users.get(y)
emails = user.emails.list()
if user.email == user.commit_email:
user_tmp = {
'owner_id': owner['id'],
'owner_name': owner['name'],
'owner_mail': user.email,
}
else:
user_tmp = {
'owner_id': owner['id'],
'owner_name': owner['name'],
'owner_mail': user.email,
'owner_mail_commit': user.commit_email
}
j_project['projects'][x]['owners'][y] = user_tmp
# print(8*"-")
except:
print('Cant connect to GitLab server, check credential')
exit()
new_jproject = json.dumps(j_project, indent=4, ensure_ascii=False) new_jproject = json.dumps(j_project, indent=4, ensure_ascii=False)
# print(new_jproject) # print(new_jproject)
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment