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:
João Palmeiro
2024-08-05 08:15:12 +01:00
committed by GitHub
parent a5438a6dc2
commit fde6040eda
2 changed files with 46 additions and 12 deletions

View File

@@ -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 }))
)
}