Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gitlab Project Doctor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
Numérique et Écologie
Gitlab Project Doctor
Commits
70d65878
Verified
Commit
70d65878
authored
2 years ago
by
Geoffrey Arthaud
Browse files
Options
Downloads
Patches
Plain Diff
Display and store bytes savable
parent
221fe380
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
src/diagnosis/artifact_size.rs
+21
-8
21 additions, 8 deletions
src/diagnosis/artifact_size.rs
with
21 additions
and
8 deletions
src/diagnosis/artifact_size.rs
+
21
−
8
View file @
70d65878
...
...
@@ -2,6 +2,7 @@ use chrono::{DateTime, Duration, Local};
use
gitlab
::
api
::{
Pagination
,
projects
,
Query
};
use
gitlab
::
api
::
paged
;
use
gitlab
::
Gitlab
;
use
human_bytes
::
human_bytes
;
use
serde
::
Deserialize
;
use
crate
::{
Reportable
,
ReportJob
,
ReportPending
};
...
...
@@ -29,6 +30,7 @@ pub struct ArtifactSizeJob {
pub
struct
ArtifactReport
{
pub
gitlab_jobs
:
Vec
<
GitlabJob
>
,
pub
report_status
:
Vec
<
ReportStatus
>
,
pub
bytes_savable
:
u64
}
impl
Reportable
for
ArtifactReport
{
...
...
@@ -50,6 +52,7 @@ impl ReportJob for ArtifactSizeJob {
report_status
:
vec!
[
ReportStatus
::
NA
(
"No CI/CD configured on this project"
.to_string
())],
gitlab_jobs
:
vec!
[],
bytes_savable
:
0
};
}
let
endpoint
=
projects
::
jobs
::
Jobs
::
builder
()
...
...
@@ -57,9 +60,11 @@ impl ReportJob for ArtifactSizeJob {
.build
()
.unwrap
();
let
jobs
:
Vec
<
GitlabJob
>
=
paged
(
endpoint
,
Pagination
::
All
)
.query
(
&
self
.gitlab
)
.unwrap
();
let
(
report
,
bytes_savable
)
=
ArtifactSizeJob
::
_number_jobs
(
&
jobs
);
ArtifactReport
{
report_status
:
ArtifactSizeJob
::
_number_jobs
(
&
jobs
)
,
report_status
:
vec!
[
report
]
,
gitlab_jobs
:
jobs
,
bytes_savable
}
})
},
...
...
@@ -75,14 +80,22 @@ impl ArtifactSizeJob {
}
}
fn
_number_jobs
(
jobs
:
&
Vec
<
GitlabJob
>
)
->
Vec
<
ReportStatus
>
{
fn
_number_jobs
(
jobs
:
&
[
GitlabJob
]
)
->
(
ReportStatus
,
u64
)
{
let
ref_date
=
Local
::
now
()
-
Duration
::
days
(
ARTIFACT_JOBS_DAYS_LIMIT
);
let
count_old
=
jobs
.iter
()
.filter
(|
j
|
j
.created_at
.le
(
&
ref_date
))
.count
();
vec!
[
ReportStatus
::
NA
(
format!
(
"{} jobs ({} %) are older than {} days"
,
count_old
,
100
*
count_old
/
jobs
.len
(),
let
mut
old_count
:
usize
=
0
;
let
mut
old_size
:
u64
=
0
;
for
job
in
jobs
.iter
()
{
let
artifact_size
:
u64
=
job
.artifacts
.iter
()
.map
(|
a
|
a
.size
)
.sum
();
if
job
.created_at
.le
(
&
ref_date
)
{
old_count
+=
1
;
old_size
+=
artifact_size
;
}
}
(
ReportStatus
::
NA
(
format!
(
"{} jobs ({}) are older than {} days"
,
old_count
,
human_bytes
(
old_size
as
f64
),
ARTIFACT_JOBS_DAYS_LIMIT
))
]
))
,
old_size
)
}
}
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