Skip to content

Commit 0579c7b

Browse files
committed
Merge remote-tracking branch 'giteaoffical/main'
* giteaoffical/main: Place inline diff comment dialogs on split diff in 4th and 8th columns (go-gitea#18403) API: Return primary language and repository language stats API URL (go-gitea#18396) Update to work with latest VS Code go debugger (go-gitea#18397) Fix restore without topic failure (go-gitea#18387) [skip ci] Updated translations via Crowdin Make WrappedQueues and PersistableChannelUniqueQueues Pausable (go-gitea#18393) Fix commit's time (go-gitea#18375) Prevent showing webauthn error for every time visiting `/user/settings/security` (go-gitea#18385)
2 parents ab961b4 + 93250bf commit 0579c7b

File tree

24 files changed

+155
-28
lines changed

24 files changed

+155
-28
lines changed

contrib/ide/vscode/launch.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"request": "launch",
88
"mode": "debug",
99
"buildFlags": "",
10-
"port": 2345,
11-
"host": "127.0.0.1",
1210
"program": "${workspaceRoot}/main.go",
13-
"env": {},
11+
"env": {
12+
"GITEA_WORK_DIR": "${workspaceRoot}",
13+
},
1414
"args": ["web"],
1515
"showLog": true
1616
},
@@ -20,10 +20,10 @@
2020
"request": "launch",
2121
"mode": "debug",
2222
"buildFlags": "-tags='sqlite sqlite_unlock_notify'",
23-
"port": 2345,
24-
"host": "127.0.0.1",
2523
"program": "${workspaceRoot}/main.go",
26-
"env": {},
24+
"env": {
25+
"GITEA_WORK_DIR": "${workspaceRoot}",
26+
},
2727
"args": ["web"],
2828
"showLog": true
2929
}

models/repo/repo.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,30 @@ func (repo *Repository) MustOwner() *user_model.User {
222222
return repo.mustOwner(db.DefaultContext)
223223
}
224224

225+
// LoadAttributes loads attributes of the repository.
226+
func (repo *Repository) LoadAttributes(ctx context.Context) error {
227+
// Load owner
228+
if err := repo.GetOwner(ctx); err != nil {
229+
return fmt.Errorf("load owner: %w", err)
230+
}
231+
232+
// Load primary language
233+
stats := make(LanguageStatList, 0, 1)
234+
if err := db.GetEngine(ctx).
235+
Where("`repo_id` = ? AND `is_primary` = ? AND `language` != ?", repo.ID, true, "other").
236+
Find(&stats); err != nil {
237+
return fmt.Errorf("find primary languages: %w", err)
238+
}
239+
stats.LoadAttributes()
240+
for _, st := range stats {
241+
if st.RepoID == repo.ID {
242+
repo.PrimaryLanguage = st
243+
break
244+
}
245+
}
246+
return nil
247+
}
248+
225249
// FullName returns the repository full name
226250
func (repo *Repository) FullName() string {
227251
return repo.OwnerName + "/" + repo.Name

models/repo_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ func FindUserAccessibleRepoIDs(user *user_model.User) ([]int64, error) {
623623
}
624624

625625
// GetUserRepositories returns a list of repositories of given user.
626-
func GetUserRepositories(opts *SearchRepoOptions) ([]*repo_model.Repository, int64, error) {
626+
func GetUserRepositories(opts *SearchRepoOptions) (RepositoryList, int64, error) {
627627
if len(opts.OrderBy) == 0 {
628628
opts.OrderBy = "updated_unix DESC"
629629
}
@@ -646,6 +646,6 @@ func GetUserRepositories(opts *SearchRepoOptions) ([]*repo_model.Repository, int
646646
}
647647

648648
sess = sess.Where(cond).OrderBy(opts.OrderBy.String())
649-
repos := make([]*repo_model.Repository, 0, opts.PageSize)
649+
repos := make(RepositoryList, 0, opts.PageSize)
650650
return repos, count, db.SetSessionPagination(sess, opts).Find(&repos)
651651
}

modules/convert/repository.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
125125
}
126126
}
127127

128+
var language string
129+
if repo.PrimaryLanguage != nil {
130+
language = repo.PrimaryLanguage.Language
131+
}
132+
133+
repoAPIURL := repo.APIURL()
134+
128135
return &api.Repository{
129136
ID: repo.ID,
130137
Owner: ToUserWithAccessMode(repo.Owner, mode),
@@ -144,6 +151,8 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
144151
CloneURL: cloneLink.HTTPS,
145152
OriginalURL: repo.SanitizedOriginalURL(),
146153
Website: repo.Website,
154+
Language: language,
155+
LanguagesURL: repoAPIURL + "/languages",
147156
Stars: repo.NumStars,
148157
Forks: repo.NumForks,
149158
Watchers: repo.NumWatches,

modules/queue/queue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func RegisteredTypesAsString() []string {
196196
func NewQueue(queueType Type, handlerFunc HandlerFunc, opts, exemplar interface{}) (Queue, error) {
197197
newFn, ok := queuesMap[queueType]
198198
if !ok {
199-
return nil, fmt.Errorf("Unsupported queue type: %v", queueType)
199+
return nil, fmt.Errorf("unsupported queue type: %v", queueType)
200200
}
201201
return newFn(handlerFunc, opts, exemplar)
202202
}

modules/queue/queue_bytefifo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (q *ByteFIFOQueue) Push(data Data) error {
9292
// PushBack pushes data to the fifo
9393
func (q *ByteFIFOQueue) PushBack(data Data) error {
9494
if !assignableTo(data, q.exemplar) {
95-
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
95+
return fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
9696
}
9797
bs, err := json.Marshal(data)
9898
if err != nil {
@@ -110,7 +110,7 @@ func (q *ByteFIFOQueue) PushBack(data Data) error {
110110
// PushFunc pushes data to the fifo
111111
func (q *ByteFIFOQueue) PushFunc(data Data, fn func() error) error {
112112
if !assignableTo(data, q.exemplar) {
113-
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
113+
return fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
114114
}
115115
bs, err := json.Marshal(data)
116116
if err != nil {
@@ -398,7 +398,7 @@ func NewByteFIFOUniqueQueue(typ Type, byteFIFO UniqueByteFIFO, handle HandlerFun
398398
// Has checks if the provided data is in the queue
399399
func (q *ByteFIFOUniqueQueue) Has(data Data) (bool, error) {
400400
if !assignableTo(data, q.exemplar) {
401-
return false, fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
401+
return false, fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
402402
}
403403
bs, err := json.Marshal(data)
404404
if err != nil {

modules/queue/queue_channel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (q *ChannelQueue) Run(atShutdown, atTerminate func(func())) {
9393
// Push will push data into the queue
9494
func (q *ChannelQueue) Push(data Data) error {
9595
if !assignableTo(data, q.exemplar) {
96-
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in queue: %s", data, q.exemplar, q.name)
96+
return fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in queue: %s", data, q.exemplar, q.name)
9797
}
9898
q.WorkerPool.Push(data)
9999
return nil

modules/queue/queue_wrapped.go

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (q *delayedStarter) setInternal(atShutdown func(func()), handle HandlerFunc
5959
if s, ok := cfg.([]byte); ok {
6060
cfg = string(s)
6161
}
62-
return fmt.Errorf("Timedout creating queue %v with cfg %#v in %s", q.underlying, cfg, q.name)
62+
return fmt.Errorf("timedout creating queue %v with cfg %#v in %s", q.underlying, cfg, q.name)
6363
default:
6464
queue, err := NewQueue(q.underlying, handle, q.cfg, exemplar)
6565
if err == nil {
@@ -76,9 +76,9 @@ func (q *delayedStarter) setInternal(atShutdown func(func()), handle HandlerFunc
7676
i++
7777
if q.maxAttempts > 0 && i > q.maxAttempts {
7878
if bs, ok := q.cfg.([]byte); ok {
79-
return fmt.Errorf("Unable to create queue %v for %s with cfg %s by max attempts: error: %v", q.underlying, q.name, string(bs), err)
79+
return fmt.Errorf("unable to create queue %v for %s with cfg %s by max attempts: error: %v", q.underlying, q.name, string(bs), err)
8080
}
81-
return fmt.Errorf("Unable to create queue %v for %s with cfg %#v by max attempts: error: %v", q.underlying, q.name, q.cfg, err)
81+
return fmt.Errorf("unable to create queue %v for %s with cfg %#v by max attempts: error: %v", q.underlying, q.name, q.cfg, err)
8282
}
8383
sleepTime := 100 * time.Millisecond
8484
if q.timeout > 0 && q.maxAttempts > 0 {
@@ -271,6 +271,46 @@ func (q *WrappedQueue) Terminate() {
271271
log.Debug("WrappedQueue: %s Terminated", q.name)
272272
}
273273

274+
// IsPaused will return if the pool or queue is paused
275+
func (q *WrappedQueue) IsPaused() bool {
276+
q.lock.Lock()
277+
defer q.lock.Unlock()
278+
pausable, ok := q.internal.(Pausable)
279+
return ok && pausable.IsPaused()
280+
}
281+
282+
// Pause will pause the pool or queue
283+
func (q *WrappedQueue) Pause() {
284+
q.lock.Lock()
285+
defer q.lock.Unlock()
286+
if pausable, ok := q.internal.(Pausable); ok {
287+
pausable.Pause()
288+
}
289+
}
290+
291+
// Resume will resume the pool or queue
292+
func (q *WrappedQueue) Resume() {
293+
q.lock.Lock()
294+
defer q.lock.Unlock()
295+
if pausable, ok := q.internal.(Pausable); ok {
296+
pausable.Resume()
297+
}
298+
}
299+
300+
// IsPausedIsResumed will return a bool indicating if the pool or queue is paused and a channel that will be closed when it is resumed
301+
func (q *WrappedQueue) IsPausedIsResumed() (paused, resumed <-chan struct{}) {
302+
q.lock.Lock()
303+
defer q.lock.Unlock()
304+
if pausable, ok := q.internal.(Pausable); ok {
305+
return pausable.IsPausedIsResumed()
306+
}
307+
return context.Background().Done(), closedChan
308+
}
309+
310+
var closedChan chan struct{}
311+
274312
func init() {
275313
queuesMap[WrappedQueueType] = NewWrappedQueue
314+
closedChan = make(chan struct{})
315+
close(closedChan)
276316
}

modules/queue/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func validType(t string) (Type, error) {
2222
return typ, nil
2323
}
2424
}
25-
return PersistableChannelQueueType, fmt.Errorf("Unknown queue type: %s defaulting to %s", t, string(PersistableChannelQueueType))
25+
return PersistableChannelQueueType, fmt.Errorf("unknown queue type: %s defaulting to %s", t, string(PersistableChannelQueueType))
2626
}
2727

2828
func getQueueSettings(name string) (setting.QueueSettings, []byte) {

modules/queue/unique_queue_channel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (q *ChannelUniqueQueue) Push(data Data) error {
111111
// PushFunc will push data into the queue
112112
func (q *ChannelUniqueQueue) PushFunc(data Data, fn func() error) error {
113113
if !assignableTo(data, q.exemplar) {
114-
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in queue: %s", data, q.exemplar, q.name)
114+
return fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in queue: %s", data, q.exemplar, q.name)
115115
}
116116

117117
bs, err := json.Marshal(data)

0 commit comments

Comments
 (0)