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
643f48c1
Commit
643f48c1
authored
3 years ago
by
kazix
Browse files
Options
Downloads
Patches
Plain Diff
dodana opcja: grupy, statusu i ostatniej aktywności
parent
7059ab1b
No related branches found
No related tags found
3 merge requests
!3
Master to Main
,
!2
Master
,
!1
Master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+41
-52
41 additions, 52 deletions
main.py
with
41 additions
and
52 deletions
main.py
+
41
−
52
View file @
643f48c1
...
@@ -7,69 +7,58 @@ from json2html import *
...
@@ -7,69 +7,58 @@ from json2html import *
# pobieranie listy projektów
# pobieranie listy projektów
# testowe
# testowe
# headers = {'PRIVATE-TOKEN': 'glpat-hQFB1vBzz9rQzq8wuhcG'}
headers
=
{
'
PRIVATE-TOKEN
'
:
'
glpat-hQFB1vBzz9rQzq8wuhcG
'
}
# gl = gitlab.Gitlab(url='https://k8s-gitlab.software.geant.org', private_token='glpat-hQFB1vBzz9rQzq8wuhcG')
gl
=
gitlab
.
Gitlab
(
url
=
'
https://k8s-gitlab.software.geant.org
'
,
private_token
=
'
glpat-hQFB1vBzz9rQzq8wuhcG
'
)
# gl_user = 'https://k8s-gitlab.software.geant.org/api/v4/users'
gl_user
=
'
https://k8s-gitlab.software.geant.org/api/v4/users
'
# 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_branch = 'repository/branches'
# produkcyjne
headers
=
{
'
PRIVATE-TOKEN
'
:
'
glpat-P6orz6-t2f3n1BoVDrnr
'
}
gl
=
gitlab
.
Gitlab
(
url
=
'
https://gitlab.geant.org
'
,
private_token
=
'
glpat-P6orz6-t2f3n1BoVDrnr
'
)
gl_user
=
'
https://gitlab.geant.org/api/v4/users
'
gl_proj
=
'
https://gitlab.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
()
# (all=True)
def
check_license_file
(
id_proj
)
->
str
:
# # produkcyjne
"""
main / master - domyslna nazwa repozytorium sprawdzenie obydwu
# headers = {'PRIVATE-TOKEN': 'glpat-P6orz6-t2f3n1BoVDrnr'}
zwraca informacje o pliku licencji
"""
# gl = gitlab.Gitlab(url='https://gitlab.geant.org', private_token='glpat-P6orz6-t2f3n1BoVDrnr')
branch
=
'
master
'
# gl_user = 'https://gitlab.geant.org/api/v4/users'
b_link
=
gl_proj
+
'
/
'
+
str
(
id_proj
)
+
'
/
'
+
gl_branch
+
'
/
'
+
branch
# gl_proj = 'https://gitlab.geant.org/api/v4/projects'
# print(b_link)
# gl_license = 'repository/files/LICENSE?ref='
b_response
=
requests
.
get
(
b_link
,
headers
=
headers
)
# gl_branch = 'repository/branches'
b_data
=
b_response
.
text
# projects = gl.projects.list(all=True)
b_answer
=
json
.
loads
(
b_data
)
# print(b_answer)
if
'
name
'
in
b_answer
:
branch
=
'
master
'
if
'
message
'
in
b_answer
:
branch
=
'
main
'
print
(
'
branch:
'
,
branch
)
c_link
=
gl_proj
+
'
/
'
+
str
(
id_proj
)
+
'
/
'
+
gl_license
+
branch
c_response
=
requests
.
get
(
c_link
,
headers
=
headers
)
c_data
=
c_response
.
text
c_answer
=
json
.
loads
(
c_data
)
# print(c_answer)
if
"
message
"
in
c_answer
:
print
(
c_answer
[
'
message
'
])
lic
=
c_answer
[
'
message
'
]
if
"
file_name
"
in
c_answer
:
print
(
c_answer
[
'
file_name
'
])
lic
=
c_answer
[
'
file_name
'
]
return
lic
projects
=
gl
.
projects
.
list
(
all
=
True
)
# (all=True)
# users = gl.users.list(all=True)
# (all=True)
# (all=True)
j_project
=
{}
j_project
=
{}
j_project
[
'
projects
'
]
=
{}
j_project
[
'
projects
'
]
=
{}
for
project
in
projects
:
for
project
in
projects
:
# print('Project ID: ', project.attributes['id'])
# print('Project ID: ', project.attributes['id'])
# print('Project Name: ', project.attributes['name'])
# print('Project Name: ', project.attributes['name_with_namespace'])
# print('branch', project.attributes['default_branch'])
# print('status', project.attributes['visibility'])
# print('aktywny', project.attributes['last_activity_at'])
# print('grupa', project.attributes['namespace']['name'])
branch
=
project
.
attributes
[
'
default_branch
'
]
x
=
project
.
attributes
[
'
id
'
]
x
=
project
.
attributes
[
'
id
'
]
# print(check_license_file(x))
c_link
=
gl_proj
+
'
/
'
+
str
(
x
)
+
'
/
'
+
gl_license
+
branch
licen
=
check_license_file
(
x
)
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
'
]
sep
=
'
T
'
full_act
=
project
.
attributes
[
'
last_activity_at
'
]
last_act
=
full_act
.
split
(
sep
,
1
)[
0
]
# print("ostatnia aktywnosc: ", last_act)
tmp
=
{
tmp
=
{
'
project_id
'
:
project
.
attributes
[
'
id
'
],
'
project_id
'
:
project
.
attributes
[
'
id
'
],
'
project_name
'
:
project
.
attributes
[
'
name
'
],
'
project_name
'
:
project
.
attributes
[
'
name_with_namespace
'
],
'
project_license
'
:
licen
'
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
]
=
{}
j_project
[
'
projects
'
][
x
]
=
tmp
j_project
[
'
projects
'
][
x
]
=
tmp
...
@@ -104,7 +93,7 @@ for project in projects:
...
@@ -104,7 +93,7 @@ for project in projects:
print
(
8
*
"
-
"
)
print
(
8
*
"
-
"
)
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)
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
)
...
@@ -112,4 +101,4 @@ with open("gitlab-projects.json", "w", encoding='utf8') as outfile:
...
@@ -112,4 +101,4 @@ with open("gitlab-projects.json", "w", encoding='utf8') as outfile:
new_jproject_html
=
json2html
.
convert
(
json
=
new_jproject
)
new_jproject_html
=
json2html
.
convert
(
json
=
new_jproject
)
with
open
(
"
gitlab-projects.html
"
,
"
w
"
,
encoding
=
'
utf8
'
)
as
outfile
:
with
open
(
"
gitlab-projects.html
"
,
"
w
"
,
encoding
=
'
utf8
'
)
as
outfile
:
outfile
.
write
(
new_jproject_html
)
outfile
.
write
(
new_jproject_html
)
\ No newline at end of file
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