kopia lustrzana https://github.com/badgen/badgen.net
feat: use default branch for GitHub commits when appropriate #575
rodzic
4577691d66
commit
6410220e91
|
@ -279,7 +279,11 @@ const makeRepoQuery = (topic, owner, repo, restArgs) => {
|
||||||
break
|
break
|
||||||
case 'commits':
|
case 'commits':
|
||||||
queryBody = `
|
queryBody = `
|
||||||
branch: ref(qualifiedName: "${restArgs.ref || 'master'}") {
|
${
|
||||||
|
restArgs.ref
|
||||||
|
? `branch: ref(qualifiedName: "${restArgs.ref}")`
|
||||||
|
: 'defaultBranchRef'
|
||||||
|
} {
|
||||||
target {
|
target {
|
||||||
... on Commit {
|
... on Commit {
|
||||||
history(first: 0) {
|
history(first: 0) {
|
||||||
|
@ -292,7 +296,11 @@ const makeRepoQuery = (topic, owner, repo, restArgs) => {
|
||||||
break
|
break
|
||||||
case 'last-commit':
|
case 'last-commit':
|
||||||
queryBody = `
|
queryBody = `
|
||||||
branch: ref(qualifiedName: "${restArgs.ref || 'master'}") {
|
${
|
||||||
|
restArgs.ref ?
|
||||||
|
`branch: ref(qualifiedName: "${restArgs.ref}")` :
|
||||||
|
'defaultBranchRef'
|
||||||
|
} {
|
||||||
target {
|
target {
|
||||||
... on Commit {
|
... on Commit {
|
||||||
history(first: 1) {
|
history(first: 1) {
|
||||||
|
@ -442,7 +450,11 @@ async function repoStats ({topic, owner, repo, ...restArgs}: PathArgs) {
|
||||||
case 'commits':
|
case 'commits':
|
||||||
return {
|
return {
|
||||||
subject: topic,
|
subject: topic,
|
||||||
status: millify(result.branch.target.history.totalCount),
|
status: millify(
|
||||||
|
result.branch ?
|
||||||
|
result.branch.target.history.totalCount :
|
||||||
|
result.defaultBranchRef.target.history.totalCount
|
||||||
|
),
|
||||||
color: 'blue'
|
color: 'blue'
|
||||||
}
|
}
|
||||||
case 'tag':
|
case 'tag':
|
||||||
|
@ -461,7 +473,8 @@ async function repoStats ({topic, owner, repo, ...restArgs}: PathArgs) {
|
||||||
// color: li ? 'blue' : 'grey'
|
// color: li ? 'blue' : 'grey'
|
||||||
// }
|
// }
|
||||||
case 'last-commit':
|
case 'last-commit':
|
||||||
const commits = result.branch.target.history.nodes
|
const branch = result.branch || result.defaultBranchRef
|
||||||
|
const commits = branch.target.history.nodes
|
||||||
const lastDate = commits.length && new Date(commits[0].committedDate)
|
const lastDate = commits.length && new Date(commits[0].committedDate)
|
||||||
const fromNow = lastDate && distanceToNow(lastDate, { addSuffix: true })
|
const fromNow = lastDate && distanceToNow(lastDate, { addSuffix: true })
|
||||||
return {
|
return {
|
||||||
|
|
Ładowanie…
Reference in New Issue