Skip to content

Commit 8f6034c

Browse files
authored
Merge branch 'main' into feat/add-lock-fullname-option
2 parents 4d1e443 + b594cec commit 8f6034c

File tree

25 files changed

+469
-93
lines changed

25 files changed

+469
-93
lines changed

.github/labeler.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ modifies/go:
7070
- any-glob-to-any-file:
7171
- "**/*.go"
7272

73-
modifies/js:
73+
modifies/frontend:
7474
- changed-files:
7575
- any-glob-to-any-file:
7676
- "**/*.js"
77+
- "**/*.ts"
7778
- "**/*.vue"
7879

7980
docs-update-needed:

.github/workflows/pull-db-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ jobs:
201201
runs-on: ubuntu-latest
202202
services:
203203
mssql:
204-
image: mcr.microsoft.com/mssql/server:2017-latest
204+
# some images before 2024-04 can't run on new kernels
205+
image: mcr.microsoft.com/mssql/server:2019-latest
205206
env:
206207
ACCEPT_EULA: Y
207208
MSSQL_PID: Standard

custom/conf/app.example.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ INTERNAL_TOKEN =
526526
;; HMAC to encode urls with, it **is required** if camo is enabled.
527527
;HMAC_KEY =
528528
;; Set to true to use camo for https too lese only non https urls are proxyed
529-
;ALLWAYS = false
529+
;; ALLWAYS is deprecated and will be removed in the future
530+
;ALWAYS = false
530531

531532
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
532533
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

models/activities/repo_activity.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type ActivityStats struct {
3434
OpenedPRAuthorCount int64
3535
MergedPRs issues_model.PullRequestList
3636
MergedPRAuthorCount int64
37+
ActiveIssues issues_model.IssueList
3738
OpenedIssues issues_model.IssueList
3839
OpenedIssueAuthorCount int64
3940
ClosedIssues issues_model.IssueList
@@ -172,7 +173,7 @@ func (stats *ActivityStats) MergedPRPerc() int {
172173

173174
// ActiveIssueCount returns total active issue count
174175
func (stats *ActivityStats) ActiveIssueCount() int {
175-
return stats.OpenedIssueCount() + stats.ClosedIssueCount()
176+
return len(stats.ActiveIssues)
176177
}
177178

178179
// OpenedIssueCount returns open issue count
@@ -285,13 +286,21 @@ func (stats *ActivityStats) FillIssues(ctx context.Context, repoID int64, fromTi
285286
stats.ClosedIssueAuthorCount = count
286287

287288
// New issues
288-
sess = issuesForActivityStatement(ctx, repoID, fromTime, false, false)
289+
sess = newlyCreatedIssues(ctx, repoID, fromTime)
289290
sess.OrderBy("issue.created_unix ASC")
290291
stats.OpenedIssues = make(issues_model.IssueList, 0)
291292
if err = sess.Find(&stats.OpenedIssues); err != nil {
292293
return err
293294
}
294295

296+
// Active issues
297+
sess = activeIssues(ctx, repoID, fromTime)
298+
sess.OrderBy("issue.created_unix ASC")
299+
stats.ActiveIssues = make(issues_model.IssueList, 0)
300+
if err = sess.Find(&stats.ActiveIssues); err != nil {
301+
return err
302+
}
303+
295304
// Opened issue authors
296305
sess = issuesForActivityStatement(ctx, repoID, fromTime, false, false)
297306
if _, err = sess.Select("count(distinct issue.poster_id) as `count`").Table("issue").Get(&count); err != nil {
@@ -317,6 +326,23 @@ func (stats *ActivityStats) FillUnresolvedIssues(ctx context.Context, repoID int
317326
return sess.Find(&stats.UnresolvedIssues)
318327
}
319328

329+
func newlyCreatedIssues(ctx context.Context, repoID int64, fromTime time.Time) *xorm.Session {
330+
sess := db.GetEngine(ctx).Where("issue.repo_id = ?", repoID).
331+
And("issue.is_pull = ?", false). // Retain the is_pull check to exclude pull requests
332+
And("issue.created_unix >= ?", fromTime.Unix()) // Include all issues created after fromTime
333+
334+
return sess
335+
}
336+
337+
func activeIssues(ctx context.Context, repoID int64, fromTime time.Time) *xorm.Session {
338+
sess := db.GetEngine(ctx).Where("issue.repo_id = ?", repoID).
339+
And("issue.is_pull = ?", false).
340+
And("issue.created_unix >= ?", fromTime.Unix()).
341+
Or("issue.closed_unix >= ?", fromTime.Unix())
342+
343+
return sess
344+
}
345+
320346
func issuesForActivityStatement(ctx context.Context, repoID int64, fromTime time.Time, closed, unresolved bool) *xorm.Session {
321347
sess := db.GetEngine(ctx).Where("issue.repo_id = ?", repoID).
322348
And("issue.is_closed = ?", closed)

modules/httpcache/httpcache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func HandleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag s
7575
w.Header().Set("Etag", etag)
7676
}
7777
if lastModified != nil && !lastModified.IsZero() {
78-
w.Header().Set("Last-Modified", lastModified.Format(http.TimeFormat))
78+
// http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
79+
w.Header().Set("Last-Modified", lastModified.UTC().Format(http.TimeFormat))
7980
}
8081

8182
if len(etag) > 0 {

modules/httplib/serve.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func ServeSetHeaders(w http.ResponseWriter, opts *ServeHeaderOptions) {
7979
httpcache.SetCacheControlInHeader(header, duration)
8080

8181
if !opts.LastModified.IsZero() {
82+
// http.TimeFormat required a UTC time, refer to https://pkg.go.dev/net/http#TimeFormat
8283
header.Set("Last-Modified", opts.LastModified.UTC().Format(http.TimeFormat))
8384
}
8485
}

modules/httplib/url.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ func getRequestScheme(req *http.Request) string {
5252
return ""
5353
}
5454

55-
func getForwardedHost(req *http.Request) string {
56-
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
57-
return req.Header.Get("X-Forwarded-Host")
58-
}
59-
6055
// GuessCurrentAppURL tries to guess the current full app URL (with sub-path) by http headers. It always has a '/' suffix, exactly the same as setting.AppURL
6156
func GuessCurrentAppURL(ctx context.Context) string {
6257
return GuessCurrentHostURL(ctx) + setting.AppSubURL + "/"
@@ -81,11 +76,9 @@ func GuessCurrentHostURL(ctx context.Context) string {
8176
if reqScheme == "" {
8277
return strings.TrimSuffix(setting.AppURL, setting.AppSubURL+"/")
8378
}
84-
reqHost := getForwardedHost(req)
85-
if reqHost == "" {
86-
reqHost = req.Host
87-
}
88-
return reqScheme + "://" + reqHost
79+
// X-Forwarded-Host has many problems: non-standard, not well-defined (X-Forwarded-Port or not), conflicts with Host header.
80+
// So do not use X-Forwarded-Host, just use Host header directly.
81+
return reqScheme + "://" + req.Host
8982
}
9083

9184
// MakeAbsoluteURL tries to make a link to an absolute URL:

modules/httplib/url_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestMakeAbsoluteURL(t *testing.T) {
7070
"X-Forwarded-Proto": {"https"},
7171
},
7272
})
73-
assert.Equal(t, "https://forwarded-host/foo", MakeAbsoluteURL(ctx, "/foo"))
73+
assert.Equal(t, "https://user-host/foo", MakeAbsoluteURL(ctx, "/foo"))
7474
}
7575

7676
func TestIsCurrentGiteaSiteURL(t *testing.T) {
@@ -119,5 +119,6 @@ func TestIsCurrentGiteaSiteURL(t *testing.T) {
119119
},
120120
})
121121
assert.True(t, IsCurrentGiteaSiteURL(ctx, "http://localhost:3000"))
122-
assert.True(t, IsCurrentGiteaSiteURL(ctx, "https://forwarded-host"))
122+
assert.True(t, IsCurrentGiteaSiteURL(ctx, "https://user-host"))
123+
assert.False(t, IsCurrentGiteaSiteURL(ctx, "https://forwarded-host"))
123124
}

modules/markup/camo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func camoHandleLink(link string) string {
3838
if setting.Camo.Enabled {
3939
lnkURL, err := url.Parse(link)
4040
if err == nil && lnkURL.IsAbs() && !strings.HasPrefix(link, setting.AppURL) &&
41-
(setting.Camo.Allways || lnkURL.Scheme != "https") {
41+
(setting.Camo.Always || lnkURL.Scheme != "https") {
4242
return CamoEncode(link)
4343
}
4444
}

modules/markup/camo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestCamoHandleLink(t *testing.T) {
2828
"https://image.proxy/eivin43gJwGVIjR9MiYYtFIk0mw/aHR0cDovL3Rlc3RpbWFnZXMub3JnL2ltZy5qcGc",
2929
camoHandleLink("http://testimages.org/img.jpg"))
3030

31-
setting.Camo.Allways = true
31+
setting.Camo.Always = true
3232
assert.Equal(t,
3333
"https://gitea.com/img.jpg",
3434
camoHandleLink("https://gitea.com/img.jpg"))

0 commit comments

Comments
 (0)