Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SonarQube Scripts
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
Geant DevOps
SonarQube Scripts
Commits
8078844c
Unverified
Commit
8078844c
authored
2 years ago
by
Max Adamo
Browse files
Options
Downloads
Patches
Plain Diff
change ini file structure
parent
86239745
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sq_projects_list.py
+13
-6
13 additions, 6 deletions
sq_projects_list.py
with
13 additions
and
6 deletions
sq_projects_list.py
+
13
−
6
View file @
8078844c
...
...
@@ -2,16 +2,19 @@
"""
Filter JSON data based on the last_analysis_date.
Usage:
sq_projects_list.py --months=<n>
sq_projects_list.py --months=<N>
0 or negative number means all projects
Options:
--months=<n> Show only projects with last_analysis_date older than n months ago.
-h --help Show this help screen.
--months=<N> Show only projects with last_analysis_date older than N months ago.
"""
import
os
import
json
import
configparser
import
requests
import
datetime
import
requests
from
docopt
import
docopt
...
...
@@ -21,7 +24,9 @@ def filter_data(data, months_nr):
for
item
in
data
:
date_str
=
item
[
'
last_analysis_date
'
]
date_obj
=
datetime
.
datetime
.
strptime
(
date_str
,
'
%Y-%m-%dT%H:%M:%S%z
'
)
months_diff
=
(
datetime
.
datetime
.
now
(
date_obj
.
tzinfo
)
-
date_obj
)
//
datetime
.
timedelta
(
days
=
30
)
months_diff
=
(
datetime
.
datetime
.
now
(
date_obj
.
tzinfo
)
-
date_obj
)
//
datetime
.
timedelta
(
days
=
30
)
if
months_diff
>
months_nr
:
filtered_data
.
append
(
item
)
return
filtered_data
...
...
@@ -30,6 +35,7 @@ def filter_data(data, months_nr):
if
__name__
==
'
__main__
'
:
# parse the command line arguments using docopt
args
=
docopt
(
__doc__
)
months
=
args
[
'
--months
'
]
sq_ini
=
os
.
path
.
expanduser
(
'
~/.config/sonarqube.ini
'
)
if
not
os
.
path
.
isfile
(
sq_ini
):
...
...
@@ -40,6 +46,7 @@ with the following content:
[sq]
token = <your token>
host = sonarqube.example.org
You can generate a token in SonarQube under My Account > Security
'''
)
...
...
@@ -48,10 +55,11 @@ You can generate a token in SonarQube under My Account > Security
config
=
configparser
.
RawConfigParser
()
config
.
read
(
sq_ini
)
sq_token
=
config
.
get
(
'
sq
'
,
'
token
'
)
sq_host
=
config
.
get
(
'
sq
'
,
'
host
'
)
session
=
requests
.
Session
()
session
.
auth
=
(
sq_token
,
''
)
req
=
session
.
get
(
'
https://
sonarqube.software.geant.org
/api/projects/search
'
)
req
=
session
.
get
(
f
'
https://
{
sq_host
}
/api/projects/search
'
)
if
req
.
status_code
==
401
:
print
(
'
Error: Invalid token
'
)
...
...
@@ -76,7 +84,6 @@ You can generate a token in SonarQube under My Account > Security
'
last_analysis_date
'
:
'
1970-01-01T01:00:00+0200
'
})
months
=
int
(
args
[
'
--months
'
])
# filter the data based on the last_analysis_date
filtered_list
=
filter_data
(
final_list
,
int
(
months
))
...
...
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