Skip to content

Commit 411bfe0

Browse files
committed
Merge branch 'main' into upstream_sort-repo-list-on-dashboard
2 parents e0ee13e + 67c1a07 commit 411bfe0

File tree

165 files changed

+2375
-1526
lines changed

Some content is hidden

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

165 files changed

+2375
-1526
lines changed

cmd/hook.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ Gitea or set your environment appropriately.`, "")
220220
}
221221
}
222222

223-
supportProcReceive := false
224-
if git.CheckGitVersionAtLeast("2.29") == nil {
225-
supportProcReceive = true
226-
}
223+
supportProcReceive := git.DefaultFeatures().SupportProcReceive
227224

228225
for scanner.Scan() {
229226
// TODO: support news feeds for wiki
@@ -341,6 +338,7 @@ Gitea or set your environment appropriately.`, "")
341338
isWiki, _ := strconv.ParseBool(os.Getenv(repo_module.EnvRepoIsWiki))
342339
repoName := os.Getenv(repo_module.EnvRepoName)
343340
pusherID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPusherID), 10, 64)
341+
prID, _ := strconv.ParseInt(os.Getenv(repo_module.EnvPRID), 10, 64)
344342
pusherName := os.Getenv(repo_module.EnvPusherName)
345343

346344
hookOptions := private.HookOptions{
@@ -350,6 +348,8 @@ Gitea or set your environment appropriately.`, "")
350348
GitObjectDirectory: os.Getenv(private.GitObjectDirectory),
351349
GitQuarantinePath: os.Getenv(private.GitQuarantinePath),
352350
GitPushOptions: pushOptions(),
351+
PullRequestID: prID,
352+
PushTrigger: repo_module.PushTrigger(os.Getenv(repo_module.EnvPushTrigger)),
353353
}
354354
oldCommitIDs := make([]string, hookBatchSize)
355355
newCommitIDs := make([]string, hookBatchSize)
@@ -497,7 +497,7 @@ Gitea or set your environment appropriately.`, "")
497497
return nil
498498
}
499499

500-
if git.CheckGitVersionAtLeast("2.29") != nil {
500+
if !git.DefaultFeatures().SupportProcReceive {
501501
return fail(ctx, "No proc-receive support", "current git version doesn't support proc-receive.")
502502
}
503503

cmd/migrate_storage.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var CmdMigrateStorage = &cli.Command{
3434
Name: "type",
3535
Aliases: []string{"t"},
3636
Value: "",
37-
Usage: "Type of stored files to copy. Allowed types: 'attachments', 'lfs', 'avatars', 'repo-avatars', 'repo-archivers', 'packages', 'actions-log'",
37+
Usage: "Type of stored files to copy. Allowed types: 'attachments', 'lfs', 'avatars', 'repo-avatars', 'repo-archivers', 'packages', 'actions-log', 'actions-artifacts",
3838
},
3939
&cli.StringFlag{
4040
Name: "storage",
@@ -160,6 +160,13 @@ func migrateActionsLog(ctx context.Context, dstStorage storage.ObjectStorage) er
160160
})
161161
}
162162

163+
func migrateActionsArtifacts(ctx context.Context, dstStorage storage.ObjectStorage) error {
164+
return db.Iterate(ctx, nil, func(ctx context.Context, artifact *actions_model.ActionArtifact) error {
165+
_, err := storage.Copy(dstStorage, artifact.ArtifactPath, storage.ActionsArtifacts, artifact.ArtifactPath)
166+
return err
167+
})
168+
}
169+
163170
func runMigrateStorage(ctx *cli.Context) error {
164171
stdCtx, cancel := installSignals()
165172
defer cancel()
@@ -223,13 +230,14 @@ func runMigrateStorage(ctx *cli.Context) error {
223230
}
224231

225232
migratedMethods := map[string]func(context.Context, storage.ObjectStorage) error{
226-
"attachments": migrateAttachments,
227-
"lfs": migrateLFS,
228-
"avatars": migrateAvatars,
229-
"repo-avatars": migrateRepoAvatars,
230-
"repo-archivers": migrateRepoArchivers,
231-
"packages": migratePackages,
232-
"actions-log": migrateActionsLog,
233+
"attachments": migrateAttachments,
234+
"lfs": migrateLFS,
235+
"avatars": migrateAvatars,
236+
"repo-avatars": migrateRepoAvatars,
237+
"repo-archivers": migrateRepoArchivers,
238+
"packages": migratePackages,
239+
"actions-log": migrateActionsLog,
240+
"actions-artifacts": migrateActionsArtifacts,
233241
}
234242

235243
tp := strings.ToLower(ctx.String("type"))

cmd/serv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func runServ(c *cli.Context) error {
178178
}
179179

180180
if len(words) < 2 {
181-
if git.CheckGitVersionAtLeast("2.29") == nil {
181+
if git.DefaultFeatures().SupportProcReceive {
182182
// for AGit Flow
183183
if cmd == "ssh_info" {
184184
fmt.Print(`{"type":"gitea","version":1}`)

custom/conf/app.example.ini

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ LEVEL = Info
14561456
;; Batch size to send for batched queues
14571457
;BATCH_LENGTH = 20
14581458
;;
1459-
;; Connection string for redis queues this will store the redis or redis-cluster connection string.
1459+
;; Connection string for redis queues this will store the redis (or Redis cluster) connection string.
14601460
;; When `TYPE` is `persistable-channel`, this provides a directory for the underlying leveldb
14611461
;; or additional options of the form `leveldb://path/to/db?option=value&....`, and will override `DATADIR`.
14621462
;CONN_STR = "redis://127.0.0.1:6379/0"
@@ -1740,9 +1740,8 @@ LEVEL = Info
17401740
;; For "memory" only, GC interval in seconds, default is 60
17411741
;INTERVAL = 60
17421742
;;
1743-
;; For "redis", "redis-cluster" and "memcache", connection host address
1744-
;; redis: `redis://127.0.0.1:6379/0?pool_size=100&idle_timeout=180s`
1745-
;; redis-cluster: `redis+cluster://127.0.0.1:6379/0?pool_size=100&idle_timeout=180s`
1743+
;; For "redis" and "memcache", connection host address
1744+
;; redis: `redis://127.0.0.1:6379/0?pool_size=100&idle_timeout=180s` (or `redis+cluster://127.0.0.1:6379/0?pool_size=100&idle_timeout=180s` for a Redis cluster)
17461745
;; memcache: `127.0.0.1:11211`
17471746
;; twoqueue: `{"size":50000,"recent_ratio":0.25,"ghost_ratio":0.5}` or `50000`
17481747
;HOST =
@@ -1772,15 +1771,14 @@ LEVEL = Info
17721771
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17731772
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17741773
;;
1775-
;; Either "memory", "file", "redis", "redis-cluster", "db", "mysql", "couchbase", "memcache" or "postgres"
1774+
;; Either "memory", "file", "redis", "db", "mysql", "couchbase", "memcache" or "postgres"
17761775
;; Default is "memory". "db" will reuse the configuration in [database]
17771776
;PROVIDER = memory
17781777
;;
17791778
;; Provider config options
17801779
;; memory: doesn't have any config yet
17811780
;; file: session file path, e.g. `data/sessions`
1782-
;; redis: `redis://127.0.0.1:6379/0?pool_size=100&idle_timeout=180s`
1783-
;; redis-cluster: `redis+cluster://127.0.0.1:6379/0?pool_size=100&idle_timeout=180s`
1781+
;; redis: `redis://127.0.0.1:6379/0?pool_size=100&idle_timeout=180s` (or `redis+cluster://127.0.0.1:6379/0?pool_size=100&idle_timeout=180s` for a Redis cluster)
17841782
;; mysql: go-sql-driver/mysql dsn config string, e.g. `root:password@/session_table`
17851783
;PROVIDER_CONFIG = data/sessions ; Relative paths will be made absolute against _`AppWorkPath`_.
17861784
;;

docker/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Gitea - Docker
22

3-
Dockerfile is found in root of repository.
3+
Dockerfile is found in the root of the repository.
44

5-
Docker image can be found on [docker hub](https://hub.docker.com/r/gitea/gitea)
5+
Docker image can be found on [docker hub](https://hub.docker.com/r/gitea/gitea).
66

7-
Documentation on using docker image can be found on [Gitea Docs site](https://docs.gitea.com/installation/install-with-docker-rootless)
7+
Documentation on using docker image can be found on [Gitea Docs site](https://docs.gitea.com/installation/install-with-docker-rootless).

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ Configuration at `[queue]` will set defaults for queues with overrides for indiv
492492
- `DATADIR`: **queues/common**: Base DataDir for storing level queues. `DATADIR` for individual queues can be set in `queue.name` sections. Relative paths will be made absolute against `%(APP_DATA_PATH)s`.
493493
- `LENGTH`: **100000**: Maximal queue size before channel queues block
494494
- `BATCH_LENGTH`: **20**: Batch data before passing to the handler
495-
- `CONN_STR`: **redis://127.0.0.1:6379/0**: Connection string for the redis queue type. For `redis-cluster` use `redis+cluster://127.0.0.1:6379/0`. Options can be set using query params. Similarly, LevelDB options can also be set using: **leveldb://relative/path?option=value** or **leveldb:///absolute/path?option=value**, and will override `DATADIR`
495+
- `CONN_STR`: **redis://127.0.0.1:6379/0**: Connection string for the redis queue type. If you're running a Redis cluster, use `redis+cluster://127.0.0.1:6379/0`. Options can be set using query params. Similarly, LevelDB options can also be set using: **leveldb://relative/path?option=value** or **leveldb:///absolute/path?option=value**, and will override `DATADIR`
496496
- `QUEUE_NAME`: **_queue**: The suffix for default redis and disk queue name. Individual queues will default to **`name`**`QUEUE_NAME` but can be overridden in the specific `queue.name` section.
497497
- `SET_NAME`: **_unique**: The suffix that will be added to the default redis and disk queue `set` name for unique queues. Individual queues will default to **`name`**`QUEUE_NAME`_`SET_NAME`_ but can be overridden in the specific `queue.name` section.
498498
- `MAX_WORKERS`: **(dynamic)**: Maximum number of worker go-routines for the queue. Default value is "CpuNum/2" clipped to between 1 and 10.
@@ -777,11 +777,11 @@ and
777777

778778
## Cache (`cache`)
779779

780-
- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, `redis-cluster`, `twoqueue` or `memcache`. (`twoqueue` represents a size limited LRU cache.)
780+
- `ADAPTER`: **memory**: Cache engine adapter, either `memory`, `redis`, `twoqueue` or `memcache`. (`twoqueue` represents a size limited LRU cache.)
781781
- `INTERVAL`: **60**: Garbage Collection interval (sec), for memory and twoqueue cache only.
782-
- `HOST`: **_empty_**: Connection string for `redis`, `redis-cluster` and `memcache`. For `twoqueue` sets configuration for the queue.
782+
- `HOST`: **_empty_**: Connection string for `redis` and `memcache`. For `twoqueue` sets configuration for the queue.
783783
- Redis: `redis://:[email protected]:6379/0?pool_size=100&idle_timeout=180s`
784-
- Redis-cluster `redis+cluster://:[email protected]:6379/0?pool_size=100&idle_timeout=180s`
784+
- For a Redis cluster: `redis+cluster://:[email protected]:6379/0?pool_size=100&idle_timeout=180s`
785785
- Memcache: `127.0.0.1:9090;127.0.0.1:9091`
786786
- TwoQueue LRU cache: `{"size":50000,"recent_ratio":0.25,"ghost_ratio":0.5}` or `50000` representing the maximum number of objects stored in the cache.
787787
- `ITEM_TTL`: **16h**: Time to keep items in cache if not used, Setting it to -1 disables caching.
@@ -793,7 +793,7 @@ and
793793

794794
## Session (`session`)
795795

796-
- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, redis-cluster, db, mysql, couchbase, memcache, postgres\]. Setting `db` will reuse the configuration in `[database]`
796+
- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, db, mysql, couchbase, memcache, postgres\]. Setting `db` will reuse the configuration in `[database]`
797797
- `PROVIDER_CONFIG`: **data/sessions**: For file, the root path; for db, empty (database config will be used); for others, the connection string. Relative paths will be made absolute against _`AppWorkPath`_.
798798
- `COOKIE_SECURE`:**_empty_**: `true` or `false`. Enable this to force using HTTPS for all session access. If not set, it defaults to `true` if the ROOT_URL is an HTTPS URL.
799799
- `COOKIE_NAME`: **i\_like\_gitea**: The name of the cookie used for the session ID.

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
code.gitea.io/sdk/gitea v0.17.1
99
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570
1010
connectrpc.com/connect v1.15.0
11-
gitea.com/go-chi/binding v0.0.0-20240316035258-17450c5f3028
11+
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed
1212
gitea.com/go-chi/cache v0.2.0
1313
gitea.com/go-chi/captcha v0.0.0-20240315150714-fb487f629098
1414
gitea.com/go-chi/session v0.0.0-20240316035857-16768d98ec96
@@ -59,6 +59,7 @@ require (
5959
github.com/google/uuid v1.6.0
6060
github.com/gorilla/feeds v1.1.2
6161
github.com/gorilla/sessions v1.2.2
62+
github.com/h2non/gock v1.2.0
6263
github.com/hashicorp/go-version v1.6.0
6364
github.com/hashicorp/golang-lru/v2 v2.0.7
6465
github.com/huandu/xstrings v1.4.0
@@ -209,6 +210,7 @@ require (
209210
github.com/gorilla/handlers v1.5.2 // indirect
210211
github.com/gorilla/mux v1.8.1 // indirect
211212
github.com/gorilla/securecookie v1.1.2 // indirect
213+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
212214
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
213215
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
214216
github.com/hashicorp/hcl v1.0.0 // indirect

go.sum

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4H
2020
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
2121
gitea.com/gitea/act v0.259.1 h1:8GG1o/xtUHl3qjn5f0h/2FXrT5ubBn05TJOM5ry+FBw=
2222
gitea.com/gitea/act v0.259.1/go.mod h1:UxZWRYqQG2Yj4+4OqfGWW5a3HELwejyWFQyU7F1jUD8=
23-
gitea.com/go-chi/binding v0.0.0-20240316035258-17450c5f3028 h1:6/QAx4+s0dyRwdaTFPTnhGppuiuu0OqxIH9szyTpvKw=
24-
gitea.com/go-chi/binding v0.0.0-20240316035258-17450c5f3028/go.mod h1:E3i3cgB04dDx0v3CytCgRTTn9Z/9x891aet3r456RVw=
23+
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed h1:EZZBtilMLSZNWtHHcgq2mt6NSGhJSZBuduAlinMEmso=
24+
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed/go.mod h1:E3i3cgB04dDx0v3CytCgRTTn9Z/9x891aet3r456RVw=
2525
gitea.com/go-chi/cache v0.2.0 h1:E0npuTfDW6CT1yD8NMDVc1SK6IeRjfmRL2zlEsCEd7w=
2626
gitea.com/go-chi/cache v0.2.0/go.mod h1:iQlVK2aKTZ/rE9UcHyz9pQWGvdP9i1eI2spOpzgCrtE=
2727
gitea.com/go-chi/captcha v0.0.0-20240315150714-fb487f629098 h1:p2ki+WK0cIeNQuqjR98IP2KZQKRzJJiV7aTeMAFwaWo=
@@ -430,6 +430,10 @@ github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pw
430430
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
431431
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
432432
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
433+
github.com/h2non/gock v1.2.0 h1:K6ol8rfrRkUOefooBC8elXoaNGYkpp7y2qcxGG6BzUE=
434+
github.com/h2non/gock v1.2.0/go.mod h1:tNhoxHYW2W42cYkYb1WqzdbYIieALC99kpYr7rH/BQk=
435+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
436+
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
433437
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
434438
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
435439
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
@@ -591,6 +595,8 @@ github.com/mschoch/smat v0.2.0 h1:8imxQsjDm8yFEAVBe7azKmKSgzSkZXDuKkSq9374khM=
591595
github.com/mschoch/smat v0.2.0/go.mod h1:kc9mz7DoBKqDyiRL7VZN8KvXQMWeTaVnttLRXOlotKw=
592596
github.com/msteinert/pam v1.2.0 h1:mYfjlvN2KYs2Pb9G6nb/1f/nPfAttT/Jee5Sq9r3bGE=
593597
github.com/msteinert/pam v1.2.0/go.mod h1:d2n0DCUK8rGecChV3JzvmsDjOY4R7AYbsNxAT+ftQl0=
598+
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
599+
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
594600
github.com/niklasfasching/go-org v1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMimOjGMek=
595601
github.com/niklasfasching/go-org v1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o=
596602
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=

models/git/commit_status.go

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -397,36 +397,16 @@ func GetLatestCommitStatusForRepoCommitIDs(ctx context.Context, repoID int64, co
397397

398398
// FindRepoRecentCommitStatusContexts returns repository's recent commit status contexts
399399
func FindRepoRecentCommitStatusContexts(ctx context.Context, repoID int64, before time.Duration) ([]string, error) {
400-
type result struct {
401-
Index int64
402-
SHA string
403-
}
404-
getBase := func() *xorm.Session {
405-
return db.GetEngine(ctx).Table(&CommitStatus{}).Where("repo_id = ?", repoID)
406-
}
407-
408400
start := timeutil.TimeStampNow().AddDuration(-before)
409-
results := make([]result, 0, 10)
410401

411-
sess := getBase().And("updated_unix >= ?", start).
412-
Select("max( `index` ) as `index`, sha").
413-
GroupBy("context_hash, sha").OrderBy("max( `index` ) desc")
414-
415-
err := sess.Find(&results)
416-
if err != nil {
402+
var contexts []string
403+
if err := db.GetEngine(ctx).Table("commit_status").
404+
Where("repo_id = ?", repoID).And("updated_unix >= ?", start).
405+
Cols("context").Distinct().Find(&contexts); err != nil {
417406
return nil, err
418407
}
419408

420-
contexts := make([]string, 0, len(results))
421-
if len(results) == 0 {
422-
return contexts, nil
423-
}
424-
425-
conds := make([]builder.Cond, 0, len(results))
426-
for _, result := range results {
427-
conds = append(conds, builder.Eq{"`index`": result.Index, "sha": result.SHA})
428-
}
429-
return contexts, getBase().And(builder.Or(conds...)).Select("context").Find(&contexts)
409+
return contexts, nil
430410
}
431411

432412
// NewCommitStatusOptions holds options for creating a CommitStatus

models/git/commit_status_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ package git_test
55

66
import (
77
"testing"
8+
"time"
89

910
"code.gitea.io/gitea/models/db"
1011
git_model "code.gitea.io/gitea/models/git"
1112
repo_model "code.gitea.io/gitea/models/repo"
1213
"code.gitea.io/gitea/models/unittest"
14+
user_model "code.gitea.io/gitea/models/user"
15+
"code.gitea.io/gitea/modules/git"
16+
"code.gitea.io/gitea/modules/gitrepo"
1317
"code.gitea.io/gitea/modules/structs"
1418

1519
"github.com/stretchr/testify/assert"
@@ -175,3 +179,55 @@ func Test_CalcCommitStatus(t *testing.T) {
175179
assert.Equal(t, kase.expected, git_model.CalcCommitStatus(kase.statuses))
176180
}
177181
}
182+
183+
func TestFindRepoRecentCommitStatusContexts(t *testing.T) {
184+
assert.NoError(t, unittest.PrepareTestDatabase())
185+
186+
repo2 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 2})
187+
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
188+
gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo2)
189+
assert.NoError(t, err)
190+
defer gitRepo.Close()
191+
192+
commit, err := gitRepo.GetBranchCommit(repo2.DefaultBranch)
193+
assert.NoError(t, err)
194+
195+
defer func() {
196+
_, err := db.DeleteByBean(db.DefaultContext, &git_model.CommitStatus{
197+
RepoID: repo2.ID,
198+
CreatorID: user2.ID,
199+
SHA: commit.ID.String(),
200+
})
201+
assert.NoError(t, err)
202+
}()
203+
204+
err = git_model.NewCommitStatus(db.DefaultContext, git_model.NewCommitStatusOptions{
205+
Repo: repo2,
206+
Creator: user2,
207+
SHA: commit.ID,
208+
CommitStatus: &git_model.CommitStatus{
209+
State: structs.CommitStatusFailure,
210+
TargetURL: "https://example.com/tests/",
211+
Context: "compliance/lint-backend",
212+
},
213+
})
214+
assert.NoError(t, err)
215+
216+
err = git_model.NewCommitStatus(db.DefaultContext, git_model.NewCommitStatusOptions{
217+
Repo: repo2,
218+
Creator: user2,
219+
SHA: commit.ID,
220+
CommitStatus: &git_model.CommitStatus{
221+
State: structs.CommitStatusSuccess,
222+
TargetURL: "https://example.com/tests/",
223+
Context: "compliance/lint-backend",
224+
},
225+
})
226+
assert.NoError(t, err)
227+
228+
contexts, err := git_model.FindRepoRecentCommitStatusContexts(db.DefaultContext, repo2.ID, time.Hour)
229+
assert.NoError(t, err)
230+
if assert.Len(t, contexts, 1) {
231+
assert.Equal(t, "compliance/lint-backend", contexts[0])
232+
}
233+
}

0 commit comments

Comments
 (0)