Skip to content

Commit 5afde86

Browse files
authored
Merge branch 'main' into monaco-tsx
2 parents 7817a45 + 2ee4aa8 commit 5afde86

File tree

15 files changed

+279
-28
lines changed

15 files changed

+279
-28
lines changed

custom/conf/app.example.ini

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,13 @@ LEVEL = Info
10401040
;; Don't allow download source archive files from UI
10411041
;DISABLE_DOWNLOAD_SOURCE_ARCHIVES = false
10421042

1043-
;; Allow fork repositories without maximum number limit
1043+
;; Allow to fork repositories without maximum number limit
10441044
;ALLOW_FORK_WITHOUT_MAXIMUM_LIMIT = true
10451045

1046+
;; Allow to fork repositories into the same owner (user or organization)
1047+
;; This feature is experimental, not fully tested, and may be changed in the future
1048+
;ALLOW_FORK_INTO_SAME_OWNER = false
1049+
10461050
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10471051
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10481052
;[repository.editor]

models/actions/run_job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
137137
if err != nil {
138138
return 0, err
139139
}
140-
run.Status = aggregateJobStatus(jobs)
140+
run.Status = AggregateJobStatus(jobs)
141141
if run.Started.IsZero() && run.Status.IsRunning() {
142142
run.Started = timeutil.TimeStampNow()
143143
}
@@ -152,7 +152,7 @@ func UpdateRunJob(ctx context.Context, job *ActionRunJob, cond builder.Cond, col
152152
return affected, nil
153153
}
154154

155-
func aggregateJobStatus(jobs []*ActionRunJob) Status {
155+
func AggregateJobStatus(jobs []*ActionRunJob) Status {
156156
allDone := true
157157
allWaiting := true
158158
hasFailure := false

models/fixtures/action_run.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,22 @@
3636
updated: 1683636626
3737
need_approval: 0
3838
approved_by: 0
39+
-
40+
id: 793
41+
title: "job output"
42+
repo_id: 4
43+
owner_id: 1
44+
workflow_id: "test.yaml"
45+
index: 189
46+
trigger_user_id: 1
47+
ref: "refs/heads/master"
48+
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
49+
event: "push"
50+
is_fork_pull_request: 0
51+
status: 1
52+
started: 1683636528
53+
stopped: 1683636626
54+
created: 1683636108
55+
updated: 1683636626
56+
need_approval: 0
57+
approved_by: 0

models/fixtures/action_run_job.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,46 @@
2626
status: 1
2727
started: 1683636528
2828
stopped: 1683636626
29+
-
30+
id: 194
31+
run_id: 793
32+
repo_id: 4
33+
owner_id: 1
34+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
35+
is_fork_pull_request: 0
36+
name: job1 (1)
37+
attempt: 1
38+
job_id: job1
39+
task_id: 49
40+
status: 1
41+
started: 1683636528
42+
stopped: 1683636626
43+
-
44+
id: 195
45+
run_id: 793
46+
repo_id: 4
47+
owner_id: 1
48+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
49+
is_fork_pull_request: 0
50+
name: job1 (2)
51+
attempt: 1
52+
job_id: job1
53+
task_id: 50
54+
status: 1
55+
started: 1683636528
56+
stopped: 1683636626
57+
-
58+
id: 196
59+
run_id: 793
60+
repo_id: 4
61+
owner_id: 1
62+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
63+
is_fork_pull_request: 0
64+
name: job2
65+
attempt: 1
66+
job_id: job2
67+
needs: [job1]
68+
task_id: 51
69+
status: 5
70+
started: 1683636528
71+
stopped: 1683636626

models/fixtures/action_task.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,63 @@
5757
log_length: 707
5858
log_size: 90179
5959
log_expired: 0
60+
-
61+
id: 49
62+
job_id: 194
63+
attempt: 1
64+
runner_id: 1
65+
status: 1 # success
66+
started: 1683636528
67+
stopped: 1683636626
68+
repo_id: 4
69+
owner_id: 1
70+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
71+
is_fork_pull_request: 0
72+
token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc4784220
73+
token_salt: ffffffffff
74+
token_last_eight: ffffffff
75+
log_filename: artifact-test2/2f/47.log
76+
log_in_storage: 1
77+
log_length: 707
78+
log_size: 90179
79+
log_expired: 0
80+
-
81+
id: 50
82+
job_id: 195
83+
attempt: 1
84+
runner_id: 1
85+
status: 1 # success
86+
started: 1683636528
87+
stopped: 1683636626
88+
repo_id: 4
89+
owner_id: 1
90+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
91+
is_fork_pull_request: 0
92+
token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc4784221
93+
token_salt: ffffffffff
94+
token_last_eight: ffffffff
95+
log_filename: artifact-test2/2f/47.log
96+
log_in_storage: 1
97+
log_length: 707
98+
log_size: 90179
99+
log_expired: 0
100+
-
101+
id: 51
102+
job_id: 196
103+
attempt: 1
104+
runner_id: 1
105+
status: 6 # running
106+
started: 1683636528
107+
stopped: 1683636626
108+
repo_id: 4
109+
owner_id: 1
110+
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
111+
is_fork_pull_request: 0
112+
token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc4784222
113+
token_salt: ffffffffff
114+
token_last_eight: ffffffff
115+
log_filename: artifact-test2/2f/47.log
116+
log_in_storage: 1
117+
log_length: 707
118+
log_size: 90179
119+
log_expired: 0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-
2+
id: 1
3+
task_id: 49
4+
output_key: output_a
5+
output_value: abc
6+
-
7+
id: 2
8+
task_id: 49
9+
output_key: output_b
10+
output_value: ''
11+
-
12+
id: 3
13+
task_id: 50
14+
output_key: output_a
15+
output_value: ''
16+
-
17+
id: 4
18+
task_id: 50
19+
output_key: output_b
20+
output_value: bbb

modules/repository/fork.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ import (
99
"code.gitea.io/gitea/models/organization"
1010
repo_model "code.gitea.io/gitea/models/repo"
1111
user_model "code.gitea.io/gitea/models/user"
12+
"code.gitea.io/gitea/modules/setting"
1213
)
1314

15+
func CanUserForkBetweenOwners(id1, id2 int64) bool {
16+
if id1 != id2 {
17+
return true
18+
}
19+
return setting.Repository.AllowForkIntoSameOwner
20+
}
21+
1422
// CanUserForkRepo returns true if specified user can fork repository.
1523
func CanUserForkRepo(ctx context.Context, user *user_model.User, repo *repo_model.Repository) (bool, error) {
1624
if user == nil {
1725
return false, nil
1826
}
19-
if repo.OwnerID != user.ID && !repo_model.HasForkedRepo(ctx, user.ID, repo.ID) {
27+
if CanUserForkBetweenOwners(repo.OwnerID, user.ID) && !repo_model.HasForkedRepo(ctx, user.ID, repo.ID) {
2028
return true, nil
2129
}
2230
ownedOrgs, err := organization.GetOrgsCanCreateRepoByUserID(ctx, user.ID)

modules/repository/fork_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package repository
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/modules/setting"
10+
"code.gitea.io/gitea/modules/test"
11+
12+
"github.com/stretchr/testify/assert"
13+
)
14+
15+
func TestCanUserForkBetweenOwners(t *testing.T) {
16+
defer test.MockVariableValue(&setting.Repository.AllowForkIntoSameOwner)
17+
18+
setting.Repository.AllowForkIntoSameOwner = true
19+
assert.True(t, CanUserForkBetweenOwners(1, 1))
20+
assert.True(t, CanUserForkBetweenOwners(1, 2))
21+
22+
setting.Repository.AllowForkIntoSameOwner = false
23+
assert.False(t, CanUserForkBetweenOwners(1, 1))
24+
assert.True(t, CanUserForkBetweenOwners(1, 2))
25+
}

modules/setting/repository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var (
5353
AllowDeleteOfUnadoptedRepositories bool
5454
DisableDownloadSourceArchives bool
5555
AllowForkWithoutMaximumLimit bool
56+
AllowForkIntoSameOwner bool
5657

5758
// Repository editor settings
5859
Editor struct {

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)