badges/shields · error · NotFound
no commits found
Error message
no commits found
What it means
The GitLab last-commit service fetches the commit list for a project/ref and destructures the first element. When the API returns an empty array, `commit` is undefined and the service throws `NotFound` with 'no commits found'. The request succeeded; there is simply no commit data for the given project/ref/path combination.
Source
Thrown at services/gitlab/gitlab-last-commit.service.js:87
// https://docs.gitlab.com/ee/api/commits.html#list-repository-commits
return super.fetch({
url: `${baseUrl}/api/v4/projects/${encodeURIComponent(
project,
)}/repository/commits`,
options: { searchParams: { ref_name: ref, path, per_page: 1 } },
schema,
httpErrors: httpErrorsFor('project not found'),
})
}
async handle(
{ project },
{ gitlab_url: baseUrl = 'https://gitlab.com', ref, path },
) {
const data = await this.fetch({ project, baseUrl, ref, path })
const [commit] = data
if (!commit) throw new NotFound({ prettyMessage: 'no commits found' })
return renderDateBadge(commit.committed_date)
}
}
View on GitHub (pinned to 766fd8bc89)
Solutions
- Verify the project path in the badge URL points at a non-empty repository
- Check the `ref` parameter names an existing branch/tag with commits
- Remove or fix the `path` parameter if it filters out all commits
- Push at least one commit to the referenced branch
Example fix
// before /badge/last-commit/group/empty-project?ref=new-branch -> no commits found // after /badge/last-commit/group/project?ref=main
Defensive patterns
Strategy: try-catch
Validate before calling
const res = await fetch(`${baseUrl}/api/v4/projects/${encodeURIComponent(project)}/repository/commits?ref_name=${ref}`)
const commits = await res.json()
if (Array.isArray(commits) && commits.length === 0) throw new Error(`no commits for ref '${ref}'`) Type guard
const hasCommits = (data) => Array.isArray(data) && data.length > 0
Try / catch
try {
await fetchGitLabLastCommitBadge(project, ref, path)
} catch (e) {
if (e.message === 'no commits found') return 'unknown'
throw e
} Prevention
- Point the badge at a non-empty project and a ref that exists with commits
- Only use `path` when that path has history on the ref
- Verify empty repos/branches before adding last-commit badges
When it happens
Trigger: Fetching last-commit for an empty GitLab project; a `ref` matching no commits (unborn/empty branch); a `path` that has no commit history on that ref.
Common situations: Freshly created empty repository; badge pointing at a branch before its first commit; path filter referencing a non-existent directory/file; wrong ref name resolving to nothing.
Related errors
AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30).
Data as JSON: /api/errors/7f259445d6cb77bc.
Report an issue: GitHub.