Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaoffical/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Jan 25, 2022
2 parents ab961b4 + 93250bf commit 0579c7b
Show file tree
Hide file tree
Showing 24 changed files with 155 additions and 28 deletions.
12 changes: 6 additions & 6 deletions contrib/ide/vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"request": "launch",
"mode": "debug",
"buildFlags": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/main.go",
"env": {},
"env": {
"GITEA_WORK_DIR": "${workspaceRoot}",
},
"args": ["web"],
"showLog": true
},
Expand All @@ -20,10 +20,10 @@
"request": "launch",
"mode": "debug",
"buildFlags": "-tags='sqlite sqlite_unlock_notify'",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/main.go",
"env": {},
"env": {
"GITEA_WORK_DIR": "${workspaceRoot}",
},
"args": ["web"],
"showLog": true
}
Expand Down
24 changes: 24 additions & 0 deletions models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,30 @@ func (repo *Repository) MustOwner() *user_model.User {
return repo.mustOwner(db.DefaultContext)
}

// LoadAttributes loads attributes of the repository.
func (repo *Repository) LoadAttributes(ctx context.Context) error {
// Load owner
if err := repo.GetOwner(ctx); err != nil {
return fmt.Errorf("load owner: %w", err)
}

// Load primary language
stats := make(LanguageStatList, 0, 1)
if err := db.GetEngine(ctx).
Where("`repo_id` = ? AND `is_primary` = ? AND `language` != ?", repo.ID, true, "other").
Find(&stats); err != nil {
return fmt.Errorf("find primary languages: %w", err)
}
stats.LoadAttributes()
for _, st := range stats {
if st.RepoID == repo.ID {
repo.PrimaryLanguage = st
break
}
}
return nil
}

// FullName returns the repository full name
func (repo *Repository) FullName() string {
return repo.OwnerName + "/" + repo.Name
Expand Down
4 changes: 2 additions & 2 deletions models/repo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func FindUserAccessibleRepoIDs(user *user_model.User) ([]int64, error) {
}

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

sess = sess.Where(cond).OrderBy(opts.OrderBy.String())
repos := make([]*repo_model.Repository, 0, opts.PageSize)
repos := make(RepositoryList, 0, opts.PageSize)
return repos, count, db.SetSessionPagination(sess, opts).Find(&repos)
}
9 changes: 9 additions & 0 deletions modules/convert/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
}
}

var language string
if repo.PrimaryLanguage != nil {
language = repo.PrimaryLanguage.Language
}

repoAPIURL := repo.APIURL()

return &api.Repository{
ID: repo.ID,
Owner: ToUserWithAccessMode(repo.Owner, mode),
Expand All @@ -144,6 +151,8 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo
CloneURL: cloneLink.HTTPS,
OriginalURL: repo.SanitizedOriginalURL(),
Website: repo.Website,
Language: language,
LanguagesURL: repoAPIURL + "/languages",
Stars: repo.NumStars,
Forks: repo.NumForks,
Watchers: repo.NumWatches,
Expand Down
2 changes: 1 addition & 1 deletion modules/queue/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func RegisteredTypesAsString() []string {
func NewQueue(queueType Type, handlerFunc HandlerFunc, opts, exemplar interface{}) (Queue, error) {
newFn, ok := queuesMap[queueType]
if !ok {
return nil, fmt.Errorf("Unsupported queue type: %v", queueType)
return nil, fmt.Errorf("unsupported queue type: %v", queueType)
}
return newFn(handlerFunc, opts, exemplar)
}
6 changes: 3 additions & 3 deletions modules/queue/queue_bytefifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (q *ByteFIFOQueue) Push(data Data) error {
// PushBack pushes data to the fifo
func (q *ByteFIFOQueue) PushBack(data Data) error {
if !assignableTo(data, q.exemplar) {
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
return fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
}
bs, err := json.Marshal(data)
if err != nil {
Expand All @@ -110,7 +110,7 @@ func (q *ByteFIFOQueue) PushBack(data Data) error {
// PushFunc pushes data to the fifo
func (q *ByteFIFOQueue) PushFunc(data Data, fn func() error) error {
if !assignableTo(data, q.exemplar) {
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
return fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
}
bs, err := json.Marshal(data)
if err != nil {
Expand Down Expand Up @@ -398,7 +398,7 @@ func NewByteFIFOUniqueQueue(typ Type, byteFIFO UniqueByteFIFO, handle HandlerFun
// Has checks if the provided data is in the queue
func (q *ByteFIFOUniqueQueue) Has(data Data) (bool, error) {
if !assignableTo(data, q.exemplar) {
return false, fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
return false, fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
}
bs, err := json.Marshal(data)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion modules/queue/queue_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (q *ChannelQueue) Run(atShutdown, atTerminate func(func())) {
// Push will push data into the queue
func (q *ChannelQueue) Push(data Data) error {
if !assignableTo(data, q.exemplar) {
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in queue: %s", data, q.exemplar, q.name)
return fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in queue: %s", data, q.exemplar, q.name)
}
q.WorkerPool.Push(data)
return nil
Expand Down
46 changes: 43 additions & 3 deletions modules/queue/queue_wrapped.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (q *delayedStarter) setInternal(atShutdown func(func()), handle HandlerFunc
if s, ok := cfg.([]byte); ok {
cfg = string(s)
}
return fmt.Errorf("Timedout creating queue %v with cfg %#v in %s", q.underlying, cfg, q.name)
return fmt.Errorf("timedout creating queue %v with cfg %#v in %s", q.underlying, cfg, q.name)
default:
queue, err := NewQueue(q.underlying, handle, q.cfg, exemplar)
if err == nil {
Expand All @@ -76,9 +76,9 @@ func (q *delayedStarter) setInternal(atShutdown func(func()), handle HandlerFunc
i++
if q.maxAttempts > 0 && i > q.maxAttempts {
if bs, ok := q.cfg.([]byte); ok {
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)
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)
}
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)
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)
}
sleepTime := 100 * time.Millisecond
if q.timeout > 0 && q.maxAttempts > 0 {
Expand Down Expand Up @@ -271,6 +271,46 @@ func (q *WrappedQueue) Terminate() {
log.Debug("WrappedQueue: %s Terminated", q.name)
}

// IsPaused will return if the pool or queue is paused
func (q *WrappedQueue) IsPaused() bool {
q.lock.Lock()
defer q.lock.Unlock()
pausable, ok := q.internal.(Pausable)
return ok && pausable.IsPaused()
}

// Pause will pause the pool or queue
func (q *WrappedQueue) Pause() {
q.lock.Lock()
defer q.lock.Unlock()
if pausable, ok := q.internal.(Pausable); ok {
pausable.Pause()
}
}

// Resume will resume the pool or queue
func (q *WrappedQueue) Resume() {
q.lock.Lock()
defer q.lock.Unlock()
if pausable, ok := q.internal.(Pausable); ok {
pausable.Resume()
}
}

// IsPausedIsResumed will return a bool indicating if the pool or queue is paused and a channel that will be closed when it is resumed
func (q *WrappedQueue) IsPausedIsResumed() (paused, resumed <-chan struct{}) {
q.lock.Lock()
defer q.lock.Unlock()
if pausable, ok := q.internal.(Pausable); ok {
return pausable.IsPausedIsResumed()
}
return context.Background().Done(), closedChan
}

var closedChan chan struct{}

func init() {
queuesMap[WrappedQueueType] = NewWrappedQueue
closedChan = make(chan struct{})
close(closedChan)
}
2 changes: 1 addition & 1 deletion modules/queue/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func validType(t string) (Type, error) {
return typ, nil
}
}
return PersistableChannelQueueType, fmt.Errorf("Unknown queue type: %s defaulting to %s", t, string(PersistableChannelQueueType))
return PersistableChannelQueueType, fmt.Errorf("unknown queue type: %s defaulting to %s", t, string(PersistableChannelQueueType))
}

func getQueueSettings(name string) (setting.QueueSettings, []byte) {
Expand Down
2 changes: 1 addition & 1 deletion modules/queue/unique_queue_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (q *ChannelUniqueQueue) Push(data Data) error {
// PushFunc will push data into the queue
func (q *ChannelUniqueQueue) PushFunc(data Data, fn func() error) error {
if !assignableTo(data, q.exemplar) {
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in queue: %s", data, q.exemplar, q.name)
return fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in queue: %s", data, q.exemplar, q.name)
}

bs, err := json.Marshal(data)
Expand Down
20 changes: 20 additions & 0 deletions modules/queue/unique_queue_disk_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,26 @@ func (q *PersistableChannelUniqueQueue) IsEmpty() bool {
return q.channelQueue.IsEmpty()
}

// IsPaused will return if the pool or queue is paused
func (q *PersistableChannelUniqueQueue) IsPaused() bool {
return q.channelQueue.IsPaused()
}

// Pause will pause the pool or queue
func (q *PersistableChannelUniqueQueue) Pause() {
q.channelQueue.Pause()
}

// Resume will resume the pool or queue
func (q *PersistableChannelUniqueQueue) Resume() {
q.channelQueue.Resume()
}

// IsPausedIsResumed will return a bool indicating if the pool or queue is paused and a channel that will be closed when it is resumed
func (q *PersistableChannelUniqueQueue) IsPausedIsResumed() (paused, resumed <-chan struct{}) {
return q.channelQueue.IsPausedIsResumed()
}

// Shutdown processing this queue
func (q *PersistableChannelUniqueQueue) Shutdown() {
log.Trace("PersistableChannelUniqueQueue: %s Shutting down", q.delayedStarter.name)
Expand Down
2 changes: 1 addition & 1 deletion modules/queue/unique_queue_wrapped.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (q *WrappedUniqueQueue) Push(data Data) error {
// PushFunc will push the data to the internal channel checking it against the exemplar
func (q *WrappedUniqueQueue) PushFunc(data Data, fn func() error) error {
if !assignableTo(data, q.exemplar) {
return fmt.Errorf("Unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
return fmt.Errorf("unable to assign data: %v to same type as exemplar: %v in %s", data, q.exemplar, q.name)
}

q.tlock.Lock()
Expand Down
4 changes: 1 addition & 3 deletions modules/queue/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,12 @@ func NewWorkerPool(handle HandlerFunc, config WorkerPoolConfiguration) *WorkerPo
ctx, cancel := context.WithCancel(context.Background())

dataChan := make(chan Data, config.QueueLength)
resumed := make(chan struct{})
close(resumed)
pool := &WorkerPool{
baseCtx: ctx,
baseCtxCancel: cancel,
batchLength: config.BatchLength,
dataChan: dataChan,
resumed: resumed,
resumed: closedChan,
paused: make(chan struct{}),
handle: handle,
blockTimeout: config.BlockTimeout,
Expand Down
2 changes: 2 additions & 0 deletions modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type Repository struct {
Parent *Repository `json:"parent"`
Mirror bool `json:"mirror"`
Size int `json:"size"`
Language string `json:"language"`
LanguagesURL string `json:"languages_url"`
HTMLURL string `json:"html_url"`
SSHURL string `json:"ssh_url"`
CloneURL string `json:"clone_url"`
Expand Down
4 changes: 4 additions & 0 deletions options/locale/locale_pt-PT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,10 @@ settings.add_matrix_hook_desc=Integrar <a href="%s">Matrix</a> no seu repositór
settings.add_msteams_hook_desc=Integrar <a href="%s">Microsoft Teams</a> no seu repositório.
settings.add_feishu_hook_desc=Integrar <a href="%s">Feishu</a> no seu repositório.
settings.add_Wechat_hook_desc=Integrar <a href="%s">Wechatwork</a> no seu repositório.
settings.add_packagist_hook_desc=Integrar <a href="%s">Packagist</a> no seu repositório.
settings.packagist_username=Nome de utilizador no Packagist
settings.packagist_api_token=Código da API
settings.packagist_package_url=URL do pacote Packagist
settings.deploy_keys=Chaves de instalação
settings.add_deploy_key=Adicionar chave de instalação
settings.deploy_key_desc=Chaves de instalação têm acesso para puxar do repositório apenas em modo de leitura.
Expand Down
4 changes: 4 additions & 0 deletions options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,10 @@ settings.add_matrix_hook_desc=将 <a href="%s">Matrix</a> 集成到您的仓库
settings.add_msteams_hook_desc=将 <a href="%s">Microsoft Teams</a> 集成到您的仓库中。
settings.add_feishu_hook_desc=将 <a href="%s">Feishu</a> 集成到您的仓库中。
settings.add_Wechat_hook_desc=将 <a href="%s">企业微信</a> 集成到您的仓库中。
settings.add_packagist_hook_desc=将 <a href="%s">Packagist</a> 集成到您的仓库中。
settings.packagist_username=Packagist 用户名
settings.packagist_api_token=API 令牌
settings.packagist_package_url=Packagist 软件包 URL
settings.deploy_keys=部署密钥
settings.add_deploy_key=添加部署密钥
settings.deploy_key_desc=部署密钥具有对仓库的只读拉取权限。
Expand Down
5 changes: 5 additions & 0 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ func Get(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/Repository"

if err := ctx.Repo.Repository.LoadAttributes(ctx); err != nil {
ctx.Error(http.StatusInternalServerError, "Repository.LoadAttributes", err)
return
}

ctx.JSON(http.StatusOK, convert.ToRepo(ctx.Repo.Repository, ctx.Repo.AccessMode))
}

Expand Down
5 changes: 5 additions & 0 deletions routers/api/v1/user/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) {
return
}

if err := repos.LoadAttributes(); err != nil {
ctx.Error(http.StatusInternalServerError, "RepositoryList.LoadAttributes", err)
return
}

apiRepos := make([]*api.Repository, 0, len(repos))
for i := range repos {
access, err := models.AccessLevel(ctx.User, repos[i])
Expand Down
3 changes: 3 additions & 0 deletions services/migrations/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (r *RepositoryRestorer) GetTopics() ([]string, error) {

bs, err := os.ReadFile(p)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}

Expand Down
6 changes: 5 additions & 1 deletion templates/repo/commits_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@
<pre class="commit-body" style="display: none;">{{RenderCommitBody $.Context .Message $commitRepoLink $.Repository.ComposeMetas}}</pre>
{{end}}
</td>
<td class="text right aligned">{{TimeSince .Author.When $.Lang}}</td>
{{if .Committer}}
<td class="text right aligned">{{TimeSince .Committer.When $.Lang}}</td>
{{else}}
<td class="text right aligned">{{TimeSince .Author.When $.Lang}}</td>
{{end}}
</tr>
{{end}}
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/view_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</span>
{{end}}
</th>
<th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Author}}{{TimeSince .LatestCommit.Author.When $.Lang}}{{end}}{{end}}</th>
<th class="text grey right age">{{if .LatestCommit}}{{if .LatestCommit.Committer}}{{TimeSince .LatestCommit.Committer.When $.Lang}}{{end}}{{end}}</th>
</tr>
</thead>
<tbody>
Expand Down
8 changes: 8 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17188,6 +17188,14 @@
"internal_tracker": {
"$ref": "#/definitions/InternalTracker"
},
"language": {
"type": "string",
"x-go-name": "Language"
},
"languages_url": {
"type": "string",
"x-go-name": "LanguagesURL"
},
"mirror": {
"type": "boolean",
"x-go-name": "Mirror"
Expand Down
2 changes: 2 additions & 0 deletions web_src/js/features/repo-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,11 @@ export function initRepoPullRequestReview() {
<tr class="add-comment" data-line-type="${lineType}">
${isSplit ? `
<td class="lines-num"></td>
<td class="lines-escape"></td>
<td class="lines-type-marker"></td>
<td class="add-comment-left"></td>
<td class="lines-num"></td>
<td class="lines-escape"></td>
<td class="lines-type-marker"></td>
<td class="add-comment-right"></td>
` : `
Expand Down
Loading

0 comments on commit 0579c7b

Please sign in to comment.