Skip to content

Commit

Permalink
Merge branch 'main' into simplify-split-view-generation
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks authored Aug 29, 2021
2 parents 509e35e + d24eb6e commit e1ba0f4
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 36 deletions.
11 changes: 0 additions & 11 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,6 @@ steps:
GITHUB_READ_TOKEN:
from_secret: github_read_token

- name: unit-test-race
image: golang:1.17
commands:
- make test-backend
environment:
GOPROXY: off
TAGS: sqlite sqlite_unlock_notify
RACE_ENABLED: true
GITHUB_READ_TOKEN:
from_secret: github_read_token

- name: unit-test-gogit
pull: always
image: golang:1.17
Expand Down
13 changes: 13 additions & 0 deletions docs/content/doc/developers/hacking-on-gitea.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,19 @@ Visual Studio Code. Look at
[`contrib/ide/README.md`](https://github.com/go-gitea/gitea/blob/main/contrib/ide/README.md)
for more information.

## GoLand

Clicking the `Run Application` arrow on the function `func main()` in `/main.go`
can quickly start a debuggable gitea instance.

The `Output Directory` in `Run/Debug Configuration` MUST be set to the
gitea project directory (which contains `main.go` and `go.mod`),
otherwise, the started instance's working directory is a GoLand's temporary directory
and prevents gitea from loading dynamic resources (eg: templates) in a development environment.

To run unit tests with SQLite in GoLand, set `-tags sqlite,sqlite_unlock_notify`
in `Go tool arguments` of `Run/Debug Configuration`.

## Submitting PRs

Once you're happy with your changes, push them up and open a pull request. It
Expand Down
6 changes: 5 additions & 1 deletion integrations/pull_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *models.User) *models.PullReq
assert.NoError(t, err)
assert.NotEmpty(t, baseRepo)

headRepo, err := repo_module.ForkRepository(actor, forkOrg, baseRepo, "repo-pr-update", "desc")
headRepo, err := repo_module.ForkRepository(actor, forkOrg, models.ForkRepoOptions{
BaseRepo: baseRepo,
Name: "repo-pr-update",
Description: "desc",
})
assert.NoError(t, err)
assert.NotEmpty(t, headRepo)

Expand Down
46 changes: 46 additions & 0 deletions models/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
package models

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"code.gitea.io/gitea/modules/setting"
"xorm.io/xorm/schemas"

"github.com/stretchr/testify/assert"
)
Expand All @@ -32,3 +35,46 @@ func TestDumpDatabase(t *testing.T) {
assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType))
}
}

type TestSource struct {
Provider string
ClientID string
ClientSecret string
OpenIDConnectAutoDiscoveryURL string
IconURL string
}

// FromDB fills up a LDAPConfig from serialized format.
func (source *TestSource) FromDB(bs []byte) error {
return json.Unmarshal(bs, &source)
}

// ToDB exports a LDAPConfig to a serialized format.
func (source *TestSource) ToDB() ([]byte, error) {
return json.Marshal(source)
}

func TestDumpLoginSource(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

loginSourceSchema, err := x.TableInfo(new(LoginSource))
assert.NoError(t, err)

RegisterLoginTypeConfig(LoginOAuth2, new(TestSource))

CreateLoginSource(&LoginSource{
Type: LoginOAuth2,
Name: "TestSource",
IsActive: false,
Cfg: &TestSource{
Provider: "ConvertibleSourceName",
ClientID: "42",
},
})

sb := new(strings.Builder)

x.DumpTables([]*schemas.Table{loginSourceSchema}, sb)

assert.Contains(t, sb.String(), `"Provider":"ConvertibleSourceName"`)
}
7 changes: 7 additions & 0 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,13 @@ type CreateRepoOptions struct {
MirrorInterval string
}

// ForkRepoOptions contains the fork repository options
type ForkRepoOptions struct {
BaseRepo *Repository
Name string
Description string
}

// GetRepoInitFile returns repository init files
func GetRepoInitFile(tp, name string) ([]byte, error) {
cleanedName := strings.TrimLeft(path.Clean("/"+name), "/")
Expand Down
8 changes: 7 additions & 1 deletion modules/markup/external/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"runtime"
"strings"

"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/process"
Expand Down Expand Up @@ -99,7 +100,12 @@ func (p *Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.
}

if ctx == nil || ctx.Ctx == nil {
return fmt.Errorf("RenderContext did not provide context")
if ctx == nil {
log.Warn("RenderContext not provided defaulting to empty ctx")
ctx = &markup.RenderContext{}
}
log.Warn("RenderContext did not provide context, defaulting to Shutdown context")
ctx.Ctx = graceful.GetManager().ShutdownContext()
}

processCtx, cancel := context.WithCancel(ctx.Ctx)
Expand Down
32 changes: 16 additions & 16 deletions modules/repository/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import (
)

// ForkRepository forks a repository
func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name, desc string) (_ *models.Repository, err error) {
forkedRepo, err := oldRepo.GetUserFork(owner.ID)
func ForkRepository(doer, owner *models.User, opts models.ForkRepoOptions) (_ *models.Repository, err error) {
forkedRepo, err := opts.BaseRepo.GetUserFork(owner.ID)
if err != nil {
return nil, err
}
if forkedRepo != nil {
return nil, models.ErrForkAlreadyExist{
Uname: owner.Name,
RepoName: oldRepo.FullName(),
RepoName: opts.BaseRepo.FullName(),
ForkName: forkedRepo.FullName(),
}
}
Expand All @@ -33,17 +33,17 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
OwnerID: owner.ID,
Owner: owner,
OwnerName: owner.Name,
Name: name,
LowerName: strings.ToLower(name),
Description: desc,
DefaultBranch: oldRepo.DefaultBranch,
IsPrivate: oldRepo.IsPrivate || oldRepo.Owner.Visibility == structs.VisibleTypePrivate,
IsEmpty: oldRepo.IsEmpty,
Name: opts.Name,
LowerName: strings.ToLower(opts.Name),
Description: opts.Description,
DefaultBranch: opts.BaseRepo.DefaultBranch,
IsPrivate: opts.BaseRepo.IsPrivate || opts.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate,
IsEmpty: opts.BaseRepo.IsEmpty,
IsFork: true,
ForkID: oldRepo.ID,
ForkID: opts.BaseRepo.ID,
}

oldRepoPath := oldRepo.RepoPath()
oldRepoPath := opts.BaseRepo.RepoPath()

err = models.WithTx(func(ctx models.DBContext) error {
if err = models.CreateRepository(ctx, doer, owner, repo, false); err != nil {
Expand All @@ -59,23 +59,23 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
}
}

if err = models.IncrementRepoForkNum(ctx, oldRepo.ID); err != nil {
if err = models.IncrementRepoForkNum(ctx, opts.BaseRepo.ID); err != nil {
rollbackRemoveFn()
return err
}

// copy lfs files failure should not be ignored
if err := models.CopyLFS(ctx, repo, oldRepo); err != nil {
if err := models.CopyLFS(ctx, repo, opts.BaseRepo); err != nil {
rollbackRemoveFn()
return err
}

repoPath := models.RepoPath(owner.Name, repo.Name)
if stdout, err := git.NewCommand(
"clone", "--bare", oldRepoPath, repoPath).
SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", oldRepo.FullName(), repo.FullName())).
SetDescription(fmt.Sprintf("ForkRepository(git clone): %s to %s", opts.BaseRepo.FullName(), repo.FullName())).
RunInDirTimeout(10*time.Minute, ""); err != nil {
log.Error("Fork Repository (git clone) Failed for %v (from %v):\nStdout: %s\nError: %v", repo, oldRepo, stdout, err)
log.Error("Fork Repository (git clone) Failed for %v (from %v):\nStdout: %s\nError: %v", repo, opts.BaseRepo, stdout, err)
rollbackRemoveFn()
return fmt.Errorf("git clone: %v", err)
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
if err = repo.UpdateSize(ctx); err != nil {
log.Error("Failed to update size for repository: %v", err)
}
if err := models.CopyLanguageStat(oldRepo, repo); err != nil {
if err := models.CopyLanguageStat(opts.BaseRepo, repo); err != nil {
log.Error("Copy language stat from oldRepo failed")
}

Expand Down
6 changes: 5 additions & 1 deletion modules/repository/fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ func TestForkRepository(t *testing.T) {
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 13}).(*models.User)
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)

fork, err := ForkRepository(user, user, repo, "test", "test")
fork, err := ForkRepository(user, user, models.ForkRepoOptions{
BaseRepo: repo,
Name: "test",
Description: "test",
})
assert.Nil(t, fork)
assert.Error(t, err)
assert.True(t, models.IsErrForkAlreadyExist(err))
Expand Down
12 changes: 12 additions & 0 deletions options/locale/locale_ja-JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ use_template=このテンプレートを使用
clone_in_vsc=VSCodeでクローン
download_zip=ZIPファイルをダウンロード
download_tar=TAR.GZファイルをダウンロード
download_bundle=バンドルをダウンロード
generate_repo=リポジトリの生成
generate_from=他からの生成
repo_desc=説明
Expand Down Expand Up @@ -899,6 +900,12 @@ migrate.migrate=%s からの移行
migrate.migrating=<b>%s</b> から移行しています ...
migrate.migrating_failed=<b>%s</b> からの移行が失敗しました。
migrate.migrating_failed.error=エラー: %s
migrate.github.description=github.com やその他の Github インスタンスからデータを移行します。
migrate.git.description=Git サービスからリポジトリのみを移行します。
migrate.gitlab.description=gitlab.com やその他の GitLab インスタンスからデータを移行します。
migrate.gitea.description=gitea.com やその他の Gitea インスタンスからデータを移行します。
migrate.gogs.description=notabug.org やその他の Gogs インスタンスからデータを移行します。
migrate.onedev.description=code.onedev.io やその他の OneDev インスタンスからデータを移行します。
migrate.migrating_git=Gitデータ移行中
migrate.migrating_topics=トピック移行中
migrate.migrating_milestones=マイルストーン移行中
Expand Down Expand Up @@ -1325,6 +1332,8 @@ issues.dependency.remove=削除
issues.dependency.remove_info=この依存関係を削除
issues.dependency.added_dependency=`が新しい依存関係を追加 %s`
issues.dependency.removed_dependency=`が依存関係を削除 %s`
issues.dependency.pr_closing_blockedby=このプルリクエストのクローズは、これらのイシューによりブロックされています
issues.dependency.issue_closing_blockedby=このイシューのクローズは、これらのイシューによりブロックされています
issues.dependency.issue_close_blocks=このイシューは、これらのイシューのクローズをブロックしています
issues.dependency.pr_close_blocks=このプルリクエストは、これらのイシューのクローズをブロックしています
issues.dependency.issue_close_blocked=このイシューをクローズするには、ブロックしているイシューをすべてクローズする必要があります。
Expand Down Expand Up @@ -2167,12 +2176,15 @@ members.member_role=メンバーの役割:
members.owner=オーナー
members.member=メンバー
members.remove=削除
members.remove.detail=%[2]s から %[1]s を削除しますか?
members.leave=脱退
members.leave.detail=%s から脱退しますか?
members.invite_desc=%s に新しいメンバーを追加
members.invite_now=今すぐ招待

teams.join=参加
teams.leave=脱退
teams.leave.detail=%s から脱退しますか?
teams.can_create_org_repo=リポジトリを作成
teams.can_create_org_repo_helper=メンバーは組織のリポジトリを新たに作成できます。作成者には新しいリポジトリの管理者権限が与えられます。
teams.read_access=読み取りアクセス権
Expand Down
3 changes: 3 additions & 0 deletions options/locale/locale_pt-BR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1932,12 +1932,15 @@ members.member_role=Categoria de membro:
members.owner=Proprietário
members.member=Membro
members.remove=Remover
members.remove.detail=Remover %[1]s de %[2]s?
members.leave=Sair
members.leave.detail=Sair de %s?
members.invite_desc=Adicionar novo membro em %s:
members.invite_now=Convidar agora

teams.join=Juntar-se
teams.leave=Deixar
teams.leave.detail=Sair de %s?
teams.can_create_org_repo=Criar repositórios
teams.can_create_org_repo_helper=Membros podem criar novos repositórios na organização. O criador terá acesso administrativo ao novo repositório.
teams.read_access=Acesso de leitura
Expand Down
3 changes: 3 additions & 0 deletions options/locale/locale_pt-PT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2176,12 +2176,15 @@ members.member_role=Função do membro:
members.owner=Proprietário(a)
members.member=Membro
members.remove=Remover
members.remove.detail=Remover %[1]s de %[2]s?
members.leave=Sair
members.leave.detail=Sair de %s?
members.invite_desc=Adicionar um novo membro a %s:
members.invite_now=Convidar agora

teams.join=Aderir
teams.leave=Sair
teams.leave.detail=Sair de %s?
teams.can_create_org_repo=Criar repositórios
teams.can_create_org_repo_helper=Os membros podem criar novos repositórios na organização. O criador terá acesso de administrador ao novo repositório.
teams.read_access=Acesso de leitura
Expand Down
10 changes: 10 additions & 0 deletions options/locale/locale_zh-TW.ini
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ use_template=使用此範本
clone_in_vsc=在 VS Code 中 Clone
download_zip=下載 ZIP
download_tar=下載 TAR.GZ
download_bundle=下載 BUNDLE
generate_repo=產生儲存庫
generate_from=產生自
repo_desc=儲存庫描述
Expand Down Expand Up @@ -899,6 +900,12 @@ migrate.migrate=從 %s 遷移
migrate.migrating=正在從 <b>%s</b> 遷移...
migrate.migrating_failed=從 <b>%s</b> 遷移失敗
migrate.migrating_failed.error=錯誤:%s
migrate.github.description=從 github.com 或其他 Github 實例遷移資料。
migrate.git.description=從任何 Git 服務遷移儲存庫。
migrate.gitlab.description=從 gitlab.com 或其他 GitLab 實例遷移資料。
migrate.gitea.description=從 gitea.com 或其他 Gitea 實例遷移資料。
migrate.gogs.description=從 notabug.org 或其他 Gogs 實例遷移資料。
migrate.onedev.description=從 code.onedev.io 或其他 OneDev 實例遷移資料。
migrate.migrating_git=正在遷移 Git 資料
migrate.migrating_topics=正在遷移主題
migrate.migrating_milestones=正在遷移里程碑
Expand Down Expand Up @@ -2169,12 +2176,15 @@ members.member_role=成員角色:
members.owner=擁有者
members.member=普通成員
members.remove=移除
members.remove.detail=確定要從 %[2]s 中刪除 %[1]s 嗎?
members.leave=離開
members.leave.detail=確定要離開 %s 嗎?
members.invite_desc=邀請新的用戶加入 %s:
members.invite_now=立即邀請

teams.join=加入
teams.leave=離開
teams.leave.detail=確定要離開 %s 嗎?
teams.can_create_org_repo=建立儲存庫
teams.can_create_org_repo_helper=成員可以在組織中新增儲存庫。建立者將自動取得新儲存庫的管理員權限。
teams.read_access=讀取權限
Expand Down
6 changes: 5 additions & 1 deletion routers/api/v1/repo/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ func CreateFork(ctx *context.APIContext) {
forker = org
}

fork, err := repo_service.ForkRepository(ctx.User, forker, repo, repo.Name, repo.Description)
fork, err := repo_service.ForkRepository(ctx.User, forker, models.ForkRepoOptions{
BaseRepo: repo,
Name: repo.Name,
Description: repo.Description,
})
if err != nil {
ctx.Error(http.StatusInternalServerError, "ForkRepository", err)
return
Expand Down
Loading

0 comments on commit e1ba0f4

Please sign in to comment.