Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* upstream/main:
  Fix sub folder in repository missing add file dropdown (go-gitea#21069)
  [skip ci] Updated translations via Crowdin
  Add missing volume to test-e2e (go-gitea#21079)
  Fix delete user missed some comments (go-gitea#21067)
  Remove insecure flag from curl (go-gitea#21074)
  Update curl usage in API docs (go-gitea#21071)
  Move go-licenses to generate and separate generate into a frontend and backend component (go-gitea#21061)
  • Loading branch information
zjjhot committed Sep 6, 2022
2 parents ccd705d + f1ea6c9 commit b38d134
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ steps:
TEST_PGSQL_DBNAME: 'testgitea-e2e'
DEBIAN_FRONTEND: noninteractive
depends_on: [build-frontend, deps-backend]
volumes:
- name: deps
path: /go

---
kind: pipeline
Expand Down
27 changes: 21 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/img/webpack pub
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))

GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go

SVG_DEST_DIR := public/img/svg

AIR_TMP_DIR := .air
Expand All @@ -130,9 +132,12 @@ GO_DIRS := cmd tests models modules routers build services tools

GO_SOURCES := $(wildcard *.go)
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" -not -path modules/options/bindata.go -not -path modules/public/bindata.go -not -path modules/templates/bindata.go)
GO_SOURCES += $(GENERATED_GO_DEST)
GO_SOURCES_NO_BINDATA := $(GO_SOURCES)

ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
GO_SOURCES += $(BINDATA_DEST)
GENERATED_GO_DEST += $(BINDATA_DEST)
endif

# Force installation of playwright dependencies by setting this flag
Expand Down Expand Up @@ -259,7 +264,7 @@ clean:
fmt:
@MISSPELL_PACKAGE=$(MISSPELL_PACKAGE) GOFUMPT_PACKAGE=$(GOFUMPT_PACKAGE) $(GO) run build/code-batch-process.go gitea-fmt -w '{file-list}'
$(eval TEMPLATES := $(shell find templates -type f -name '*.tmpl'))
@# strip whitespace after '{{' and before `}}` unless there is only whitespace before it
@# strip whitespace after '{{' and before `}}` unless there is only whitespace before it
@$(SED_INPLACE) -e 's/{{[ ]\{1,\}/{{/g' -e '/^[ ]\{1,\}}}/! s/[ ]\{1,\}}}/}}/g' $(TEMPLATES)

.PHONY: vet
Expand All @@ -278,7 +283,9 @@ TAGS_PREREQ := $(TAGS_EVIDENCE)
endif

.PHONY: generate-swagger
generate-swagger:
generate-swagger: $(SWAGGER_SPEC)

$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA)
$(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
Expand Down Expand Up @@ -398,7 +405,6 @@ unit-test-coverage:
tidy:
$(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
$(GO) mod tidy -compat=$(MIN_GO_VERSION)
@$(MAKE) --no-print-directory assets/go-licenses.json

.PHONY: vendor
vendor: tidy
Expand Down Expand Up @@ -702,16 +708,25 @@ install: $(wildcard *.go)
build: frontend backend

.PHONY: frontend
frontend: $(WEBPACK_DEST)
frontend: generate-frontend $(WEBPACK_DEST)

.PHONY: backend
backend: go-check generate $(EXECUTABLE)
backend: go-check generate-backend $(EXECUTABLE)

# We generate the backend before the frontend in case we in future we want to generate things in the frontend from generated files in backend
.PHONY: generate
generate: $(TAGS_PREREQ)
generate: generate-backend generate-frontend

.PHONY: generate-backend
generate-backend: $(TAGS_PREREQ) generate-go

generate-go: $(TAGS_PREREQ)
@echo "Running go generate..."
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)

.PHONY: generate-frontend
generate-frontend: $(TAGS_PREREQ) go-licenses

$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@

Expand Down
8 changes: 4 additions & 4 deletions docs/content/doc/developers/api-usage.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Note that `/users/:name/tokens` is a special endpoint and requires you
to authenticate using `BasicAuth` and a password, as follows:

```sh
$ curl -XPOST -H "Content-Type: application/json" -k -d '{"name":"test"}' -u username:password https://gitea.your.host/api/v1/users/<username>/tokens
$ curl -H "Content-Type: application/json" -d '{"name":"test"}' -u username:password https://gitea.your.host/api/v1/users/<username>/tokens
{"id":1,"name":"test","sha1":"9fcb1158165773dd010fca5f0cf7174316c3e37d","token_last_eight":"16c3e37d"}
```

Expand All @@ -58,7 +58,7 @@ plain-text. It will not be displayed when listing tokens with a `GET`
request; e.g.

```sh
$ curl --request GET --url https://yourusername:password@gitea.your.host/api/v1/users/<username>/tokens
$ curl --url https://yourusername:password@gitea.your.host/api/v1/users/<username>/tokens
[{"name":"test","sha1":"","token_last_eight:"........":},{"name":"dev","sha1":"","token_last_eight":"........"}]
```
Expand All @@ -70,7 +70,7 @@ is where you'd place the code from your authenticator.
Here is how the request would look like in curl:
```sh
$ curl -H "X-Gitea-OTP: 123456" --request GET --url https://yourusername:yourpassword@gitea.your.host/api/v1/users/yourusername/tokens
$ curl -H "X-Gitea-OTP: 123456" --url https://yourusername:yourpassword@gitea.your.host/api/v1/users/yourusername/tokens
```
You can also create an API key token via your Gitea installation's web
Expand All @@ -96,7 +96,7 @@ Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675
In a `curl` command, for instance, this would look like:
```sh
curl -X POST "http://localhost:4000/api/v1/repos/test1/test1/issues" \
curl "http://localhost:4000/api/v1/repos/test1/test1/issues" \
-H "accept: application/json" \
-H "Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675" \
-H "Content-Type: application/json" -d "{ \"body\": \"testing\", \"title\": \"test 20\"}" -i
Expand Down
4 changes: 2 additions & 2 deletions docs/content/doc/developers/api-usage.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675
`curl` 命令为例,它会以如下形式携带在请求中:

```
curl -X POST "http://localhost:4000/api/v1/repos/test1/test1/issues" \
curl "http://localhost:4000/api/v1/repos/test1/test1/issues" \
-H "accept: application/json" \
-H "Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675" \
-H "Content-Type: application/json" -d "{ \"body\": \"testing\", \"title\": \"test 20\"}" -i
Expand All @@ -62,7 +62,7 @@ curl -X POST "http://localhost:4000/api/v1/repos/test1/test1/issues" \
### 使用 Basic authentication 认证:

```
$ curl --request GET --url https://yourusername:yourpassword@gitea.your.host/api/v1/users/yourusername/tokens
$ curl --url https://yourusername:yourpassword@gitea.your.host/api/v1/users/yourusername/tokens
[{"name":"test","sha1":"..."},{"name":"dev","sha1":"..."}]
```

Expand Down
6 changes: 3 additions & 3 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)

// Delete Comments
const batchSize = 50
for start := 0; ; start += batchSize {
for {
comments := make([]*issues_model.Comment, 0, batchSize)
if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, start).Find(&comments); err != nil {
if err = e.Where("type=? AND poster_id=?", issues_model.CommentTypeComment, u.ID).Limit(batchSize, 0).Find(&comments); err != nil {
return err
}
if len(comments) == 0 {
Expand Down Expand Up @@ -202,7 +202,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) (err error)
// ***** END: ExternalLoginUser *****

if _, err = e.ID(u.ID).Delete(new(user_model.User)); err != nil {
return fmt.Errorf("Delete: %v", err)
return fmt.Errorf("delete: %v", err)
}

return nil
Expand Down
11 changes: 11 additions & 0 deletions modules/charset/ambiguous/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error
verbosef("Bad source:\n%s", buf.String())
return fmt.Errorf("unable to format source: %w", err)
}

old, err := os.ReadFile(filename)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to read old file %s because %w", filename, err)
} else if err == nil {
if bytes.Equal(bs, old) {
// files are the same don't rewrite it.
return nil
}
}

file, err := os.Create(filename)
if err != nil {
return fmt.Errorf("failed to create file %s because %w", filename, err)
Expand Down
11 changes: 11 additions & 0 deletions modules/charset/invisible/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error
verbosef("Bad source:\n%s", buf.String())
return fmt.Errorf("unable to format source: %w", err)
}

old, err := os.ReadFile(filename)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to read old file %s because %w", filename, err)
} else if err == nil {
if bytes.Equal(bs, old) {
// files are the same don't rewrite it.
return nil
}
}

file, err := os.Create(filename)
if err != nil {
return fmt.Errorf("failed to create file %s because %w", filename, err)
Expand Down
2 changes: 2 additions & 0 deletions options/locale/locale_pt-PT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,8 @@ settings.event_delete=Eliminar
settings.event_delete_desc=Ramo ou etiqueta eliminados.
settings.event_fork=Derivar
settings.event_fork_desc=Feita a derivação do repositório.
settings.event_wiki=Wiki
settings.event_wiki_desc=Página do wiki criada, renomeada, editada ou eliminada.
settings.event_release=Lançamento
settings.event_release_desc=Lançamento publicado, modificado ou eliminado num repositório.
settings.event_push=Enviar
Expand Down
1 change: 0 additions & 1 deletion services/migrations/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"code.gitea.io/gitea/modules/structs"

"github.com/google/uuid"

"gopkg.in/yaml.v2"
)

Expand Down
51 changes: 26 additions & 25 deletions templates/repo/home.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,33 @@
</a>
{{end}}
<a href="{{.Repository.Link}}/find/{{.BranchNameSubURL}}" class="ui compact basic button tooltip" data-content="{{.locale.Tr "repo.find_file.go_to_file"}}">{{svg "octicon-file-moved" 15}}</a>
{{if or .CanAddFile .CanUploadFile}}
<button class="ui basic small compact dropdown jump icon button mr-2">
<span class="text">{{.locale.Tr "repo.editor.add_file"}}</span>
<div class="menu">
{{if .Repository.CanEnableEditor}}
{{if .CanAddFile}}
<a class="item" href="{{.RepoLink}}/_new/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
{{.locale.Tr "repo.editor.new_file"}}
</a>
{{end}}
{{if .CanUploadFile}}
<a class="item" href="{{.RepoLink}}/_upload/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
{{.locale.Tr "repo.editor.upload_file"}}
</a>
{{end}}
{{if .CanAddFile}}
<a class="item" href="{{.RepoLink}}/_diffpatch/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
{{.locale.Tr "repo.editor.patch"}}
</a>
{{end}}
{{end}}
{{if or .CanAddFile .CanUploadFile}}
<button class="ui basic small compact dropdown jump icon button mr-2">
<span class="text">{{.locale.Tr "repo.editor.add_file"}}</span>
<div class="menu">
{{if .Repository.CanEnableEditor}}
{{if .CanAddFile}}
<a class="item" href="{{.RepoLink}}/_new/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
{{.locale.Tr "repo.editor.new_file"}}
</a>
{{end}}
</div>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
</button>
{{end}}
{{else}}
{{if .CanUploadFile}}
<a class="item" href="{{.RepoLink}}/_upload/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
{{.locale.Tr "repo.editor.upload_file"}}
</a>
{{end}}
{{if .CanAddFile}}
<a class="item" href="{{.RepoLink}}/_diffpatch/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
{{.locale.Tr "repo.editor.patch"}}
</a>
{{end}}
{{end}}
</div>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
</button>
{{end}}
{{if ne $n 0}}
<span class="ui breadcrumb repo-path"><a class="section" href="{{.RepoLink}}/src/{{.BranchNameSubURL}}" title="{{.Repository.Name}}">{{EllipsisString .Repository.Name 30}}</a>{{range $i, $v := .TreeNames}}<span class="divider">/</span>{{if eq $i $l}}<span class="active section" title="{{$v}}">{{EllipsisString $v 30}}</span>{{else}}{{$p := index $.Paths $i}}<span class="section"><a href="{{$.BranchLink}}/{{PathEscapeSegments $p}}" title="{{$v}}">{{EllipsisString $v 30}}</a></span>{{end}}{{end}}</span>
{{end}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/sub_menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</div>
<a class="ui segment language-stats">
{{range .LanguageStats}}
<div class="bar tooltip" style="width: {{.Percentage}}%; background-color: {{.Color}}" data-placement="top" data-content={{ .Language }}>&nbsp;</div>
<div class="bar tooltip" style="width: {{.Percentage}}%; background-color: {{.Color}}" data-placement="top" data-content={{.Language}}>&nbsp;</div>
{{end}}
</a>
{{end}}
Expand Down
1 change: 1 addition & 0 deletions tests/integration/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"code.gitea.io/gitea/tests"

"github.com/stretchr/testify/assert"
)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"code.gitea.io/gitea/tests"

"github.com/stretchr/testify/assert"
)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/nonascii_branches_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"code.gitea.io/gitea/tests"

"github.com/stretchr/testify/assert"
)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/pull_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"code.gitea.io/gitea/tests"

"github.com/stretchr/testify/assert"
)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/pull_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"testing"

"code.gitea.io/gitea/tests"

"github.com/stretchr/testify/assert"
)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/repo_commits_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"code.gitea.io/gitea/tests"

"github.com/stretchr/testify/assert"
)

Expand Down
1 change: 1 addition & 0 deletions tests/integration/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"code.gitea.io/gitea/tests"

"github.com/stretchr/testify/assert"
)

Expand Down

0 comments on commit b38d134

Please sign in to comment.