-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Context
Hi! 👋
I'm documenting a Python package hosted on GitLab and, similar to a project hosted on GitHub, I would like to include the latest released version along with the rest of the repo information (e.g., stars) next to the search bar/as part of the main navigation drawer.
Description
Similar to GitHub, GitLab also has an API endpoint to obtain information about the latest release. Thus, the following snippet
mkdocs-material/src/templates/assets/javascripts/components/source/facts/gitlab/index.ts
Lines 48 to 61 in a5438a6
| export function fetchSourceFactsFromGitLab( | |
| base: string, project: string | |
| ): Observable<SourceFacts> { | |
| const url = `https://${base}/api/v4/projects/${encodeURIComponent(project)}` | |
| return requestJSON<ProjectSchema>(url) | |
| .pipe( | |
| catchError(() => EMPTY), // @todo refactor instant loading | |
| map(({ star_count, forks_count }) => ({ | |
| stars: star_count, | |
| forks: forks_count | |
| })), | |
| defaultIfEmpty({}) | |
| ) | |
| } |
could be adapted based on the GitHub one,
mkdocs-material/src/templates/assets/javascripts/components/source/facts/github/index.ts
Lines 60 to 75 in a5438a6
| export function fetchSourceFactsFromGitHub( | |
| user: string, repo?: string | |
| ): Observable<SourceFacts> { | |
| if (typeof repo !== "undefined") { | |
| const url = `https://api.github.com/repos/${user}/${repo}` | |
| return zip( | |
| /* Fetch version */ | |
| requestJSON<Release>(`${url}/releases/latest`) | |
| .pipe( | |
| catchError(() => EMPTY), // @todo refactor instant loading | |
| map(release => ({ | |
| version: release.tag_name | |
| })), | |
| defaultIfEmpty({}) | |
| ), |
in order to obtain the desired information.
You can see an example response using the following command (the relevant field is the tag_name one):
curl -L "https://gitlab.com/api/v4/projects/joaommpalmeiro%2Fgaveta/releases/permalink/latest"The list releases API endpoint can also be used for this purpose.
Let me know what you think and if I can open a PR. Thanks!
Related links
- https://squidfunk.github.io/mkdocs-material/setup/adding-a-git-repository/#repository
- https://docs.gitlab.com/ee/api/releases/#get-the-latest-release
Use Cases
Projects hosted on GitLab will also be able to show the latest version information. Additionally, repository information will become consistent, as we will be able to get the same information for GitHub and GitLab.
Visuals
No response
Before submitting
- I have read and followed the change request guidelines.
- I have verified that my idea is a change request and not a bug report.
- I have ensured that, to the best of my knowledge, my idea will benefit the entire community.
- I have included relevant links to the documentation, related issues, and discussions to underline the need for my idea.