kopia lustrzana https://github.com/badgen/badgen.net
				
				
				
			chore: use public/free github api to avoid hitting rate limit (#605)
							rodzic
							
								
									e35c8ff1ea
								
							
						
					
					
						commit
						169ae69aae
					
				| 
						 | 
					@ -171,6 +171,11 @@ async function contributors ({ owner, repo }: PathArgs) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					async function meta ({ owner, repo }: PathArgs): Promise<any> {
 | 
				
			||||||
 | 
					  const meta = await got(`https://api.github.com/repos/${owner}/${repo}`).json()
 | 
				
			||||||
 | 
					  return meta
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function downloads ({ owner, repo, tag }: PathArgs) {
 | 
					async function downloads ({ owner, repo, tag }: PathArgs) {
 | 
				
			||||||
  const releaseSelection = tag ? `tags/${tag}` : 'latest'
 | 
					  const releaseSelection = tag ? `tags/${tag}` : 'latest'
 | 
				
			||||||
  const release = await restGithub(`repos/${owner}/${repo}/releases/${releaseSelection}`)
 | 
					  const release = await restGithub(`repos/${owner}/${repo}/releases/${releaseSelection}`)
 | 
				
			||||||
| 
						 | 
					@ -328,6 +333,45 @@ const makeRepoQuery = (topic, owner, repo, restArgs) => {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function repoStats ({topic, owner, repo, ...restArgs}: PathArgs) {
 | 
					async function repoStats ({topic, owner, repo, ...restArgs}: PathArgs) {
 | 
				
			||||||
 | 
					  switch (topic) {
 | 
				
			||||||
 | 
					    case 'forks':
 | 
				
			||||||
 | 
					      const { forks } = await meta({ owner, repo })
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        subject: topic,
 | 
				
			||||||
 | 
					        status: millify(forks),
 | 
				
			||||||
 | 
					        color: 'blue'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    case 'watchers':
 | 
				
			||||||
 | 
					      const { watchers_count } = await meta({ owner, repo })
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        subject: topic,
 | 
				
			||||||
 | 
					        status: millify(watchers_count),
 | 
				
			||||||
 | 
					        color: 'blue'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    case 'open-issues':
 | 
				
			||||||
 | 
					      const { open_issues_count } = await meta({ owner, repo })
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        subject: topic,
 | 
				
			||||||
 | 
					        status: millify(open_issues_count),
 | 
				
			||||||
 | 
					        color: 'blue'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    case 'stars':
 | 
				
			||||||
 | 
					      const { stargazers_count } = await meta({ owner, repo })
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        subject: topic,
 | 
				
			||||||
 | 
					        status: millify(stargazers_count),
 | 
				
			||||||
 | 
					        color: 'blue'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    case 'license':
 | 
				
			||||||
 | 
					      const { license } = await meta({ owner, repo })
 | 
				
			||||||
 | 
					      return {
 | 
				
			||||||
 | 
					        subject: topic,
 | 
				
			||||||
 | 
					        status: license ? license.spdx_id : 'no license',
 | 
				
			||||||
 | 
					        color: license ? 'blue' : 'grey'
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Use graphql when we cannot simply get info from public/free api
 | 
				
			||||||
  const result = await makeRepoQuery(topic, owner, repo, restArgs)
 | 
					  const result = await makeRepoQuery(topic, owner, repo, restArgs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!result) {
 | 
					  if (!result) {
 | 
				
			||||||
| 
						 | 
					@ -339,8 +383,6 @@ async function repoStats ({topic, owner, repo, ...restArgs}: PathArgs) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  switch (topic) {
 | 
					  switch (topic) {
 | 
				
			||||||
    case 'watchers':
 | 
					 | 
				
			||||||
    case 'forks':
 | 
					 | 
				
			||||||
    case 'issues':
 | 
					    case 'issues':
 | 
				
			||||||
    case 'releases':
 | 
					    case 'releases':
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
| 
						 | 
					@ -355,18 +397,12 @@ async function repoStats ({topic, owner, repo, ...restArgs}: PathArgs) {
 | 
				
			||||||
        status: millify(result.refs.totalCount),
 | 
					        status: millify(result.refs.totalCount),
 | 
				
			||||||
        color: 'blue'
 | 
					        color: 'blue'
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    case 'stars':
 | 
					    // case 'open-issues':
 | 
				
			||||||
      return {
 | 
					    //   return {
 | 
				
			||||||
        subject: topic,
 | 
					    //     subject: 'open issues',
 | 
				
			||||||
        status: millify(result.stargazers.totalCount),
 | 
					    //     status: millify(result.issues.totalCount),
 | 
				
			||||||
        color: 'blue'
 | 
					    //     color: result.issues.totalCount === 0 ? 'green' : 'orange'
 | 
				
			||||||
      }
 | 
					    //   }
 | 
				
			||||||
    case 'open-issues':
 | 
					 | 
				
			||||||
      return {
 | 
					 | 
				
			||||||
        subject: 'open issues',
 | 
					 | 
				
			||||||
        status: millify(result.issues.totalCount),
 | 
					 | 
				
			||||||
        color: result.issues.totalCount === 0 ? 'green' : 'orange'
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    case 'closed-issues':
 | 
					    case 'closed-issues':
 | 
				
			||||||
      return {
 | 
					      return {
 | 
				
			||||||
        subject: 'closed issues',
 | 
					        subject: 'closed issues',
 | 
				
			||||||
| 
						 | 
					@ -417,13 +453,13 @@ async function repoStats ({topic, owner, repo, ...restArgs}: PathArgs) {
 | 
				
			||||||
        status: version(latestTag),
 | 
					        status: version(latestTag),
 | 
				
			||||||
        color: 'blue'
 | 
					        color: 'blue'
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    case 'license':
 | 
					    // case 'license':
 | 
				
			||||||
      const li = result.licenseInfo
 | 
					    //   const li = result.licenseInfo
 | 
				
			||||||
      return {
 | 
					    //   return {
 | 
				
			||||||
        subject: topic,
 | 
					    //     subject: topic,
 | 
				
			||||||
        status: li ? li.spdxId : 'no license',
 | 
					    //     status: li ? li.spdxId : 'no license',
 | 
				
			||||||
        color: li ? 'blue' : 'grey'
 | 
					    //     color: li ? 'blue' : 'grey'
 | 
				
			||||||
      }
 | 
					    //   }
 | 
				
			||||||
    case 'last-commit':
 | 
					    case 'last-commit':
 | 
				
			||||||
      const commits = result.branch.target.history.nodes
 | 
					      const commits = result.branch.target.history.nodes
 | 
				
			||||||
      const lastDate = commits.length && new Date(commits[0].committedDate)
 | 
					      const lastDate = commits.length && new Date(commits[0].committedDate)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Ładowanie…
	
		Reference in New Issue