Skip to content

Commit d34e36b

Browse files
authored
Merge branch 'main' into issue-updates
2 parents 877eb69 + 3269b04 commit d34e36b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+712
-169
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ jobs:
198198
test-mssql:
199199
if: needs.files-changed.outputs.backend == 'true' || needs.files-changed.outputs.actions == 'true'
200200
needs: files-changed
201-
runs-on: ubuntu-latest
201+
# specifying the version of ubuntu in use as mssql fails on newer kernels
202+
# pending resolution from vendor
203+
runs-on: ubuntu-20.04
202204
services:
203205
mssql:
204206
image: mcr.microsoft.com/mssql/server:2017-latest

cmd/serv.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ func runServ(c *cli.Context) error {
143143
return nil
144144
}
145145

146+
defer func() {
147+
if err := recover(); err != nil {
148+
_ = fail(ctx, "Internal Server Error", "Panic: %v\n%s", err, log.Stack(2))
149+
}
150+
}()
151+
146152
keys := strings.Split(c.Args().First(), "-")
147153
if len(keys) != 2 || keys[0] != "key" {
148154
return fail(ctx, "Key ID format error", "Invalid key argument: %s", c.Args().First())
@@ -189,10 +195,7 @@ func runServ(c *cli.Context) error {
189195
}
190196

191197
verb := words[0]
192-
repoPath := words[1]
193-
if repoPath[0] == '/' {
194-
repoPath = repoPath[1:]
195-
}
198+
repoPath := strings.TrimPrefix(words[1], "/")
196199

197200
var lfsVerb string
198201
if verb == lfsAuthenticateVerb {

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)

models/issues/pull.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ func (pr *PullRequest) LoadAttributes(ctx context.Context) (err error) {
268268
return nil
269269
}
270270

271+
func (pr *PullRequest) IsAgitFlow() bool {
272+
return pr.Flow == PullRequestFlowAGit
273+
}
274+
271275
// LoadHeadRepo loads the head repository, pr.HeadRepo will remain nil if it does not exist
272276
// and thus ErrRepoNotExist will never be returned
273277
func (pr *PullRequest) LoadHeadRepo(ctx context.Context) (err error) {

modules/actions/task_state.go

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,32 @@ func FullSteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep {
1818
return fullStepsOfEmptySteps(task)
1919
}
2020

21-
firstStep := task.Steps[0]
21+
// firstStep is the first step that has run or running, not include preStep.
22+
// For example,
23+
// 1. preStep(Success) -> step1(Success) -> step2(Running) -> step3(Waiting) -> postStep(Waiting): firstStep is step1.
24+
// 2. preStep(Success) -> step1(Skipped) -> step2(Success) -> postStep(Success): firstStep is step2.
25+
// 3. preStep(Success) -> step1(Running) -> step2(Waiting) -> postStep(Waiting): firstStep is step1.
26+
// 4. preStep(Success) -> step1(Skipped) -> step2(Skipped) -> postStep(Skipped): firstStep is nil.
27+
// 5. preStep(Success) -> step1(Cancelled) -> step2(Cancelled) -> postStep(Cancelled): firstStep is nil.
28+
var firstStep *actions_model.ActionTaskStep
29+
// lastHasRunStep is the last step that has run.
30+
// For example,
31+
// 1. preStep(Success) -> step1(Success) -> step2(Running) -> step3(Waiting) -> postStep(Waiting): lastHasRunStep is step1.
32+
// 2. preStep(Success) -> step1(Success) -> step2(Success) -> step3(Success) -> postStep(Success): lastHasRunStep is step3.
33+
// 3. preStep(Success) -> step1(Success) -> step2(Failure) -> step3 -> postStep(Waiting): lastHasRunStep is step2.
34+
// So its Stopped is the Started of postStep when there are no more steps to run.
35+
var lastHasRunStep *actions_model.ActionTaskStep
36+
2237
var logIndex int64
38+
for _, step := range task.Steps {
39+
if firstStep == nil && (step.Status.HasRun() || step.Status.IsRunning()) {
40+
firstStep = step
41+
}
42+
if step.Status.HasRun() {
43+
lastHasRunStep = step
44+
}
45+
logIndex += step.LogLength
46+
}
2347

2448
preStep := &actions_model.ActionTaskStep{
2549
Name: preStepName,
@@ -28,32 +52,17 @@ func FullSteps(task *actions_model.ActionTask) []*actions_model.ActionTaskStep {
2852
Status: actions_model.StatusRunning,
2953
}
3054

31-
if firstStep.Status.HasRun() || firstStep.Status.IsRunning() {
55+
// No step has run or is running, so preStep is equal to the task
56+
if firstStep == nil {
57+
preStep.Stopped = task.Stopped
58+
preStep.Status = task.Status
59+
} else {
3260
preStep.LogLength = firstStep.LogIndex
3361
preStep.Stopped = firstStep.Started
3462
preStep.Status = actions_model.StatusSuccess
35-
} else if task.Status.IsDone() {
36-
preStep.Stopped = task.Stopped
37-
preStep.Status = actions_model.StatusFailure
38-
if task.Status.IsSkipped() {
39-
preStep.Status = actions_model.StatusSkipped
40-
}
4163
}
4264
logIndex += preStep.LogLength
4365

44-
// lastHasRunStep is the last step that has run.
45-
// For example,
46-
// 1. preStep(Success) -> step1(Success) -> step2(Running) -> step3(Waiting) -> postStep(Waiting): lastHasRunStep is step1.
47-
// 2. preStep(Success) -> step1(Success) -> step2(Success) -> step3(Success) -> postStep(Success): lastHasRunStep is step3.
48-
// 3. preStep(Success) -> step1(Success) -> step2(Failure) -> step3 -> postStep(Waiting): lastHasRunStep is step2.
49-
// So its Stopped is the Started of postStep when there are no more steps to run.
50-
var lastHasRunStep *actions_model.ActionTaskStep
51-
for _, step := range task.Steps {
52-
if step.Status.HasRun() {
53-
lastHasRunStep = step
54-
}
55-
logIndex += step.LogLength
56-
}
5766
if lastHasRunStep == nil {
5867
lastHasRunStep = preStep
5968
}

modules/actions/task_state_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ func TestFullSteps(t *testing.T) {
137137
{Name: postStepName, Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
138138
},
139139
},
140+
{
141+
name: "first step is skipped",
142+
task: &actions_model.ActionTask{
143+
Steps: []*actions_model.ActionTaskStep{
144+
{Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
145+
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
146+
},
147+
Status: actions_model.StatusSuccess,
148+
Started: 10000,
149+
Stopped: 10100,
150+
LogLength: 100,
151+
},
152+
want: []*actions_model.ActionTaskStep{
153+
{Name: preStepName, Status: actions_model.StatusSuccess, LogIndex: 0, LogLength: 10, Started: 10000, Stopped: 10010},
154+
{Status: actions_model.StatusSkipped, LogIndex: 0, LogLength: 0, Started: 0, Stopped: 0},
155+
{Status: actions_model.StatusSuccess, LogIndex: 10, LogLength: 80, Started: 10010, Stopped: 10090},
156+
{Name: postStepName, Status: actions_model.StatusSuccess, LogIndex: 90, LogLength: 10, Started: 10090, Stopped: 10100},
157+
},
158+
},
140159
}
141160
for _, tt := range tests {
142161
t.Run(tt.name, func(t *testing.T) {

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
}

0 commit comments

Comments
 (0)