Skip to content

Commit

Permalink
Merge pull request #46 from suba327777/main
Browse files Browse the repository at this point in the history
Merge main into release
  • Loading branch information
suba327777 authored Jun 29, 2024
2 parents 3759aa9 + b376364 commit fa9a592
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
14 changes: 3 additions & 11 deletions api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func MountainHandler() ([]byte, error) {
username := os.Getenv("USERNAME")
username := os.Getenv("USERNAME2")
if len(username) == 0 {
return nil, errors.New("USERNAME is not set")
}
Expand All @@ -32,17 +32,9 @@ func MountainHandler() ([]byte, error) {

endOfMonth := toDate.Day()
dailyCommitsMonthCount := dailyCommitsPeriodCount(user.DailyCommitsPeriod)
commitsMonthCount := commitsPeriodCount(user.DailyCommitsPeriod)

fromDate = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.UTC)
toDate = time.Date(time.Now().Year(), 12, 31, 23, 59, 59, 999999999, time.UTC)
user, err = getUserData(username, fromDate, toDate)
if err != nil {
return nil, err
}

commitsYearCount := commitsPeriodCount(user.DailyCommitsPeriod)

svg := ui.GenerateCard(username, dailyCommitsSince1MonthCount, dailyCommitsMonthCount, endOfMonth, commitsYearCount)
svg := ui.GenerateCard(username, dailyCommitsSince1MonthCount, dailyCommitsMonthCount, endOfMonth, commitsMonthCount)

return []byte(svg), nil
}
23 changes: 11 additions & 12 deletions ui/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@ func title(mountainIcon, textColor, username string) string {
`, mountainIcon, textColor, username)
}

func leftInfo(dailyCommitsMonthCount, endOfMonth int, treeIcon, climberIcon, textColor, formatCommitsYearCount string) string {
func leftInfo(dailyCommitsMonthCount, endOfMonth int, treeIcon, climberIcon, textColor, formatCommitsMonthCount string) string {
return fmt.Sprintf(`
<g>
<g>
<g transform="translate(5,75)">%s</g>
<text x="46" y="85" font-size="14" dominant-baseline="middle" text-anchor="start" fill="%s">Commit Day</text>
<text x="50" y="100" font-size="14" dominant-baseline="middle" text-anchor="start" fill="%s">Per Month</text>
<text x="135" y="90" font-size="13" dominant-baseline="middle" text-anchor="start" fill="%s">%d/%d</text>
<text x="45" y="85" font-size="13" dominant-baseline="middle" text-anchor="start" fill="%s">Commit Day</text>
<text x="49" y="100" font-size="13" dominant-baseline="middle" text-anchor="start" fill="%s">Per Month</text>
<text x="134" y="90" font-size="12" dominant-baseline="middle" text-anchor="start" fill="%s">%d/%d</text>
</g>
<g>
<g transform="translate(5,140)">%s</g> <text x="40" y="150" font-size="14" dominant-baseline="middle" text-anchor="start" fill="%s">Total Commits</text>
<text x="65" y="165" font-size="14" dominant-baseline="middle" text-anchor="start" fill="%s">(2024)</text>
<text x="140" y="155" font-size="13" dominant-baseline="middle" text-anchor="start" fill="%s">%s</text>
<g transform="translate(5,140)">%s</g> <text x="60" y="150" font-size="13" dominant-baseline="middle" text-anchor="start" fill="%s">Month</text>
<text x="55" y="165" font-size="13" dominant-baseline="middle" text-anchor="start" fill="%s">Commit</text>
<text x="145" y="155" font-size="12" dominant-baseline="middle" text-anchor="start" fill="%s">%s</text>
</g>
</g>
`, treeIcon, textColor, textColor, textColor, dailyCommitsMonthCount, endOfMonth, climberIcon, textColor, textColor, textColor, formatCommitsYearCount)
`, treeIcon, textColor, textColor, textColor, dailyCommitsMonthCount, endOfMonth, climberIcon, textColor, textColor, textColor, formatCommitsMonthCount)
}

func rightInfo(bgColor, borderColor, grass string) string {
Expand All @@ -56,20 +55,20 @@ func endSVG() string {
return `</svg>`
}

func GenerateCard(username string, dailyCommitsSince1MonthCount, dailyCommitsMonthCount, endOfMonth, commitsYearCount int) string {
func GenerateCard(username string, dailyCommitsSince1MonthCount, dailyCommitsMonthCount, endOfMonth, commitsMonthCount int) string {
themeName := os.Getenv("THEME")
theme := getTheme(themeName)

mountainIcon := changeIconColor(Mountain, theme.MountainIconColor)
climberIcon := changeIconColor(Climber, theme.IconColor)
treeIcon := changeIconColor(Tree, theme.IconColor)
grassMountain := generateMountain(dailyCommitsSince1MonthCount, theme.Name, theme.TriangleMountainColor)
formatCommitsYearCount := formatNumber(commitsYearCount)
formatCommitsMonthCount := formatNumber(commitsMonthCount)

svg := startSVG()
svg += rect(theme.BgColor, theme.BorderColor)
svg += title(mountainIcon, theme.TitleColor, username)
svg += leftInfo(dailyCommitsMonthCount, endOfMonth, treeIcon, climberIcon, theme.TextColor, formatCommitsYearCount)
svg += leftInfo(dailyCommitsMonthCount, endOfMonth, treeIcon, climberIcon, theme.TextColor, formatCommitsMonthCount)
svg += rightInfo(theme.BgColor, theme.BorderColor, grassMountain)
svg += endSVG()

Expand Down

0 comments on commit fa9a592

Please sign in to comment.