Skip to content

Fetch and show the latest version of a project hosted on GitLab #7417

@joaopalmeiro

Description

@joaopalmeiro

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

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,

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    change requestIssue requests a new feature or improvement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions