mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-11-23 23:21:00 +01: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:
parent
a5438a6dc2
commit
fde6040eda
@ -22,20 +22,25 @@ repo_url: https://github.com/squidfunk/mkdocs-material
|
||||
|
||||
The link to the repository will be rendered next to the search bar on big
|
||||
screens and as part of the main navigation drawer on smaller screen sizes.
|
||||
Additionally, for public repositories hosted on [GitHub] or [GitLab], the
|
||||
number of stars and forks is automatically requested and rendered.
|
||||
|
||||
GitHub repositories also include the tag of the latest release.[^1]
|
||||
Additionally, for public repositories hosted on [GitHub] or [GitLab], the
|
||||
latest release tag[^1], as well as the number of stars and forks, are
|
||||
automatically requested and rendered.
|
||||
|
||||
[^1]:
|
||||
Unfortunately, GitHub only provides an API endpoint to obtain the [latest
|
||||
release] - not the latest tag. Thus, make sure to [create a release] (not
|
||||
pre-release) for the latest tag you want to display next to the number of
|
||||
stars and forks.
|
||||
stars and forks. For GitLab, although it is possible to get a [list of tags
|
||||
sorted by update time], the [equivalent API endpoint] is used. So, make sure
|
||||
you also [create a release for GitLab repositories].
|
||||
|
||||
[repo_url]: https://www.mkdocs.org/user-guide/configuration/#repo_url
|
||||
[latest release]: https://docs.github.com/en/rest/reference/releases#get-the-latest-release
|
||||
[create a release]: https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository#creating-a-release
|
||||
[list of tags sorted by update time]: https://docs.gitlab.com/ee/api/tags.html#list-project-repository-tags
|
||||
[equivalent API endpoint]: https://docs.gitlab.com/ee/api/releases/#get-the-latest-release
|
||||
[create a release for GitLab repositories]: https://docs.gitlab.com/ee/user/project/releases/#create-a-release
|
||||
|
||||
#### Repository name
|
||||
|
||||
|
@ -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,7 +61,20 @@ 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 }) => ({
|
||||
@ -58,4 +83,8 @@ export function fetchSourceFactsFromGitLab(
|
||||
})),
|
||||
defaultIfEmpty({})
|
||||
)
|
||||
)
|
||||
.pipe(
|
||||
map(([release, info]) => ({ ...release, ...info }))
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user