Skip to content

Commit 5053319

Browse files
authored
Merge branch 'main' into avatar-refactor
2 parents 225c97d + 167914c commit 5053319

File tree

12 files changed

+112
-56
lines changed

12 files changed

+112
-56
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,6 +2043,8 @@ PATH =
20432043
;TOKEN =
20442044
;; Enable issue by label metrics; default is false
20452045
;ENABLED_ISSUE_BY_LABEL = false
2046+
;; Enable issue by repository metrics; default is false
2047+
;ENABLED_ISSUE_BY_REPOSITORY = false
20462048

20472049
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
20482050
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,8 @@ NB: You must have `DISABLE_ROUTER_LOG` set to `false` for this option to take ef
853853
## Metrics (`metrics`)
854854

855855
- `ENABLED`: **false**: Enables /metrics endpoint for prometheus.
856-
- `ENABLED_ISSUE_BY_LABEL`: **false**: Enable issue by label metrics
856+
- `ENABLED_ISSUE_BY_LABEL`: **false**: Enable issue by label metrics with format `gitea_issues_by_label{label="bug"} 2`.
857+
- `ENABLED_ISSUE_BY_REPOSITORY`: **false**: Enable issue by repository metrics with format `gitea_issues_by_repository{repository="org/repo"} 5`.
857858
- `TOKEN`: **\<empty\>**: You need to specify the token, if you want to include in the authorization the metrics . The same token need to be used in prometheus parameters `bearer_token` or `bearer_token_file`.
858859

859860
## API (`api`)

models/pull.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ func GetLatestPullRequestByHeadInfo(repoID int64, branch string) (*PullRequest,
522522

523523
// GetPullRequestByIndex returns a pull request by the given index
524524
func GetPullRequestByIndex(repoID, index int64) (*PullRequest, error) {
525+
if index < 1 {
526+
return nil, ErrPullRequestNotExist{}
527+
}
525528
pr := &PullRequest{
526529
BaseRepoID: repoID,
527530
Index: index,

models/pull_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ func TestGetPullRequestByIndex(t *testing.T) {
134134
_, err = GetPullRequestByIndex(9223372036854775807, 9223372036854775807)
135135
assert.Error(t, err)
136136
assert.True(t, IsErrPullRequestNotExist(err))
137+
138+
_, err = GetPullRequestByIndex(1, 0)
139+
assert.Error(t, err)
140+
assert.True(t, IsErrPullRequestNotExist(err))
137141
}
138142

139143
func TestGetPullRequestByID(t *testing.T) {

models/statistic.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ type Statistic struct {
2121
Milestone, Label, HookTask,
2222
Team, UpdateTask, Project,
2323
ProjectBoard, Attachment int64
24-
IssueByLabel []IssueByLabelCount
24+
IssueByLabel []IssueByLabelCount
25+
IssueByRepository []IssueByRepositoryCount
2526
}
2627
}
2728

@@ -31,6 +32,13 @@ type IssueByLabelCount struct {
3132
Label string
3233
}
3334

35+
// IssueByRepositoryCount contains the number of issue group by repository
36+
type IssueByRepositoryCount struct {
37+
Count int64
38+
OwnerName string
39+
Repository string
40+
}
41+
3442
// GetStatistic returns the database statistics
3543
func GetStatistic() (stats Statistic) {
3644
e := db.GetEngine(db.DefaultContext)
@@ -58,6 +66,16 @@ func GetStatistic() (stats Statistic) {
5866
Find(&stats.Counter.IssueByLabel)
5967
}
6068

69+
if setting.Metrics.EnabledIssueByRepository {
70+
stats.Counter.IssueByRepository = []IssueByRepositoryCount{}
71+
72+
_ = e.Select("COUNT(*) AS count, r.owner_name, r.name AS repository").
73+
Join("LEFT", "repository r", "r.id=i.repo_id").
74+
Table("issue i").
75+
GroupBy("r.owner_name, r.name").
76+
Find(&stats.Counter.IssueByRepository)
77+
}
78+
6179
issueCounts := []IssueCount{}
6280

6381
_ = e.Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts)

modules/metrics/collector.go

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,34 @@ const namespace = "gitea_"
1515
// Collector implements the prometheus.Collector interface and
1616
// exposes gitea metrics for prometheus
1717
type Collector struct {
18-
Accesses *prometheus.Desc
19-
Actions *prometheus.Desc
20-
Attachments *prometheus.Desc
21-
Comments *prometheus.Desc
22-
Follows *prometheus.Desc
23-
HookTasks *prometheus.Desc
24-
Issues *prometheus.Desc
25-
IssuesOpen *prometheus.Desc
26-
IssuesClosed *prometheus.Desc
27-
IssuesByLabel *prometheus.Desc
28-
Labels *prometheus.Desc
29-
LoginSources *prometheus.Desc
30-
Milestones *prometheus.Desc
31-
Mirrors *prometheus.Desc
32-
Oauths *prometheus.Desc
33-
Organizations *prometheus.Desc
34-
Projects *prometheus.Desc
35-
ProjectBoards *prometheus.Desc
36-
PublicKeys *prometheus.Desc
37-
Releases *prometheus.Desc
38-
Repositories *prometheus.Desc
39-
Stars *prometheus.Desc
40-
Teams *prometheus.Desc
41-
UpdateTasks *prometheus.Desc
42-
Users *prometheus.Desc
43-
Watches *prometheus.Desc
44-
Webhooks *prometheus.Desc
18+
Accesses *prometheus.Desc
19+
Actions *prometheus.Desc
20+
Attachments *prometheus.Desc
21+
Comments *prometheus.Desc
22+
Follows *prometheus.Desc
23+
HookTasks *prometheus.Desc
24+
Issues *prometheus.Desc
25+
IssuesOpen *prometheus.Desc
26+
IssuesClosed *prometheus.Desc
27+
IssuesByLabel *prometheus.Desc
28+
IssuesByRepository *prometheus.Desc
29+
Labels *prometheus.Desc
30+
LoginSources *prometheus.Desc
31+
Milestones *prometheus.Desc
32+
Mirrors *prometheus.Desc
33+
Oauths *prometheus.Desc
34+
Organizations *prometheus.Desc
35+
Projects *prometheus.Desc
36+
ProjectBoards *prometheus.Desc
37+
PublicKeys *prometheus.Desc
38+
Releases *prometheus.Desc
39+
Repositories *prometheus.Desc
40+
Stars *prometheus.Desc
41+
Teams *prometheus.Desc
42+
UpdateTasks *prometheus.Desc
43+
Users *prometheus.Desc
44+
Watches *prometheus.Desc
45+
Webhooks *prometheus.Desc
4546
}
4647

4748
// NewCollector returns a new Collector with all prometheus.Desc initialized
@@ -88,6 +89,11 @@ func NewCollector() Collector {
8889
"Number of Issues",
8990
[]string{"label"}, nil,
9091
),
92+
IssuesByRepository: prometheus.NewDesc(
93+
namespace+"issues_by_repository",
94+
"Number of Issues",
95+
[]string{"repository"}, nil,
96+
),
9197
IssuesOpen: prometheus.NewDesc(
9298
namespace+"issues_open",
9399
"Number of open Issues",
@@ -196,6 +202,7 @@ func (c Collector) Describe(ch chan<- *prometheus.Desc) {
196202
ch <- c.HookTasks
197203
ch <- c.Issues
198204
ch <- c.IssuesByLabel
205+
ch <- c.IssuesByRepository
199206
ch <- c.IssuesOpen
200207
ch <- c.IssuesClosed
201208
ch <- c.Labels
@@ -264,6 +271,14 @@ func (c Collector) Collect(ch chan<- prometheus.Metric) {
264271
il.Label,
265272
)
266273
}
274+
for _, ir := range stats.Counter.IssueByRepository {
275+
ch <- prometheus.MustNewConstMetric(
276+
c.IssuesByRepository,
277+
prometheus.GaugeValue,
278+
float64(ir.Count),
279+
ir.OwnerName+"/"+ir.Repository,
280+
)
281+
}
267282
ch <- prometheus.MustNewConstMetric(
268283
c.IssuesClosed,
269284
prometheus.GaugeValue,

modules/setting/setting.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,15 @@ var (
390390

391391
// Metrics settings
392392
Metrics = struct {
393-
Enabled bool
394-
Token string
395-
EnabledIssueByLabel bool
393+
Enabled bool
394+
Token string
395+
EnabledIssueByLabel bool
396+
EnabledIssueByRepository bool
396397
}{
397-
Enabled: false,
398-
Token: "",
399-
EnabledIssueByLabel: false,
398+
Enabled: false,
399+
Token: "",
400+
EnabledIssueByLabel: false,
401+
EnabledIssueByRepository: false,
400402
}
401403

402404
// I18n settings

options/locale/locale_el-GR.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ reset_password.text=Κάντε κλικ στον παρακάτω σύνδεσμ
345345

346346
register_success=Επιτυχής εγγραφή
347347

348+
issue_assigned.pull=@%[1]s σας έχει αναθέσει στο pull request %[2]s στο αποθετήριο %[3]s.
349+
issue_assigned.issue=@%[1]s σας ανέθεσε το ζήτημα %[2]s στο αποθετήριο %[3]s.
348350

349351
issue.x_mentioned_you=<b>@%s</b> σας ανέφερε:
350352
issue.action.force_push=<b>%[1]s</b> έκανε force-push το <b>%[2]s</b> από %[3]s σε %[4]s.
@@ -967,6 +969,7 @@ file_view_rendered=Προβολή Απόδοσης
967969
file_view_raw=Προβολή Ακατέργαστου
968970
file_permalink=Permalink
969971
file_too_large=Το αρχείο είναι πολύ μεγάλο για να εμφανιστεί.
972+
file_copy_permalink=Αντιγραφή Permalink
970973
video_not_supported_in_browser=Το πρόγραμμα περιήγησής σας δεν υποστηρίζει την ετικέτα HTML5 'video'.
971974
audio_not_supported_in_browser=Το πρόγραμμα περιήγησής σας δεν υποστηρίζει την ετικέτα HTML5 'audio'.
972975
stored_lfs=Αποθηκεύτηκε με το Git LFS
@@ -1194,6 +1197,11 @@ issues.action_milestone_no_select=Χωρίς ορόσημο
11941197
issues.action_assignee=Αποδέκτης
11951198
issues.action_assignee_no_select=Κανένας Αποδέκτης
11961199
issues.opened_by=άνοιξαν %[1]s από <a href="%[2]s">%[3]s</a>
1200+
pulls.merged_by=συγχώνευσε το %[1]s από <a href="%[2]s">%[3]s</a>
1201+
pulls.merged_by_fake=συγχώνευσε το %[1]s από %[2]s
1202+
issues.closed_by=έκλεισε το %[1]s από <a href="%[2]s">%[3]s</a>
1203+
issues.opened_by_fake=άνοιξε το %[1]s από %[2]s
1204+
issues.closed_by_fake=έκλεισε το %[1]s από %[2]s
11971205
issues.previous=Προηγούμενο
11981206
issues.next=Επόμενο
11991207
issues.open_title=Ανοιχτό
@@ -1378,6 +1386,8 @@ pulls.compare_changes=Νέο Pull Request
13781386
pulls.compare_changes_desc=Επιλέξτε τον κλάδο που θα συγχωνευθεί και τον κλάδο από τον οποίο θα τραβηχτεί.
13791387
pulls.compare_base=συγχώνευση σε
13801388
pulls.compare_compare=τράβηγμα από
1389+
pulls.switch_comparison_type=Αλλαγή τύπου σύγκρισης
1390+
pulls.switch_head_and_base=Αλλαγή κεφαλής και βάσης
13811391
pulls.filter_branch=Φιλτράρισμα κλάδου
13821392
pulls.no_results=Δεν βρέθηκαν αποτελέσματα.
13831393
pulls.nothing_to_compare=Αυτοί οι κλάδοι είναι όμοιοι. Δεν υπάρχει ανάγκη να δημιουργήσετε ένα pull request.
@@ -2412,6 +2422,7 @@ auths.attribute_name=Χαρακτηριστικό Ονόματος
24122422
auths.attribute_surname=Χαρακτηριστικό Επωνύμου
24132423
auths.attribute_mail=Χαρακτηριστικό Email
24142424
auths.attribute_ssh_public_key=Χαρακτηριστικό Δημόσιου Κλειδιού SSH
2425+
auths.attribute_avatar=Παράμετρος Εικόνας
24152426
auths.attributes_in_bind=Λήψη χαρακτηριστικών μέσα στο πλαίσιο του Bind DN
24162427
auths.allow_deactivate_all=Επιτρέψτε σε ένα κενό αποτέλεσμα αναζήτησης να απενεργοποιήσει όλους τους χρήστες
24172428
auths.use_paged_search=Χρήση Σελιδοποιημένης Αναζήτησης

routers/web/repo/issue.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,9 @@ func NewIssue(ctx *context.Context) {
803803
ctx.Data["Project"] = project
804804
}
805805

806+
if len(ctx.Req.URL.Query().Get("project")) > 0 {
807+
ctx.Data["redirect_after_creation"] = "project"
808+
}
806809
}
807810

808811
RetrieveRepoMetas(ctx, ctx.Repo.Repository, false)
@@ -990,7 +993,11 @@ func NewIssuePost(ctx *context.Context) {
990993
}
991994

992995
log.Trace("Issue created: %d/%d", repo.ID, issue.ID)
993-
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + fmt.Sprint(issue.Index))
996+
if ctx.FormString("redirect_after_creation") == "project" {
997+
ctx.Redirect(ctx.Repo.RepoLink + "/projects/" + fmt.Sprint(form.ProjectID))
998+
} else {
999+
ctx.Redirect(ctx.Repo.RepoLink + "/issues/" + fmt.Sprint(issue.Index))
1000+
}
9941001
}
9951002

9961003
// commentTag returns the CommentTag for a comment in/with the given repo, poster and issue

routers/web/repo/pull.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,29 +1322,16 @@ func DownloadPullPatch(ctx *context.Context) {
13221322

13231323
// DownloadPullDiffOrPatch render a pull's raw diff or patch
13241324
func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
1325-
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
1325+
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
13261326
if err != nil {
1327-
if models.IsErrIssueNotExist(err) {
1328-
ctx.NotFound("GetIssueByIndex", err)
1327+
if models.IsErrPullRequestNotExist(err) {
1328+
ctx.NotFound("GetPullRequestByIndex", err)
13291329
} else {
1330-
ctx.ServerError("GetIssueByIndex", err)
1330+
ctx.ServerError("GetPullRequestByIndex", err)
13311331
}
13321332
return
13331333
}
13341334

1335-
// Return not found if it's not a pull request
1336-
if !issue.IsPull {
1337-
ctx.NotFound("DownloadPullDiff",
1338-
fmt.Errorf("Issue is not a pull request"))
1339-
return
1340-
}
1341-
1342-
if err = issue.LoadPullRequest(); err != nil {
1343-
ctx.ServerError("LoadPullRequest", err)
1344-
return
1345-
}
1346-
1347-
pr := issue.PullRequest
13481335
binary := ctx.FormBool("binary")
13491336

13501337
if err := pull_service.DownloadDiffOrPatch(pr, ctx, patch, binary); err != nil {

services/webhook/deliver.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,21 @@ func Deliver(t *models.HookTask) error {
113113
signatureSHA256 = hex.EncodeToString(sig256.Sum(nil))
114114
}
115115

116+
event := t.EventType.Event()
117+
eventType := string(t.EventType)
116118
req.Header.Add("X-Gitea-Delivery", t.UUID)
117-
req.Header.Add("X-Gitea-Event", t.EventType.Event())
119+
req.Header.Add("X-Gitea-Event", event)
120+
req.Header.Add("X-Gitea-Event-Type", eventType)
118121
req.Header.Add("X-Gitea-Signature", signatureSHA256)
119122
req.Header.Add("X-Gogs-Delivery", t.UUID)
120-
req.Header.Add("X-Gogs-Event", t.EventType.Event())
123+
req.Header.Add("X-Gogs-Event", event)
124+
req.Header.Add("X-Gogs-Event-Type", eventType)
121125
req.Header.Add("X-Gogs-Signature", signatureSHA256)
122126
req.Header.Add("X-Hub-Signature", "sha1="+signatureSHA1)
123127
req.Header.Add("X-Hub-Signature-256", "sha256="+signatureSHA256)
124128
req.Header["X-GitHub-Delivery"] = []string{t.UUID}
125-
req.Header["X-GitHub-Event"] = []string{t.EventType.Event()}
129+
req.Header["X-GitHub-Event"] = []string{event}
130+
req.Header["X-GitHub-Event-Type"] = []string{eventType}
126131

127132
// Record delivery information.
128133
t.RequestInfo = &models.HookRequest{

templates/repo/issue/new_form.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,6 @@
236236
{{end}}
237237
</div>
238238
</div>
239+
<input type="hidden" name="redirect_after_creation" value="{{.redirect_after_creation}}">
239240
</div>
240241
</form>

0 commit comments

Comments
 (0)