@@ -26,13 +26,25 @@ import {
26
26
Observable ,
27
27
catchError ,
28
28
defaultIfEmpty ,
29
- map
29
+ map ,
30
+ zip
30
31
} from "rxjs"
31
32
32
33
import { requestJSON } from "~/browser"
33
34
34
35
import { SourceFacts } from "../_"
35
36
37
+ /* ----------------------------------------------------------------------------
38
+ * Helper types
39
+ * ------------------------------------------------------------------------- */
40
+
41
+ /**
42
+ * GitLab release (partial)
43
+ */
44
+ interface Release { // @todo remove and use the ReleaseSchema type instead after switching from gitlab to @gitbeaker/rest
45
+ tag_name : string /* Tag name */
46
+ }
47
+
36
48
/* ----------------------------------------------------------------------------
37
49
* Functions
38
50
* ------------------------------------------------------------------------- */
@@ -49,13 +61,30 @@ export function fetchSourceFactsFromGitLab(
49
61
base : string , project : string
50
62
) : Observable < SourceFacts > {
51
63
const url = `https://${ base } /api/v4/projects/${ encodeURIComponent ( project ) } `
52
- return requestJSON < ProjectSchema > ( url )
64
+ return zip (
65
+
66
+ /* Fetch version */
67
+ requestJSON < Release > ( `${ url } /releases/permalink/latest` )
68
+ . pipe (
69
+ catchError ( ( ) => EMPTY ) , // @todo refactor instant loading
70
+ map ( ( { tag_name } ) => ( {
71
+ version : tag_name
72
+ } ) ) ,
73
+ defaultIfEmpty ( { } )
74
+ ) ,
75
+
76
+ /* Fetch stars and forks */
77
+ requestJSON < ProjectSchema > ( url )
78
+ . pipe (
79
+ catchError ( ( ) => EMPTY ) , // @todo refactor instant loading
80
+ map ( ( { star_count, forks_count } ) => ( {
81
+ stars : star_count ,
82
+ forks : forks_count
83
+ } ) ) ,
84
+ defaultIfEmpty ( { } )
85
+ )
86
+ )
53
87
. pipe (
54
- catchError ( ( ) => EMPTY ) , // @todo refactor instant loading
55
- map ( ( { star_count, forks_count } ) => ( {
56
- stars : star_count ,
57
- forks : forks_count
58
- } ) ) ,
59
- defaultIfEmpty ( { } )
88
+ map ( ( [ release , info ] ) => ( { ...release , ...info } ) )
60
89
)
61
90
}
0 commit comments