Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gitlab-getlists
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gn4-3-wp9-t2
gitlab-getlists
Commits
93280b11
Commit
93280b11
authored
2 years ago
by
kazix
Browse files
Options
Downloads
Patches
Plain Diff
poprawne generowanie pliku, teraz kosmetyka
parent
ad8d39ad
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+36
-9
36 additions, 9 deletions
main.py
with
36 additions
and
9 deletions
main.py
+
36
−
9
View file @
93280b11
# from re import I
import
gitlab
import
requests
import
json
...
...
@@ -5,6 +6,9 @@ from json2html import *
import
argparse
import
os
from
dotenv
import
load_dotenv
from
pandas.io.json
import
json_normalize
import
pandas
as
pd
from
flatten_json
import
flatten
import
csv
parser
=
argparse
.
ArgumentParser
(
description
=
"
Get Project, License and Owners from gitlab
"
)
...
...
@@ -35,7 +39,7 @@ try:
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
()
projects
=
gl
.
projects
.
list
(
all
=
True
)
# projects = gl.projects.list(all=True)
else
:
print
(
"
--production or --developer, please, now exit
"
)
...
...
@@ -97,12 +101,14 @@ try:
owners
=
json
.
loads
(
data
)
c_user_tmp
=
[]
for
owner
in
owners
:
# c_user_tmp = []
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
]
=
{}
# c_user_tmp = []
user
=
gl
.
users
.
get
(
y
)
emails
=
user
.
emails
.
list
()
if
user
.
email
==
user
.
commit_email
:
...
...
@@ -111,6 +117,7 @@ try:
'
owner_name
'
:
owner
[
'
name
'
],
'
owner_mail
'
:
user
.
email
,
}
# c_user_tmp.append(owner['name'] + '<' + user.email + '>' + ';')
else
:
user_tmp
=
{
'
owner_id
'
:
owner
[
'
id
'
],
...
...
@@ -118,13 +125,23 @@ try:
'
owner_mail
'
:
user
.
email
,
'
owner_mail_commit
'
:
user
.
commit_email
}
# c_user_tmp.append(owner['name'] + '<' + user.email + '>' + ';')
# c_user_tmp.append(j_project['projects'][x]['owners'][y]['owner_name'] + '<' +
# j_project['projects'][x]['owners'][y]['owner_mail'] + '>' + ';')
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
]
=
user_tmp
c_user_tmp
.
append
(
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_name
'
]
+
'
<
'
+
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_mail
'
]
+
'
>
'
+
'
'
)
print
(
c_user_tmp
)
print
(
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_name
'
]
+
'
<
'
+
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_mail
'
]
+
'
>
'
+
'
;
'
)
c_user_tmp
.
append
(
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_name
'
]
+
'
<
'
+
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_mail
'
]
+
'
>
'
+
'
'
)
print
(
c_user_tmp
)
# c_owners = j_project['projects'][x]['owners']
# c_user = []
# for c_owner in c_owners:
# c_user.append(c_owner['owner_name'] + ':' + c_owner['owner_mail'])
c_project
.
append
([
project
.
attributes
[
'
id
'
],
project
.
attributes
[
'
name_with_namespace
'
],
project
.
attributes
[
'
namespace
'
][
'
name
'
],
project
.
attributes
[
'
visibility
'
],
lic
,
last_act
,
c_user_tmp
[
0
]])
project
.
attributes
[
'
visibility
'
],
lic
,
last_act
,
c_user_tmp
[
0
]])
print
(
8
*
"
-
"
)
except
:
print
(
'
Something wrong or Cant connect to GitLab server, check credential
'
)
...
...
@@ -132,6 +149,8 @@ except:
new_jproject
=
json
.
dumps
(
j_project
,
indent
=
4
,
ensure_ascii
=
False
)
# print(new_jproject)
with
open
(
"
gitlab-projects.json
"
,
"
w
"
,
encoding
=
'
utf8
'
)
as
outfile
:
outfile
.
write
(
new_jproject
)
...
...
@@ -143,10 +162,18 @@ with open("gitlab-projects.html", "w", encoding='utf8') as outfile:
print
(
c_project
)
with
open
(
'
gitlab-projects.csv
'
,
'
w
'
,
encoding
=
'
UTF8
'
,
newline
=
''
)
as
f
:
writer
=
csv
.
writer
(
f
,
delimiter
=
"
;
"
)
csv_header
=
[
'
Project ID
'
,
'
Project Name
'
,
'
Group
'
,
'
Status
'
,
'
LICENSE
'
,
'
Last Activity
'
,
'
Owners
'
]
writer
=
csv
.
writer
(
f
)
# writer = csv.DictWriter(j_project)
# write the header
writer
.
writerow
(
csv_header
)
# writer.writerow(header)
# write multiple rows
writer
.
writerows
(
c_project
)
# for project in projects:
# print(new_csv)
print
(
"
This is the end...
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment