mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-22 05:53:03 -04:00
Added support for fetching latest release from GitLab (#7418)
* Fetch version for GitLab repositories * Update documentation about repositories * Fix code formatting
This commit is contained in:
@@ -26,13 +26,25 @@ import {
|
||||
Observable,
|
||||
catchError,
|
||||
defaultIfEmpty,
|
||||
map
|
||||
map,
|
||||
zip
|
||||
} from "rxjs"
|
||||
|
||||
import { requestJSON } from "~/browser"
|
||||
|
||||
import { SourceFacts } from "../_"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Helper types
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* GitLab release (partial)
|
||||
*/
|
||||
interface Release { // @todo remove and use the ReleaseSchema type instead after switching from gitlab to @gitbeaker/rest
|
||||
tag_name: string /* Tag name */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Functions
|
||||
* ------------------------------------------------------------------------- */
|
||||
@@ -49,13 +61,30 @@ export function fetchSourceFactsFromGitLab(
|
||||
base: string, project: string
|
||||
): Observable<SourceFacts> {
|
||||
const url = `https://${base}/api/v4/projects/${encodeURIComponent(project)}`
|
||||
return requestJSON<ProjectSchema>(url)
|
||||
return zip(
|
||||
|
||||
/* Fetch version */
|
||||
requestJSON<Release>(`${url}/releases/permalink/latest`)
|
||||
.pipe(
|
||||
catchError(() => EMPTY), // @todo refactor instant loading
|
||||
map(({ tag_name }) => ({
|
||||
version: tag_name
|
||||
})),
|
||||
defaultIfEmpty({})
|
||||
),
|
||||
|
||||
/* Fetch stars and forks */
|
||||
requestJSON<ProjectSchema>(url)
|
||||
.pipe(
|
||||
catchError(() => EMPTY), // @todo refactor instant loading
|
||||
map(({ star_count, forks_count }) => ({
|
||||
stars: star_count,
|
||||
forks: forks_count
|
||||
})),
|
||||
defaultIfEmpty({})
|
||||
)
|
||||
)
|
||||
.pipe(
|
||||
catchError(() => EMPTY), // @todo refactor instant loading
|
||||
map(({ star_count, forks_count }) => ({
|
||||
stars: star_count,
|
||||
forks: forks_count
|
||||
})),
|
||||
defaultIfEmpty({})
|
||||
map(([release, info]) => ({ ...release, ...info }))
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user