Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a66f88e0bf | |||
| 58782a3920 | |||
| 53b7e378d1 | |||
| ad78bb7c27 | |||
| ff016ed888 | |||
| 33fd9c5620 | |||
| d300cde639 | |||
| 05f1ac1a12 |
@@ -0,0 +1,9 @@
|
||||
---
|
||||
name: ".mokogitea Test Template"
|
||||
about: "Verify .mokogitea issue templates work"
|
||||
labels: ["test"]
|
||||
---
|
||||
|
||||
This template was loaded from `.mokogitea/ISSUE_TEMPLATE/`.
|
||||
|
||||
If you can see this, the `.mokogitea` dot-folder feature is working.
|
||||
@@ -0,0 +1,12 @@
|
||||
# Test workflow to verify .mokogitea/ directory is discovered
|
||||
name: Test .mokogitea workflows
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Verify .mokogitea
|
||||
run: echo "This workflow ran from .mokogitea/workflows/ — feature works!"
|
||||
@@ -6,6 +6,7 @@ package activities
|
||||
import (
|
||||
"context"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
||||
"code.gitea.io/gitea/models/auth"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
@@ -18,6 +19,7 @@ import (
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/optional"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
)
|
||||
@@ -37,6 +39,11 @@ type Statistic struct {
|
||||
Branches, Tags, CommitStatus int64
|
||||
IssueByLabel []IssueByLabelCount
|
||||
IssueByRepository []IssueByRepositoryCount
|
||||
|
||||
// MokoGitea extended metrics
|
||||
ActiveUsers30d int64
|
||||
ActionsQueueLength int64
|
||||
ActionsRunningJobs int64
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,5 +138,19 @@ func GetStatistic(ctx context.Context) (stats Statistic) {
|
||||
stats.Counter.Attachment, _ = e.Count(new(repo_model.Attachment))
|
||||
stats.Counter.Project, _ = e.Count(new(project_model.Project))
|
||||
stats.Counter.ProjectColumn, _ = e.Count(new(project_model.Column))
|
||||
|
||||
// MokoGitea extended metrics
|
||||
// Active users in last 30 days (users who performed any action)
|
||||
stats.Counter.ActiveUsers30d, _ = e.Where("last_login_unix > ?",
|
||||
timeutil.TimeStampNow()-30*24*60*60).Count(new(user_model.User))
|
||||
|
||||
// Actions queue and running jobs (if actions enabled)
|
||||
if setting.Actions.Enabled {
|
||||
stats.Counter.ActionsQueueLength, _ = e.Where("status = ?", 1). // StatusWaiting
|
||||
Count(new(actions_model.ActionRunJob))
|
||||
stats.Counter.ActionsRunningJobs, _ = e.Where("status = ?", 2). // StatusRunning
|
||||
Count(new(actions_model.ActionRunJob))
|
||||
}
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
@@ -46,6 +46,11 @@ type Collector struct {
|
||||
Users *prometheus.Desc
|
||||
Watches *prometheus.Desc
|
||||
Webhooks *prometheus.Desc
|
||||
|
||||
// MokoGitea extended metrics
|
||||
ActiveUsers30d *prometheus.Desc
|
||||
ActionsQueueLength *prometheus.Desc
|
||||
ActionsRunningJobs *prometheus.Desc
|
||||
}
|
||||
|
||||
// NewCollector returns a new Collector with all prometheus.Desc initialized
|
||||
@@ -196,6 +201,21 @@ func NewCollector() Collector {
|
||||
"Number of Webhooks",
|
||||
nil, nil,
|
||||
),
|
||||
ActiveUsers30d: prometheus.NewDesc(
|
||||
namespace+"active_users_30d",
|
||||
"Number of active users in the last 30 days",
|
||||
nil, nil,
|
||||
),
|
||||
ActionsQueueLength: prometheus.NewDesc(
|
||||
namespace+"actions_queue_length",
|
||||
"Number of actions jobs waiting to run",
|
||||
nil, nil,
|
||||
),
|
||||
ActionsRunningJobs: prometheus.NewDesc(
|
||||
namespace+"actions_running_jobs",
|
||||
"Number of actions jobs currently running",
|
||||
nil, nil,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,6 +249,9 @@ func (c Collector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- c.Users
|
||||
ch <- c.Watches
|
||||
ch <- c.Webhooks
|
||||
ch <- c.ActiveUsers30d
|
||||
ch <- c.ActionsQueueLength
|
||||
ch <- c.ActionsRunningJobs
|
||||
}
|
||||
|
||||
// Collect returns the metrics with values
|
||||
@@ -392,4 +415,21 @@ func (c Collector) Collect(ch chan<- prometheus.Metric) {
|
||||
prometheus.GaugeValue,
|
||||
float64(stats.Counter.Webhook),
|
||||
)
|
||||
|
||||
// MokoGitea extended metrics
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.ActiveUsers30d,
|
||||
prometheus.GaugeValue,
|
||||
float64(stats.Counter.ActiveUsers30d),
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.ActionsQueueLength,
|
||||
prometheus.GaugeValue,
|
||||
float64(stats.Counter.ActionsQueueLength),
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.ActionsRunningJobs,
|
||||
prometheus.GaugeValue,
|
||||
float64(stats.Counter.ActionsRunningJobs),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package setting
|
||||
|
||||
// Ntfy holds ntfy push notification settings.
|
||||
var Ntfy = struct {
|
||||
Enabled bool
|
||||
ServerURL string
|
||||
DefaultTopic string
|
||||
Token string
|
||||
}{
|
||||
Enabled: false,
|
||||
ServerURL: "https://ntfy.mokoconsulting.tech",
|
||||
DefaultTopic: "mokogitea",
|
||||
}
|
||||
|
||||
func loadNtfyFrom(cfg ConfigProvider) {
|
||||
sec := cfg.Section("ntfy")
|
||||
Ntfy.Enabled = sec.Key("ENABLED").MustBool(false)
|
||||
Ntfy.ServerURL = sec.Key("SERVER_URL").MustString(Ntfy.ServerURL)
|
||||
Ntfy.DefaultTopic = sec.Key("DEFAULT_TOPIC").MustString(Ntfy.DefaultTopic)
|
||||
Ntfy.Token = sec.Key("TOKEN").String()
|
||||
}
|
||||
@@ -28,6 +28,15 @@ var (
|
||||
CfgProvider ConfigProvider
|
||||
IsWindows bool
|
||||
|
||||
// UpdateChecker configuration for MokoGitea version checking
|
||||
UpdateChecker = struct {
|
||||
Enabled bool
|
||||
Endpoint string
|
||||
}{
|
||||
Enabled: true,
|
||||
Endpoint: "https://git.mokoconsulting.tech/api/v1/repos/MokoConsulting/MokoGitea/releases/latest",
|
||||
}
|
||||
|
||||
// IsInTesting indicates whether the testing is running (unit test or integration test). It can be used for:
|
||||
// * Skip nonsense error logs during testing caused by unreliable code (TODO: this is only a temporary solution, we should make the test code more reliable)
|
||||
// * Panic in dev or testing mode to make the problem more obvious and easier to debug
|
||||
@@ -158,9 +167,17 @@ func loadCommonSettingsFrom(cfg ConfigProvider) error {
|
||||
loadMarkupFrom(cfg)
|
||||
loadGlobalLockFrom(cfg)
|
||||
loadOtherFrom(cfg)
|
||||
loadUpdateCheckerFrom(cfg)
|
||||
loadNtfyFrom(cfg)
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadUpdateCheckerFrom(cfg ConfigProvider) {
|
||||
sec := cfg.Section("update_checker")
|
||||
UpdateChecker.Enabled = sec.Key("ENABLED").MustBool(true)
|
||||
UpdateChecker.Endpoint = sec.Key("ENDPOINT").MustString(UpdateChecker.Endpoint)
|
||||
}
|
||||
|
||||
func loadRunModeFrom(rootCfg ConfigProvider) {
|
||||
rootSec := rootCfg.Section("")
|
||||
RunUser = rootSec.Key("RUN_USER").MustString(user.CurrentUsername())
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
// Copyright 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package updatechecker
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
// UpdateInfo holds the result of the latest update check.
|
||||
type UpdateInfo struct {
|
||||
UpdateAvailable bool
|
||||
LatestVersion string
|
||||
ReleaseURL string
|
||||
CheckedAt time.Time
|
||||
}
|
||||
|
||||
var (
|
||||
cachedInfo *UpdateInfo
|
||||
mu sync.RWMutex
|
||||
)
|
||||
|
||||
// giteaRelease is the subset of Gitea's release API response we need.
|
||||
type giteaRelease struct {
|
||||
TagName string `json:"tag_name"`
|
||||
HTMLURL string `json:"html_url"`
|
||||
Draft bool `json:"draft"`
|
||||
}
|
||||
|
||||
// CheckForUpdate fetches the latest release from the configured endpoint
|
||||
// and compares it to the running version.
|
||||
func CheckForUpdate() error {
|
||||
if !setting.UpdateChecker.Enabled || setting.UpdateChecker.Endpoint == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
client := &http.Client{Timeout: 15 * time.Second}
|
||||
resp, err := client.Get(setting.UpdateChecker.Endpoint)
|
||||
if err != nil {
|
||||
return fmt.Errorf("update check failed: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("update check returned status %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading update response: %w", err)
|
||||
}
|
||||
|
||||
var release giteaRelease
|
||||
if err := json.Unmarshal(body, &release); err != nil {
|
||||
return fmt.Errorf("parsing update response: %w", err)
|
||||
}
|
||||
|
||||
if release.Draft || release.TagName == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
latestVersion := strings.TrimPrefix(release.TagName, "v")
|
||||
currentVersion := setting.AppVer
|
||||
|
||||
info := &UpdateInfo{
|
||||
LatestVersion: latestVersion,
|
||||
ReleaseURL: release.HTMLURL,
|
||||
CheckedAt: time.Now(),
|
||||
}
|
||||
|
||||
// Simple comparison: if latest != current, update is available.
|
||||
// This handles both upgrades and the case where versions differ
|
||||
// in any way (patch, upstream bump, etc.)
|
||||
info.UpdateAvailable = latestVersion != "" && !strings.HasPrefix(currentVersion, latestVersion)
|
||||
|
||||
mu.Lock()
|
||||
cachedInfo = info
|
||||
mu.Unlock()
|
||||
|
||||
if info.UpdateAvailable {
|
||||
log.Info("MokoGitea update available: %s (current: %s)", latestVersion, currentVersion)
|
||||
} else {
|
||||
log.Debug("MokoGitea is up to date: %s", currentVersion)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUpdateInfo returns the cached update check result.
|
||||
func GetUpdateInfo() *UpdateInfo {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
if cachedInfo == nil {
|
||||
return &UpdateInfo{}
|
||||
}
|
||||
return cachedInfo
|
||||
}
|
||||
+2
@@ -617,6 +617,7 @@
|
||||
"__github/workflows__": "folder-gh-workflows",
|
||||
"gitea/workflows": "folder-gitea-workflows",
|
||||
".gitea/workflows": "folder-gitea-workflows",
|
||||
".mokogitea/workflows": "folder-gitea-workflows",
|
||||
"_gitea/workflows": "folder-gitea-workflows",
|
||||
"-gitea/workflows": "folder-gitea-workflows",
|
||||
"__gitea/workflows__": "folder-gitea-workflows",
|
||||
@@ -5237,6 +5238,7 @@
|
||||
"__github/workflows__": "folder-gh-workflows-open",
|
||||
"gitea/workflows": "folder-gitea-workflows-open",
|
||||
".gitea/workflows": "folder-gitea-workflows-open",
|
||||
".mokogitea/workflows": "folder-gitea-workflows-open",
|
||||
"_gitea/workflows": "folder-gitea-workflows-open",
|
||||
"-gitea/workflows": "folder-gitea-workflows-open",
|
||||
"__gitea/workflows__": "folder-gitea-workflows-open",
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/updatechecker"
|
||||
"code.gitea.io/gitea/modules/templates"
|
||||
"code.gitea.io/gitea/modules/web"
|
||||
"code.gitea.io/gitea/services/context"
|
||||
@@ -135,8 +136,13 @@ func prepareStartupProblemsAlert(ctx *context.Context) {
|
||||
func Dashboard(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("admin.dashboard")
|
||||
ctx.Data["PageIsAdminDashboard"] = true
|
||||
// MokoGitea: upstream update checker removed — this is an independent fork
|
||||
ctx.Data["NeedUpdate"] = false
|
||||
|
||||
// MokoGitea update checker
|
||||
info := updatechecker.GetUpdateInfo()
|
||||
ctx.Data["NeedUpdate"] = info.UpdateAvailable
|
||||
ctx.Data["LatestVersion"] = info.LatestVersion
|
||||
ctx.Data["ReleaseURL"] = info.ReleaseURL
|
||||
|
||||
updateSystemStatus()
|
||||
ctx.Data["SysStatus"] = sysStatus
|
||||
ctx.Data["SSH"] = setting.SSH
|
||||
|
||||
@@ -58,6 +58,12 @@ var IssueTemplateCandidates = []string{
|
||||
"issue_template.md",
|
||||
"issue_template.yaml",
|
||||
"issue_template.yml",
|
||||
".mokogitea/ISSUE_TEMPLATE.md",
|
||||
".mokogitea/ISSUE_TEMPLATE.yaml",
|
||||
".mokogitea/ISSUE_TEMPLATE.yml",
|
||||
".mokogitea/issue_template.md",
|
||||
".mokogitea/issue_template.yaml",
|
||||
".mokogitea/issue_template.yml",
|
||||
".gitea/ISSUE_TEMPLATE.md",
|
||||
".gitea/ISSUE_TEMPLATE.yaml",
|
||||
".gitea/ISSUE_TEMPLATE.yml",
|
||||
|
||||
@@ -71,6 +71,12 @@ var pullRequestTemplateCandidates = []string{
|
||||
"pull_request_template.md",
|
||||
"pull_request_template.yaml",
|
||||
"pull_request_template.yml",
|
||||
".mokogitea/PULL_REQUEST_TEMPLATE.md",
|
||||
".mokogitea/PULL_REQUEST_TEMPLATE.yaml",
|
||||
".mokogitea/PULL_REQUEST_TEMPLATE.yml",
|
||||
".mokogitea/pull_request_template.md",
|
||||
".mokogitea/pull_request_template.yaml",
|
||||
".mokogitea/pull_request_template.yml",
|
||||
".gitea/PULL_REQUEST_TEMPLATE.md",
|
||||
".gitea/PULL_REQUEST_TEMPLATE.yaml",
|
||||
".gitea/PULL_REQUEST_TEMPLATE.yml",
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/models/webhook"
|
||||
"code.gitea.io/gitea/modules/git/gitcmd"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/updatechecker"
|
||||
"code.gitea.io/gitea/services/auth"
|
||||
"code.gitea.io/gitea/services/migrations"
|
||||
mirror_service "code.gitea.io/gitea/services/mirror"
|
||||
@@ -183,4 +184,17 @@ func initBasicTasks() {
|
||||
registerCleanupPackages()
|
||||
}
|
||||
registerSyncRepoLicenses()
|
||||
if setting.UpdateChecker.Enabled {
|
||||
registerUpdateChecker()
|
||||
}
|
||||
}
|
||||
|
||||
func registerUpdateChecker() {
|
||||
RegisterTaskFatal("update_checker", &BaseConfig{
|
||||
Enabled: true,
|
||||
RunAtStart: true,
|
||||
Schedule: "@every 24h",
|
||||
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
||||
return updatechecker.CheckForUpdate()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import (
|
||||
var templateDirCandidates = []string{
|
||||
"ISSUE_TEMPLATE",
|
||||
"issue_template",
|
||||
".mokogitea/ISSUE_TEMPLATE",
|
||||
".mokogitea/issue_template",
|
||||
".gitea/ISSUE_TEMPLATE",
|
||||
".gitea/issue_template",
|
||||
".github/ISSUE_TEMPLATE",
|
||||
@@ -32,6 +34,8 @@ var templateDirCandidates = []string{
|
||||
}
|
||||
|
||||
var templateConfigCandidates = []string{
|
||||
".mokogitea/ISSUE_TEMPLATE/config",
|
||||
".mokogitea/issue_template/config",
|
||||
".gitea/ISSUE_TEMPLATE/config",
|
||||
".gitea/issue_template/config",
|
||||
".github/ISSUE_TEMPLATE/config",
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
// Copyright 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package ntfy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
issues_model "code.gitea.io/gitea/models/issues"
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
notify_service "code.gitea.io/gitea/services/notify"
|
||||
)
|
||||
|
||||
func init() {
|
||||
if setting.Ntfy.Enabled {
|
||||
notify_service.RegisterNotifier(NewNotifier())
|
||||
}
|
||||
}
|
||||
|
||||
type ntfyNotifier struct {
|
||||
notify_service.NullNotifier
|
||||
}
|
||||
|
||||
// NewNotifier creates a new ntfy notifier.
|
||||
func NewNotifier() notify_service.Notifier {
|
||||
return &ntfyNotifier{}
|
||||
}
|
||||
|
||||
func (*ntfyNotifier) Run() {}
|
||||
|
||||
func repoTopic(repo *repo_model.Repository) string {
|
||||
if repo == nil {
|
||||
return setting.Ntfy.DefaultTopic
|
||||
}
|
||||
return setting.Ntfy.DefaultTopic
|
||||
}
|
||||
|
||||
func (*ntfyNotifier) NewIssue(_ context.Context, issue *issues_model.Issue, _ []*user_model.User) {
|
||||
_ = issue.LoadRepo(context.Background())
|
||||
SendAsync(repoTopic(issue.Repo),
|
||||
fmt.Sprintf("New Issue: %s", issue.Title),
|
||||
fmt.Sprintf("#%d in %s\n%s", issue.Index, issue.Repo.FullName(), issue.Content),
|
||||
"default",
|
||||
"issue,new")
|
||||
}
|
||||
|
||||
func (*ntfyNotifier) IssueChangeStatus(_ context.Context, doer *user_model.User, _ string, issue *issues_model.Issue, _ *issues_model.Comment, closeOrReopen bool) {
|
||||
_ = issue.LoadRepo(context.Background())
|
||||
action := "reopened"
|
||||
if !closeOrReopen {
|
||||
action = "closed"
|
||||
}
|
||||
SendAsync(repoTopic(issue.Repo),
|
||||
fmt.Sprintf("Issue %s: %s", action, issue.Title),
|
||||
fmt.Sprintf("#%d %s by %s", issue.Index, action, doer.Name),
|
||||
"low",
|
||||
"issue,"+action)
|
||||
}
|
||||
|
||||
func (*ntfyNotifier) NewPullRequest(_ context.Context, pr *issues_model.PullRequest, _ []*user_model.User) {
|
||||
_ = pr.LoadIssue(context.Background())
|
||||
_ = pr.Issue.LoadRepo(context.Background())
|
||||
SendAsync(repoTopic(pr.Issue.Repo),
|
||||
fmt.Sprintf("New PR: %s", pr.Issue.Title),
|
||||
fmt.Sprintf("#%d in %s\n%s → %s", pr.Issue.Index, pr.Issue.Repo.FullName(), pr.HeadBranch, pr.BaseBranch),
|
||||
"default",
|
||||
"git-pull-request,new")
|
||||
}
|
||||
|
||||
func (*ntfyNotifier) MergePullRequest(_ context.Context, doer *user_model.User, pr *issues_model.PullRequest) {
|
||||
_ = pr.LoadIssue(context.Background())
|
||||
_ = pr.Issue.LoadRepo(context.Background())
|
||||
SendAsync(repoTopic(pr.Issue.Repo),
|
||||
fmt.Sprintf("PR Merged: %s", pr.Issue.Title),
|
||||
fmt.Sprintf("#%d merged by %s", pr.Issue.Index, doer.Name),
|
||||
"default",
|
||||
"git-merge,merged")
|
||||
}
|
||||
|
||||
func (*ntfyNotifier) NewRelease(_ context.Context, rel *repo_model.Release) {
|
||||
SendAsync(repoTopic(rel.Repo),
|
||||
fmt.Sprintf("New Release: %s", rel.TagName),
|
||||
fmt.Sprintf("%s in %s\n%s", rel.TagName, rel.Repo.FullName(), rel.Note),
|
||||
"high",
|
||||
"rocket,release")
|
||||
}
|
||||
|
||||
func (*ntfyNotifier) WorkflowRunStatusUpdate(_ context.Context, repo *repo_model.Repository, _ *user_model.User, run *actions_model.ActionRun) {
|
||||
if run.Status.String() != "success" && run.Status.String() != "failure" {
|
||||
return // only notify on completion
|
||||
}
|
||||
priority := "default"
|
||||
tags := "white_check_mark,ci"
|
||||
if run.Status.String() == "failure" {
|
||||
priority = "high"
|
||||
tags = "x,ci-fail"
|
||||
}
|
||||
SendAsync(repoTopic(repo),
|
||||
fmt.Sprintf("CI %s: %s", run.Status.String(), run.Title),
|
||||
fmt.Sprintf("Workflow in %s", repo.FullName()),
|
||||
priority,
|
||||
tags)
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// Copyright 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package ntfy
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
// Send publishes a notification to the ntfy server.
|
||||
func Send(topic, title, message, priority, tags string) error {
|
||||
if !setting.Ntfy.Enabled || setting.Ntfy.ServerURL == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if topic == "" {
|
||||
topic = setting.Ntfy.DefaultTopic
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s/%s", strings.TrimRight(setting.Ntfy.ServerURL, "/"), topic)
|
||||
|
||||
req, err := http.NewRequest("POST", url, strings.NewReader(message))
|
||||
if err != nil {
|
||||
return fmt.Errorf("ntfy request: %w", err)
|
||||
}
|
||||
|
||||
req.Header.Set("Title", title)
|
||||
if priority != "" {
|
||||
req.Header.Set("Priority", priority)
|
||||
}
|
||||
if tags != "" {
|
||||
req.Header.Set("Tags", tags)
|
||||
}
|
||||
if setting.Ntfy.Token != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+setting.Ntfy.Token)
|
||||
}
|
||||
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ntfy send: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
return fmt.Errorf("ntfy returned status %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
log.Debug("ntfy notification sent: %s — %s", topic, title)
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendAsync sends a notification in a goroutine (non-blocking).
|
||||
func SendAsync(topic, title, message, priority, tags string) {
|
||||
go func() {
|
||||
if err := Send(topic, title, message, priority, tags); err != nil {
|
||||
log.Error("ntfy async send failed: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
{{template "admin/layout_head" (dict "pageClass" "admin dashboard")}}
|
||||
<div class="admin-setting-content">
|
||||
{{if .NeedUpdate}}
|
||||
<div class="ui positive message">
|
||||
<div class="header">{{svg "octicon-info"}} MokoGitea Update Available</div>
|
||||
<p>A new version <strong>{{.LatestVersion}}</strong> is available.
|
||||
{{if .ReleaseURL}}<a href="{{.ReleaseURL}}" target="_blank" rel="noopener noreferrer">View release notes</a>{{end}}</p>
|
||||
</div>
|
||||
{{end}}
|
||||
<h4 class="ui top attached header">
|
||||
{{ctx.Locale.Tr "admin.dashboard.maintenance_operations"}}
|
||||
</h4>
|
||||
|
||||
Reference in New Issue
Block a user