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
|
||||
case 'commits':
|
||||
queryBody = `
|
||||
branch: ref(qualifiedName: "${restArgs.ref || 'master'}") {
|
||||
${
|
||||
restArgs.ref
|
||||
? `branch: ref(qualifiedName: "${restArgs.ref}")`
|
||||
: 'defaultBranchRef'
|
||||
} {
|
||||
target {
|
||||
... on Commit {
|
||||
history(first: 0) {
|
||||
|
@ -292,7 +296,11 @@ const makeRepoQuery = (topic, owner, repo, restArgs) => {
|
|||
break
|
||||
case 'last-commit':
|
||||
queryBody = `
|
||||
branch: ref(qualifiedName: "${restArgs.ref || 'master'}") {
|
||||
${
|
||||
restArgs.ref ?
|
||||
`branch: ref(qualifiedName: "${restArgs.ref}")` :
|
||||
'defaultBranchRef'
|
||||
} {
|
||||
target {
|
||||
... on Commit {
|
||||
history(first: 1) {
|
||||
|
@ -442,7 +450,11 @@ async function repoStats ({topic, owner, repo, ...restArgs}: PathArgs) {
|
|||
case 'commits':
|
||||
return {
|
||||
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'
|
||||
}
|
||||
case 'tag':
|
||||
|
@ -461,7 +473,8 @@ async function repoStats ({topic, owner, repo, ...restArgs}: PathArgs) {
|
|||
// color: li ? 'blue' : 'grey'
|
||||
// }
|
||||
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 fromNow = lastDate && distanceToNow(lastDate, { addSuffix: true })
|
||||
return {
|
||||
|
|
Ładowanie…
Reference in New Issue