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
WP9-T2-SWD-Tools
gitlab-getlists
Commits
755c5625
Commit
755c5625
authored
2 years ago
by
kazix
Browse files
Options
Downloads
Patches
Plain Diff
poprawne generowanie pliku, teraz kosmetyka
parent
e3a07ccb
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 @
755c5625
# from re import I
import
gitlab
import
gitlab
import
requests
import
requests
import
json
import
json
...
@@ -5,6 +6,9 @@ from json2html import *
...
@@ -5,6 +6,9 @@ from json2html import *
import
argparse
import
argparse
import
os
import
os
from
dotenv
import
load_dotenv
from
dotenv
import
load_dotenv
from
pandas.io.json
import
json_normalize
import
pandas
as
pd
from
flatten_json
import
flatten
import
csv
import
csv
parser
=
argparse
.
ArgumentParser
(
description
=
"
Get Project, License and Owners from gitlab
"
)
parser
=
argparse
.
ArgumentParser
(
description
=
"
Get Project, License and Owners from gitlab
"
)
...
@@ -35,7 +39,7 @@ try:
...
@@ -35,7 +39,7 @@ try:
gl_proj
=
'
https://k8s-gitlab.software.geant.org/api/v4/projects
'
gl_proj
=
'
https://k8s-gitlab.software.geant.org/api/v4/projects
'
gl_license
=
'
repository/files/LICENSE?ref=
'
gl_license
=
'
repository/files/LICENSE?ref=
'
gl_branch
=
'
repository/branches
'
gl_branch
=
'
repository/branches
'
projects
=
gl
.
projects
.
list
()
projects
=
gl
.
projects
.
list
(
all
=
True
)
# projects = gl.projects.list(all=True)
# projects = gl.projects.list(all=True)
else
:
else
:
print
(
"
--production or --developer, please, now exit
"
)
print
(
"
--production or --developer, please, now exit
"
)
...
@@ -97,12 +101,14 @@ try:
...
@@ -97,12 +101,14 @@ try:
owners
=
json
.
loads
(
data
)
owners
=
json
.
loads
(
data
)
c_user_tmp
=
[]
c_user_tmp
=
[]
for
owner
in
owners
:
for
owner
in
owners
:
# c_user_tmp = []
if
owner
[
'
access_level
'
]
==
50
:
if
owner
[
'
access_level
'
]
==
50
:
# print('User ID: ', owner['id'])
# print('User ID: ', owner['id'])
# print('User Name: ', owner['name'])
# print('User Name: ', owner['name'])
# print('Access level: ', owner['access_level'])
# print('Access level: ', owner['access_level'])
y
=
owner
[
'
id
'
]
y
=
owner
[
'
id
'
]
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
]
=
{}
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
]
=
{}
# c_user_tmp = []
user
=
gl
.
users
.
get
(
y
)
user
=
gl
.
users
.
get
(
y
)
emails
=
user
.
emails
.
list
()
emails
=
user
.
emails
.
list
()
if
user
.
email
==
user
.
commit_email
:
if
user
.
email
==
user
.
commit_email
:
...
@@ -111,6 +117,7 @@ try:
...
@@ -111,6 +117,7 @@ try:
'
owner_name
'
:
owner
[
'
name
'
],
'
owner_name
'
:
owner
[
'
name
'
],
'
owner_mail
'
:
user
.
email
,
'
owner_mail
'
:
user
.
email
,
}
}
# c_user_tmp.append(owner['name'] + '<' + user.email + '>' + ';')
else
:
else
:
user_tmp
=
{
user_tmp
=
{
'
owner_id
'
:
owner
[
'
id
'
],
'
owner_id
'
:
owner
[
'
id
'
],
...
@@ -118,13 +125,23 @@ try:
...
@@ -118,13 +125,23 @@ try:
'
owner_mail
'
:
user
.
email
,
'
owner_mail
'
:
user
.
email
,
'
owner_mail_commit
'
:
user
.
commit_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
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
]
=
user_tmp
c_user_tmp
.
append
(
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_name
'
]
+
'
<
'
+
print
(
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_name
'
]
+
'
<
'
+
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_mail
'
]
+
'
>
'
+
'
'
)
j_project
[
'
projects
'
][
x
][
'
owners
'
][
y
][
'
owner_mail
'
]
+
'
>
'
+
'
;
'
)
print
(
c_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
)
# 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
'
],
c_project
.
append
([
project
.
attributes
[
'
id
'
],
project
.
attributes
[
'
name_with_namespace
'
],
project
.
attributes
[
'
namespace
'
][
'
name
'
],
project
.
attributes
[
'
visibility
'
],
project
.
attributes
[
'
visibility
'
],
lic
,
last_act
,
c_user_tmp
[
0
]])
lic
,
last_act
,
c_user_tmp
[
0
]])
print
(
8
*
"
-
"
)
print
(
8
*
"
-
"
)
except
:
except
:
print
(
'
Something wrong or Cant connect to GitLab server, check credential
'
)
print
(
'
Something wrong or Cant connect to GitLab server, check credential
'
)
...
@@ -132,6 +149,8 @@ except:
...
@@ -132,6 +149,8 @@ except:
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)
with
open
(
"
gitlab-projects.json
"
,
"
w
"
,
encoding
=
'
utf8
'
)
as
outfile
:
with
open
(
"
gitlab-projects.json
"
,
"
w
"
,
encoding
=
'
utf8
'
)
as
outfile
:
outfile
.
write
(
new_jproject
)
outfile
.
write
(
new_jproject
)
...
@@ -143,10 +162,18 @@ with open("gitlab-projects.html", "w", encoding='utf8') as outfile:
...
@@ -143,10 +162,18 @@ with open("gitlab-projects.html", "w", encoding='utf8') as outfile:
print
(
c_project
)
print
(
c_project
)
with
open
(
'
gitlab-projects.csv
'
,
'
w
'
,
encoding
=
'
UTF8
'
,
newline
=
''
)
as
f
:
with
open
(
'
gitlab-projects.csv
'
,
'
w
'
,
encoding
=
'
UTF8
'
,
newline
=
''
)
as
f
:
writer
=
csv
.
writer
(
f
,
delimiter
=
"
;
"
)
writer
=
csv
.
writer
(
f
)
csv_header
=
[
'
Project ID
'
,
'
Project Name
'
,
'
Group
'
,
'
Status
'
,
'
LICENSE
'
,
'
Last Activity
'
,
'
Owners
'
]
# writer = csv.DictWriter(j_project)
# write the header
# write the header
writer
.
writerow
(
csv_header
)
# writer.writerow(header)
# write multiple rows
# write multiple rows
writer
.
writerows
(
c_project
)
writer
.
writerows
(
c_project
)
# for project in projects:
# print(new_csv)
print
(
"
This is the end...
"
)
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