1
1
package org .purpurmc .papyrus .controller .v2 ;
2
2
3
3
import io .swagger .v3 .oas .annotations .Operation ;
4
- import org .apache .commons .lang3 .RandomStringUtils ;
5
4
import org .purpurmc .papyrus .config .AppConfiguration ;
6
5
import org .purpurmc .papyrus .db .entity .Build ;
7
6
import org .purpurmc .papyrus .db .entity .Commit ;
8
7
import org .purpurmc .papyrus .db .entity .File ;
8
+ import org .purpurmc .papyrus .db .entity .Metadata ;
9
9
import org .purpurmc .papyrus .db .entity .Project ;
10
10
import org .purpurmc .papyrus .db .entity .Version ;
11
11
import org .purpurmc .papyrus .db .repository .BuildRepository ;
12
12
import org .purpurmc .papyrus .db .repository .CommitRepository ;
13
13
import org .purpurmc .papyrus .db .repository .FileRepository ;
14
+ import org .purpurmc .papyrus .db .repository .MetadataRepository ;
14
15
import org .purpurmc .papyrus .db .repository .ProjectRepository ;
15
16
import org .purpurmc .papyrus .db .repository .VersionRepository ;
16
17
import org .purpurmc .papyrus .exception .BuildNotFound ;
33
34
import java .io .IOException ;
34
35
import java .nio .file .Files ;
35
36
import java .nio .file .Path ;
37
+ import java .util .HashMap ;
36
38
import java .util .List ;
37
- import java .util .Random ;
39
+ import java .util .Map ;
38
40
39
41
@ RestController
40
42
@ RequestMapping ("/v2/{project}/{version}" )
@@ -44,15 +46,17 @@ public class BuildController {
44
46
private final VersionRepository versionRepository ;
45
47
private final BuildRepository buildRepository ;
46
48
private final CommitRepository commitRepository ;
49
+ private final MetadataRepository metadataRepository ;
47
50
private final FileRepository fileRepository ;
48
51
49
52
@ Autowired
50
- public BuildController (AppConfiguration configuration , ProjectRepository projectRepository , VersionRepository versionRepository , BuildRepository buildRepository , CommitRepository commitRepository , FileRepository fileRepository ) {
53
+ public BuildController (AppConfiguration configuration , ProjectRepository projectRepository , VersionRepository versionRepository , BuildRepository buildRepository , CommitRepository commitRepository , MetadataRepository metadataRepository , FileRepository fileRepository ) {
51
54
this .configuration = configuration ;
52
55
this .projectRepository = projectRepository ;
53
56
this .versionRepository = versionRepository ;
54
57
this .buildRepository = buildRepository ;
55
58
this .commitRepository = commitRepository ;
59
+ this .metadataRepository = metadataRepository ;
56
60
this .fileRepository = fileRepository ;
57
61
}
58
62
@@ -69,13 +73,14 @@ public BuildResponse getBuild(@PathVariable("project") String projectName, @Path
69
73
List <Commit > commits = commitRepository .findAllByBuild (build );
70
74
71
75
List <BuildResponse .BuildCommits > responseCommits = commits .stream ().map (commit -> new BuildResponse .BuildCommits (commit .getAuthor (), commit .getEmail (), commit .getDescription (), commit .getHash (), commit .getTimestamp ())).toList ();
72
- return new BuildResponse ( project . getName (), version . getName (), build . getName (), build . getResult (). toString (), build . getTimestamp (), build . getDuration (), responseCommits , build . getHash () );
73
- }
76
+ List < Metadata > metadata = metadataRepository . findByBuild ( build );
77
+ Map < String , String > responseMetadata = new HashMap <>();
74
78
75
- public record BuildResponse (String project , String version , String build , String result , long timestamp , long duration ,
76
- List <BuildCommits > commits , String md5 ) {
77
- public record BuildCommits (String author , String email , String description , String hash , long timestamp ) {
79
+ for (Metadata data : metadata ) {
80
+ responseMetadata .put (data .getName (), data .getValue ());
78
81
}
82
+
83
+ return new BuildResponse (project .getName (), version .getName (), build .getName (), build .getResult ().toString (), build .getTimestamp (), build .getDuration (), responseCommits , responseMetadata , build .getHash ());
79
84
}
80
85
81
86
@ GetMapping ("/{build}/download" )
@@ -115,4 +120,17 @@ public ResponseEntity<Resource> downloadBuild(@PathVariable("project") String pr
115
120
.header (HttpHeaders .CONTENT_DISPOSITION , ContentDisposition .attachment ().filename (filename ).build ().toString ())
116
121
.body (resource );
117
122
}
123
+
124
+ public record BuildResponse (String project ,
125
+ String version ,
126
+ String build ,
127
+ String result ,
128
+ long timestamp ,
129
+ long duration ,
130
+ List <BuildCommits > commits ,
131
+ Map <String , String > metadata ,
132
+ String md5 ) {
133
+ public record BuildCommits (String author , String email , String description , String hash , long timestamp ) {
134
+ }
135
+ }
118
136
}
0 commit comments