Skip to content

Commit

Permalink
update download-svgs
Browse files Browse the repository at this point in the history
  • Loading branch information
gernotstarke committed Dec 9, 2023
1 parent fa36349 commit fc66534
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
13 changes: 2 additions & 11 deletions cmd/downloadBadgeSVGs/get-badges-from-shields.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,20 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Load shields.io badges</title>



</head>
<body>


<h1>Welcome to shields.io badges for arc42 status-page</h1>


<img src="https://img.shields.io/badge/open_issues-CEA41E"/>
<img src="https://img.shields.io/badge/20-open_issues-CEA41E"/>
<img src="https://img.shields.io/badge/20+-open_issues-CEA41E"/>


<img src="https://img.shields.io/badge/issues-6-BDB76B"/>
<img src="https://img.shields.io/badge/issues-7-BDB76B"/>
<img src="https://img.shields.io/badge/issues-8-BDB76B"/>
<img src="https://img.shields.io/badge/issues-9-BDB76B"/>
<img src="https://img.shields.io/badge/issues-10-BDB76B"/>
<img src="https://img.shields.io/badge/issues-11-BDB76B"/>
<img src="https://img.shields.io/badge/issues-12-BDB76B"/>
<img src="https://img.shields.io/badge/issues-13-BDB76B"/>
<img src="https://img.shields.io/badge/issues-14-BDB76B"/>
<img src="https://img.shields.io/badge/issues-...-BDB76B"/>

<h2>Bugs</h2>
<img src="https://img.shields.io/badge/bugs-1-DC143C"/>
Expand Down
23 changes: 9 additions & 14 deletions cmd/downloadBadgeSVGs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,19 @@ import (
// SVGBadgePath is the constant path to the directory where SVG files for badges are stored.
const SVGBadgePath = "./svgs/"

const IssueBadgeFileNameSuffix = "-issues.svg"
const BugBadgeFileNameSuffix = "-bugs.svg"

const issuesColor = "CEA41E"
const bugsColor = "DC143C"

const issueName = "issue"
const bugName = "bug"

const badgeDownloadURLPrefix = "https://img.shields.io/badge/"

// svgFileNameForKindOf creates the filename for the downloaded issue-svg files.
// These are required both for the downloading process AND for creating the URLs in the final output HTML
func svgFileNameForKindOf(kindOf string, count int) string {
switch kindOf {
case issueName:
return strconv.Itoa(count) + IssueBadgeFileNameSuffix
case bugName:
return strconv.Itoa(count) + BugBadgeFileNameSuffix
case badge.IssueName:
return strconv.Itoa(count) + badge.IssueBadgeFileNameSuffix
case badge.BugName:
return strconv.Itoa(count) + badge.BugBadgeFileNameSuffix
default:
log.Error().Msgf("error creating filename for count %d and kindOf %s", count, kindOf)
return "_error-" + strconv.Itoa(count)
Expand All @@ -49,9 +44,9 @@ func svgFileNameForKindOf(kindOf string, count int) string {

func badgeColorForKindOf(kindOf string) string {
switch kindOf {
case issueName:
case badge.IssueName:
return issuesColor
case bugName:
case badge.BugName:
return bugsColor
default:
return issuesColor
Expand Down Expand Up @@ -138,7 +133,7 @@ func main() {
// so we have a filesystem location to store SVG files
createSVGBadgeDirIfNotPresent(SVGBadgePath)

downloadSVGBadgesForKindof(issueName)
downloadSVGBadgesForKindof(bugName)
downloadSVGBadgesForKindof(badge.IssueName)
downloadSVGBadgesForKindof(badge.BugName)

}
17 changes: 12 additions & 5 deletions internal/badge/badges.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import (
"strconv"
)

const ShieldsGithubIssuesURL = "https://img.shields.io/github/issues-raw/arc42/"
// after ADR-0006, we don't need the following URLs any more:
// const ShieldsGithubIssuesURL = "https://img.shields.io/github/issues-raw/arc42/"
// const ShieldsGithubBugsURLPrefix = "https://img.shields.io/github/issues-search/arc42/"
// const ShieldsBugSuffix = "?query=label%3Abug%20is%3Aopen&label=bugs&color=red"

const ShieldsGithubBugsURLPrefix = "https://img.shields.io/github/issues-search/arc42/"
const ShieldsBugSuffix = "?query=label%3Abug%20is%3Aopen&label=bugs&color=red"
const IssueName = "issue"
const BugName = "bug"

const IssueBadgeFileNameSuffix = "-issues.svg"
const BugBadgeFileNameSuffix = "-bugs.svg"

// LocalBadgeLocation is the constant for the file path of local badge images.
// we use these local versions to save remote-requests to shields.io
Expand All @@ -24,8 +30,9 @@ const LocalBugBadgePrefix = LocalBadgeLocation + "bugs-" +
""
const LocalBadgeSvgThreshold = 20

// bugBadgeURL returns a badge URL, which is either a local URL or a hyperlink to shields.io.
// if the bug-count is >= 0, create a link to a badge, otherwise NO bug badge shall be shown.
// bugBadgeURL returns a badge URL, which always refers to a local image
// as these have been pre-generated (see ADR-0006)
// if the nrOfBugs is >= 0, create a link to a badge, otherwise NO bug badge shall be shown.
func bugBadgeURL(site string, nrOfBugs int) string {

// shields.io bug URLS look like that:https://img.shields.io/github/issues-search/arc42/quality.arc42.org-site?query=label%3Abug%20is%3Aopen&label=bugs&color=red
Expand Down

0 comments on commit fc66534

Please sign in to comment.