Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions pages/api/codecov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default createBadgenHandler({
title: 'CodeCov',
examples: {
'/codecov/github/babel/babel': 'coverage (github)',
'/codecov/github/babel/babel/6.x': 'coverage (github, branch)',
'/codecov/github/babel/babel/7.x': 'coverage (github, branch)',
'/codecov/bitbucket/ignitionrobotics/ign-math': 'coverage (bitbucket)',
'/codecov/bitbucket/ignitionrobotics/ign-math/master': 'coverage (bitbucket, branch)',
'/codecov/gitlab/gitlab-org/gitaly': 'coverage (gitlab)',
Expand All @@ -19,19 +19,20 @@ export default createBadgenHandler({
})

async function handler ({ vcs, owner, repo, branch }: PathArgs) {
const endpoint = `https://codecov.io/api/v2/${vcs}/${owner}/repos/${repo}?format=json`

const endpoint = `https://api.codecov.io/api/v2/${vcs}/${owner}/repos/${repo}${branch ? `/branches/${branch}` : ``}?format=json`
const data = await got(endpoint).json<any>()

if (!data.totals) {
const totals = branch ? data.head_commit?.totals : data.totals

if (!totals) {
return {
subject: 'codecov',
status: 'unknown',
color: 'grey'
}
}

const cov = data.totals?.coverage || 0
const cov = totals?.coverage || 0
return {
subject: 'coverage',
status: coverage(cov),
Expand Down
Loading