feat(package): gitea: add heatmap contribution model

This commit is contained in:
2026-06-06 19:20:37 +00:00
parent 3299daf061
commit 53dfd60b4c
5 changed files with 210 additions and 0 deletions
@@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"strconv"
"strings"
"code.gitea.io/gitea/models/db"
@@ -19,6 +20,8 @@ import (
"xorm.io/xorm/convert"
)
const SettingsKeyIncludePrivateContributions = "include_private_contributions"
// Setting is a key value store of user settings
type Setting struct {
ID int64 `xorm:"pk autoincr"`
@@ -254,3 +257,17 @@ func SetUserSettingJSON[T any](ctx context.Context, userID int64, key string, va
}
return SetUserSetting(ctx, userID, key, util.UnsafeBytesToString(bs))
}
// GetIncludePrivateContributions returns whether a user opted in to private heatmap contributions.
func GetIncludePrivateContributions(ctx context.Context, userID int64) (bool, error) {
value, err := GetUserSetting(ctx, userID, SettingsKeyIncludePrivateContributions, "false")
if err != nil {
return false, err
}
return strconv.ParseBool(value)
}
// SetIncludePrivateContributions stores whether a user opted in to private heatmap contributions.
func SetIncludePrivateContributions(ctx context.Context, userID int64, include bool) error {
return SetUserSetting(ctx, userID, SettingsKeyIncludePrivateContributions, strconv.FormatBool(include))
}