Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into release #46

Merged
merged 3 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading