Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.NativeQuery;
import org.springframework.stereotype.Repository;

@Repository
public interface ScoreRepository extends JpaRepository<Score, Long> {
Optional<Score> findFirstByPluginOrderByComputedAtDesc(Plugin plugin);

@Query(
@NativeQuery(
value =
"""
SELECT DISTINCT ON (s.plugin_id)
Expand All @@ -50,23 +50,21 @@ SELECT DISTINCT ON (s.plugin_id)
FROM scores s
JOIN plugins p on s.plugin_id = p.id
ORDER BY s.plugin_id, s.computed_at DESC;
""",
nativeQuery = true)
""")
List<Score> findLatestScoreForAllPlugins();

@Query(
@NativeQuery(
value =
"""
SELECT DISTINCT ON (s.plugin_id)
s.value
FROM scores s
ORDER BY s.plugin_id, s.computed_at DESC, s.value;
""",
nativeQuery = true)
""")
int[] getLatestScoreValueOfEveryPlugin();

@Modifying
@Query(
@NativeQuery(
value =
"""
DELETE FROM scores
Expand All @@ -78,11 +76,10 @@ SELECT id, ROW_NUMBER() OVER (PARTITION BY plugin_id ORDER BY computed_at DESC)
) s
WHERE row_num <= 5
);
""",
nativeQuery = true)
""")
int deleteOldScoreFromPlugin();

@Query(
@NativeQuery(
value =
"""
SELECT
Expand All @@ -99,7 +96,35 @@ SELECT DISTINCT ON (s.plugin_id)
FROM scores s
ORDER BY s.plugin_id, s.computed_at DESC
);
""",
nativeQuery = true)
""")
List<Score> getAllLatestScoresWithValue(int score);

@NativeQuery(
value =
"""
SELECT
s.id,
s.plugin_id,
s.computed_at,
s.details,
s.value
FROM scores s
LEFT JOIN plugins p on s.plugin_id = p.id
WHERE s.id IN (
SELECT DISTINCT ON (s.plugin_id)
s.id
FROM scores s
ORDER BY s.plugin_id, s.computed_at DESC
) AND (EXISTS (
SELECT *
FROM jsonb_array_elements(s.details) as r(detail)
WHERE detail ->> 'key' = ?1
AND (detail -> 'value')::int < 100
) OR NOT EXISTS (
SELECT *
FROM jsonb_array_elements(s.details) as r(detail)
WHERE detail ->> 'key' = ?1
));
""")
List<Score> getAllLatestScoresWithIncompleteScoring(String scoringKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ public Map<Integer, Long> getScoresDistribution() {
public List<Score> getAllLatestScoresWithValue(int value) {
return repository.getAllLatestScoresWithValue(value);
}

@Transactional(readOnly = true)
public List<Score> getAllLatestScoresWithIncompleteScoring(String scoringKey) {
return repository.getAllLatestScoresWithIncompleteScoring(scoringKey);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,39 @@ void shouldBeAbleToRetrieveAllPluginsWithSpecificScore() {
assertThat(scoreService.getAllLatestScoresWithValue(50)).containsExactly(s2);
assertThat(scoreService.getAllLatestScoresWithValue(75)).containsExactlyInAnyOrder(s3, s4);
}

@Test
void shouldBeAbleToRetrieveScoresWithIncompleteSections() {
final Plugin p1 =
entityManager.persist(new Plugin("foo", new VersionNumber("1.0"), "scm", ZonedDateTime.now()));
final Plugin p2 =
entityManager.persist(new Plugin("bar", new VersionNumber("1.1"), "scm", ZonedDateTime.now()));
final Plugin p3 =
entityManager.persist(new Plugin("zoo", new VersionNumber("1.1"), "scm", ZonedDateTime.now()));

final Score s1 = new Score(p1, ZonedDateTime.now().minusDays(1));
s1.addDetail(new ScoreResult("key-1", 90, 1, Set.of(), 1));
s1.addDetail(new ScoreResult("key-2", 80, 1, Set.of(), 1));
final Score s2 = new Score(p1, ZonedDateTime.now());
s2.addDetail(new ScoreResult("key-1", 50, 1, Set.of(), 1));
s2.addDetail(new ScoreResult("key-2", 80, 1, Set.of(), 1));
final Score s3 = new Score(p2, ZonedDateTime.now());
s3.addDetail(new ScoreResult("key-1", 100, 1, Set.of(), 1));
s3.addDetail(new ScoreResult("key-2", 100, 1, Set.of(), 1));
final Score s4 = new Score(p3, ZonedDateTime.now());
s4.addDetail(new ScoreResult("key-1", 75, 1, Set.of(), 1));
s4.addDetail(new ScoreResult("key-2", 100, 1, Set.of(), 1));

entityManager.persist(s1);
entityManager.persist(s2);
entityManager.persist(s3);
entityManager.persist(s4);

assertThat(scoreService.getAllLatestScoresWithIncompleteScoring("key-1"))
.containsExactlyInAnyOrder(s2, s4);
assertThat(scoreService.getAllLatestScoresWithIncompleteScoring("key-2"))
.containsOnly(s2);
assertThat(scoreService.getAllLatestScoresWithIncompleteScoring("key-3"))
.containsExactlyInAnyOrder(s2, s3, s4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
*/
package io.jenkins.pluginhealth.scoring.http;

import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import io.jenkins.pluginhealth.scoring.scores.Scoring;
import io.jenkins.pluginhealth.scoring.service.ScoreService;
import io.jenkins.pluginhealth.scoring.service.ScoringService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -37,9 +43,11 @@
public class DataController {

private final ScoreService scoreService;
private final ScoringService scoringService;

public DataController(ScoreService scoreService) {
public DataController(ScoreService scoreService, ScoringService scoringService) {
this.scoreService = scoreService;
this.scoringService = scoringService;
}

@ModelAttribute(name = "module")
Expand All @@ -61,4 +69,23 @@ public ModelAndView pluginsPerScore(@PathVariable int score) {
modelAndView.addObject("scores", scoreService.getAllLatestScoresWithValue(score));
return modelAndView;
}

@GetMapping(path = {"/pluginsPerScoring", "/pluginsPerScoring/", "/pluginsPerScoring/{scoring}"})
public ModelAndView pluginsPerScoring(@PathVariable(required = false) String scoring) {
final ModelAndView modelAndView = new ModelAndView("data/pluginsPerScoring");
final Set<String> scoringKeys =
scoringService.getScoringList().stream().map(Scoring::key).collect(Collectors.toSet());
modelAndView.addObject("scorings", scoringKeys);
if (scoring != null) {
modelAndView.addObject("selectedScoring", scoring);
modelAndView.addObject("scores", scoreService.getAllLatestScoresWithIncompleteScoring(scoring));
} else {
final Map<String, Integer> distribution = scoringKeys.stream()
.collect(Collectors.toMap(key -> key, key -> scoreService
.getAllLatestScoresWithIncompleteScoring(key)
.size()));
modelAndView.addObject("distribution", distribution);
}
return modelAndView;
}
}
2 changes: 1 addition & 1 deletion war/src/main/js/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export function setupDataTable(elementId, option = {}) {
},
...option
}
new DataTable(elementId, mergedOpt);
return new DataTable(elementId, mergedOpt);
}
7 changes: 7 additions & 0 deletions war/src/main/less/modules/score.less
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
@import '../abstracts/colors';

.score--failure {
color: var(--danger);
}
.score--success {
color: var(--success);
}

ion-icon {
font-size: 24px;

Expand Down
2 changes: 1 addition & 1 deletion war/src/main/resources/templates/data/distribution.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<body>

<section data-layout-fragment="content">
<h1>Data</h1>
<h1>Data / Score distribution</h1>
<div id="distribution-graph" style="width: 100%; height: 75vh">
</div>

Expand Down
19 changes: 15 additions & 4 deletions war/src/main/resources/templates/data/pluginsPerScore.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,35 @@
<body>

<section data-layout-fragment="content">
<h1>Data</h1>
<h1>
<a href="/data">Data</a> / Per score
</h1>
<div>
<table class="table" id="plugins">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
<th>Scorings</th>
<th>Computation timestamp</th>
<th></th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr data-th-each="score : ${scores}" data-th-with="plugin = ${score.plugin}">
<td data-th-text="${plugin.name}"></td>
<td data-th-text="${score.value}">
<td data-th-text="${#temporals.format(score.computedAt, 'yyyy-MM-dd HH:mm', 'UTC')}"></td>
<td>
<a data-th-href="'/scores/' + ${plugin.name}" target="_blank">details</a>
<code data-th-each="scoring: ${score.getDetails()}"
class="label" data-th-classappend="|score--${scoring.value() == 100 ? 'success':'failure'}|">
<span data-th-text="${scoring.key()}"></span>
<ion-icon name="failure" data-th-if="${scoring.value() != 100}"></ion-icon>
<ion-icon name="success" data-th-if="${scoring.value() == 100}"></ion-icon>
</code>
</td>
<td data-th-text="${{score.computedAt}}"></td>
<td>
<a data-th-href="|/scores/${plugin.name}|" target="_blank">details</a>
</td>
</tr>
</tbody>
Expand Down
108 changes: 108 additions & 0 deletions war/src/main/resources/templates/data/pluginsPerScoring.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!DOCTYPE html>
<html lang="en" data-layout-decorate="~{layouts/main}">
<head>
<title>Data</title>
</head>
<body>

<section data-layout-fragment="content">
<h1>
<a href="/data">Data</a> /
<span data-th-if="${selectedScoring != null}" ><a href="/data/pluginsPerScoring">Per scoring</a> / <span data-th-text="${selectedScoring}"></span></span>
<span data-th-unless="${selectedScoring != null}">Per scoring</span>
</h1>
<div data-th-if="${scores != null}">
<table class="table" id="plugins">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
<th>Popularity</th>
<th>Scorings</th>
<th>Computation timestamp</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr data-th-each="score : ${scores}" data-th-with="plugin = ${score.plugin}">
<td data-th-text="${plugin.name}"></td>
<td data-th-text="${score.value}"></td>
<td data-th-text="${plugin.getDetails().get('stat').message}"></td>
<td>
<code data-th-each="scoring: ${score.getDetails()}"
class="label" data-th-classappend="|score--${scoring.value() == 100 ? 'success':'failure'}|">
<span data-th-text="${scoring.key()}"></span>
<ion-icon name="failure" data-th-if="${scoring.value() != 100}"></ion-icon>
<ion-icon name="success" data-th-if="${scoring.value() == 100}"></ion-icon>
</code>
</td>
<td data-th-text="${{score.computedAt}}"></td>
<td>
<a data-th-href="|/scores/${plugin.name}|" target="_blank">
<ion-icon name="eye-outline"></ion-icon>
</a>
</td>
</tr>
</tbody>
</table>
</div>
<div data-th-if="${distribution != null}" id="distribution-graph" style="width: 100%; height: 75vh"></div>

<script data-th-src="@{/js/chart.js}" type="application/javascript"></script>
<script data-th-src="@{/js/table.js}" type="application/javascript"></script>
<link data-th-href="@{/js/table.css}" rel="stylesheet"/>
<script defer type="application/javascript" data-th-if="${scores != null}">
const table = module['js/table'].setupDataTable('#plugins', {
perPageSelect: [25, 50, 100],
});
table.on('datatable.init', () => {
table.columns.sort(2, 'desc');
})
</script>
<script defer type="application/javascript" data-th-inline="javascript" data-th-if="${distribution != null}">
const distribution = /*[[${distribution}]]*/{}
if (distribution !== {}) {
const source = [...Object.keys(distribution).flatMap((scoring) => ({'scoring': scoring, 'count': distribution[scoring]}))]
const option = {
title: {
show: true,
text: 'Count of plugins failing each scoring',
},
dataset: {
source,
},
xAxis: {
type: 'category',
name: 'Scoring',
axisTick: {
alignWithLabel: true
},
axisPointer: {
snap: true,
},
axisLabel: {
interval: 0,
},
},
yAxis: {
type: 'value',
name: 'Number of plugins',
axisPointer: {
snap: true
},
},
series: [{
type: 'bar',
animation: false,
}]
}
const chart = module["js/chart"].createChart('distribution-graph', option)
chart.on('click', ({data: {scoring}}) => {
window.open(`/data/pluginsPerScoring/${scoring}`)
})
}
</script>
</section>

</body>
</html>
6 changes: 6 additions & 0 deletions war/src/main/resources/templates/scores/listing.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1>Scores</h1>
<th>Weight</th>
<th>What is validated</th>
<th>Description</th>
<th>View failing plugins</th>
</tr>
</thead>
<tbody>
Expand All @@ -28,6 +29,11 @@ <h1>Scores</h1>
</ul>
</td>
<td data-th-text="${scoring.description}"></td>
<td>
<a data-th-href="|/data/pluginsPerScoring/${scoring.key()}|">
<ion-icon name="eye-outline"></ion-icon>
</a>
</td>
</tr>
</tbody>
</table>
Expand Down
1 change: 1 addition & 0 deletions war/src/main/svg/eye-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading