Skip to content

Commit 7a2387a

Browse files
authored
Merge branch 'main' into katex-rendering
2 parents de68952 + 0ad0190 commit 7a2387a

Some content is hidden

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

53 files changed

+686
-23
lines changed

Makefile

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/img/webpack pub
111111
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
112112
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
113113

114+
GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go
115+
114116
SVG_DEST_DIR := public/img/svg
115117

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

131133
GO_SOURCES := $(wildcard *.go)
132134
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)
135+
GO_SOURCES += $(GENERATED_GO_DEST)
136+
GO_SOURCES_NO_BINDATA := $(GO_SOURCES)
133137

134138
ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
135139
GO_SOURCES += $(BINDATA_DEST)
140+
GENERATED_GO_DEST += $(BINDATA_DEST)
136141
endif
137142

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

265270
.PHONY: vet
@@ -278,7 +283,9 @@ TAGS_PREREQ := $(TAGS_EVIDENCE)
278283
endif
279284

280285
.PHONY: generate-swagger
281-
generate-swagger:
286+
generate-swagger: $(SWAGGER_SPEC)
287+
288+
$(SWAGGER_SPEC): $(GO_SOURCES_NO_BINDATA)
282289
$(GO) run $(SWAGGER_PACKAGE) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
283290
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
284291
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
@@ -398,7 +405,6 @@ unit-test-coverage:
398405
tidy:
399406
$(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
400407
$(GO) mod tidy -compat=$(MIN_GO_VERSION)
401-
@$(MAKE) --no-print-directory assets/go-licenses.json
402408

403409
.PHONY: vendor
404410
vendor: tidy
@@ -702,16 +708,25 @@ install: $(wildcard *.go)
702708
build: frontend backend
703709

704710
.PHONY: frontend
705-
frontend: $(WEBPACK_DEST)
711+
frontend: generate-frontend $(WEBPACK_DEST)
706712

707713
.PHONY: backend
708-
backend: go-check generate $(EXECUTABLE)
714+
backend: go-check generate-backend $(EXECUTABLE)
709715

716+
# 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
710717
.PHONY: generate
711-
generate: $(TAGS_PREREQ)
718+
generate: generate-backend generate-frontend
719+
720+
.PHONY: generate-backend
721+
generate-backend: $(TAGS_PREREQ) generate-go
722+
723+
generate-go: $(TAGS_PREREQ)
712724
@echo "Running go generate..."
713725
@CC= GOOS= GOARCH= $(GO) generate -tags '$(TAGS)' $(GO_PACKAGES)
714726

727+
.PHONY: generate-frontend
728+
generate-frontend: $(TAGS_PREREQ) go-licenses
729+
715730
$(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
716731
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
717732

docs/content/doc/developers/api-usage.en-us.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Note that `/users/:name/tokens` is a special endpoint and requires you
4949
to authenticate using `BasicAuth` and a password, as follows:
5050

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

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

6060
```sh
61-
$ curl --request GET --url https://yourusername:password@gitea.your.host/api/v1/users/<username>/tokens
61+
$ curl --url https://yourusername:password@gitea.your.host/api/v1/users/<username>/tokens
6262
[{"name":"test","sha1":"","token_last_eight:"........":},{"name":"dev","sha1":"","token_last_eight":"........"}]
6363
```
6464
@@ -70,7 +70,7 @@ is where you'd place the code from your authenticator.
7070
Here is how the request would look like in curl:
7171
7272
```sh
73-
$ curl -H "X-Gitea-OTP: 123456" --request GET --url https://yourusername:yourpassword@gitea.your.host/api/v1/users/yourusername/tokens
73+
$ curl -H "X-Gitea-OTP: 123456" --url https://yourusername:yourpassword@gitea.your.host/api/v1/users/yourusername/tokens
7474
```
7575
7676
You can also create an API key token via your Gitea installation's web
@@ -96,7 +96,7 @@ Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675
9696
In a `curl` command, for instance, this would look like:
9797
9898
```sh
99-
curl -X POST "http://localhost:4000/api/v1/repos/test1/test1/issues" \
99+
curl "http://localhost:4000/api/v1/repos/test1/test1/issues" \
100100
-H "accept: application/json" \
101101
-H "Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675" \
102102
-H "Content-Type: application/json" -d "{ \"body\": \"testing\", \"title\": \"test 20\"}" -i

docs/content/doc/developers/api-usage.zh-cn.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675
4646
`curl` 命令为例,它会以如下形式携带在请求中:
4747

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

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

models/webhook/hooktask.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const (
4747
HookEventPullRequestReviewRejected HookEventType = "pull_request_review_rejected"
4848
HookEventPullRequestReviewComment HookEventType = "pull_request_review_comment"
4949
HookEventPullRequestSync HookEventType = "pull_request_sync"
50+
HookEventWiki HookEventType = "wiki"
5051
HookEventRepository HookEventType = "repository"
5152
HookEventRelease HookEventType = "release"
5253
HookEventPackage HookEventType = "package"
@@ -76,6 +77,8 @@ func (h HookEventType) Event() string {
7677
return "pull_request_rejected"
7778
case HookEventPullRequestReviewComment:
7879
return "pull_request_comment"
80+
case HookEventWiki:
81+
return "wiki"
7982
case HookEventRepository:
8083
return "repository"
8184
case HookEventRelease:

models/webhook/webhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ type HookEvents struct {
132132
PullRequestComment bool `json:"pull_request_comment"`
133133
PullRequestReview bool `json:"pull_request_review"`
134134
PullRequestSync bool `json:"pull_request_sync"`
135+
Wiki bool `json:"wiki"`
135136
Repository bool `json:"repository"`
136137
Release bool `json:"release"`
137138
Package bool `json:"package"`
@@ -328,6 +329,12 @@ func (w *Webhook) HasPullRequestSyncEvent() bool {
328329
(w.ChooseEvents && w.HookEvents.PullRequestSync)
329330
}
330331

332+
// HasWikiEvent returns true if hook enabled wiki event.
333+
func (w *Webhook) HasWikiEvent() bool {
334+
return w.SendEverything ||
335+
(w.ChooseEvents && w.HookEvent.Wiki)
336+
}
337+
331338
// HasReleaseEvent returns if hook enabled release event.
332339
func (w *Webhook) HasReleaseEvent() bool {
333340
return w.SendEverything ||
@@ -373,6 +380,7 @@ func (w *Webhook) EventCheckers() []struct {
373380
{w.HasPullRequestRejectedEvent, HookEventPullRequestReviewRejected},
374381
{w.HasPullRequestCommentEvent, HookEventPullRequestReviewComment},
375382
{w.HasPullRequestSyncEvent, HookEventPullRequestSync},
383+
{w.HasWikiEvent, HookEventWiki},
376384
{w.HasRepositoryEvent, HookEventRepository},
377385
{w.HasReleaseEvent, HookEventRelease},
378386
{w.HasPackageEvent, HookEventPackage},

models/webhook/webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestWebhook_EventsArray(t *testing.T) {
7171
"issues", "issue_assign", "issue_label", "issue_milestone", "issue_comment",
7272
"pull_request", "pull_request_assign", "pull_request_label", "pull_request_milestone",
7373
"pull_request_comment", "pull_request_review_approved", "pull_request_review_rejected",
74-
"pull_request_review_comment", "pull_request_sync", "repository", "release",
74+
"pull_request_review_comment", "pull_request_sync", "wiki", "repository", "release",
7575
"package",
7676
},
7777
(&Webhook{

modules/charset/ambiguous/generate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error
110110
verbosef("Bad source:\n%s", buf.String())
111111
return fmt.Errorf("unable to format source: %w", err)
112112
}
113+
114+
old, err := os.ReadFile(filename)
115+
if err != nil && !os.IsNotExist(err) {
116+
return fmt.Errorf("failed to read old file %s because %w", filename, err)
117+
} else if err == nil {
118+
if bytes.Equal(bs, old) {
119+
// files are the same don't rewrite it.
120+
return nil
121+
}
122+
}
123+
113124
file, err := os.Create(filename)
114125
if err != nil {
115126
return fmt.Errorf("failed to create file %s because %w", filename, err)

modules/charset/invisible/generate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ func runTemplate(t *template.Template, filename string, data interface{}) error
6363
verbosef("Bad source:\n%s", buf.String())
6464
return fmt.Errorf("unable to format source: %w", err)
6565
}
66+
67+
old, err := os.ReadFile(filename)
68+
if err != nil && !os.IsNotExist(err) {
69+
return fmt.Errorf("failed to read old file %s because %w", filename, err)
70+
} else if err == nil {
71+
if bytes.Equal(bs, old) {
72+
// files are the same don't rewrite it.
73+
return nil
74+
}
75+
}
76+
6677
file, err := os.Create(filename)
6778
if err != nil {
6879
return fmt.Errorf("failed to create file %s because %w", filename, err)

modules/notification/base/notifier.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ type Notifier interface {
4545
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User)
4646
NotifyUpdateComment(*user_model.User, *issues_model.Comment, string)
4747
NotifyDeleteComment(*user_model.User, *issues_model.Comment)
48+
NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string)
49+
NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string)
50+
NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string)
4851
NotifyNewRelease(rel *repo_model.Release)
4952
NotifyUpdateRelease(doer *user_model.User, rel *repo_model.Release)
5053
NotifyDeleteRelease(doer *user_model.User, rel *repo_model.Release)

modules/notification/base/null.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ func (*NullNotifier) NotifyUpdateComment(doer *user_model.User, c *issues_model.
7878
func (*NullNotifier) NotifyDeleteComment(doer *user_model.User, c *issues_model.Comment) {
7979
}
8080

81+
// NotifyNewWikiPage places a place holder function
82+
func (*NullNotifier) NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
83+
}
84+
85+
// NotifyEditWikiPage places a place holder function
86+
func (*NullNotifier) NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
87+
}
88+
89+
// NotifyDeleteWikiPage places a place holder function
90+
func (*NullNotifier) NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) {
91+
}
92+
8193
// NotifyNewRelease places a place holder function
8294
func (*NullNotifier) NotifyNewRelease(rel *repo_model.Release) {
8395
}

modules/notification/notification.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ func NewContext() {
4040
RegisterNotifier(mirror.NewNotifier())
4141
}
4242

43+
// NotifyNewWikiPage notifies creating new wiki pages to notifiers
44+
func NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
45+
for _, notifier := range notifiers {
46+
notifier.NotifyNewWikiPage(doer, repo, page, comment)
47+
}
48+
}
49+
50+
// NotifyEditWikiPage notifies editing or renaming wiki pages to notifiers
51+
func NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
52+
for _, notifier := range notifiers {
53+
notifier.NotifyEditWikiPage(doer, repo, page, comment)
54+
}
55+
}
56+
57+
// NotifyDeleteWikiPage notifies deleting wiki pages to notifiers
58+
func NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) {
59+
for _, notifier := range notifiers {
60+
notifier.NotifyDeleteWikiPage(doer, repo, page)
61+
}
62+
}
63+
4364
// NotifyCreateIssueComment notifies issue comment related message to notifiers
4465
func NotifyCreateIssueComment(doer *user_model.User, repo *repo_model.Repository,
4566
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,

modules/notification/webhook/webhook.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,44 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *user_model.User, comment *is
501501
}
502502
}
503503

504+
func (m *webhookNotifier) NotifyNewWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
505+
// Add to hook queue for created wiki page.
506+
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventWiki, &api.WikiPayload{
507+
Action: api.HookWikiCreated,
508+
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
509+
Sender: convert.ToUser(doer, nil),
510+
Page: page,
511+
Comment: comment,
512+
}); err != nil {
513+
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
514+
}
515+
}
516+
517+
func (m *webhookNotifier) NotifyEditWikiPage(doer *user_model.User, repo *repo_model.Repository, page, comment string) {
518+
// Add to hook queue for edit wiki page.
519+
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventWiki, &api.WikiPayload{
520+
Action: api.HookWikiEdited,
521+
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
522+
Sender: convert.ToUser(doer, nil),
523+
Page: page,
524+
Comment: comment,
525+
}); err != nil {
526+
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
527+
}
528+
}
529+
530+
func (m *webhookNotifier) NotifyDeleteWikiPage(doer *user_model.User, repo *repo_model.Repository, page string) {
531+
// Add to hook queue for edit wiki page.
532+
if err := webhook_services.PrepareWebhooks(repo, webhook.HookEventWiki, &api.WikiPayload{
533+
Action: api.HookWikiDeleted,
534+
Repository: convert.ToRepo(repo, perm.AccessModeOwner),
535+
Sender: convert.ToUser(doer, nil),
536+
Page: page,
537+
}); err != nil {
538+
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
539+
}
540+
}
541+
504542
func (m *webhookNotifier) NotifyIssueChangeLabels(doer *user_model.User, issue *issues_model.Issue,
505543
addedLabels, removedLabels []*issues_model.Label,
506544
) {

modules/structs/hook.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,39 @@ type ReviewPayload struct {
397397
Content string `json:"content"`
398398
}
399399

400+
// __ __.__ __ .__
401+
// / \ / \__| | _|__|
402+
// \ \/\/ / | |/ / |
403+
// \ /| | <| |
404+
// \__/\ / |__|__|_ \__|
405+
// \/ \/
406+
407+
// HookWikiAction an action that happens to a wiki page
408+
type HookWikiAction string
409+
410+
const (
411+
// HookWikiCreated created
412+
HookWikiCreated HookWikiAction = "created"
413+
// HookWikiEdited edited
414+
HookWikiEdited HookWikiAction = "edited"
415+
// HookWikiDeleted deleted
416+
HookWikiDeleted HookWikiAction = "deleted"
417+
)
418+
419+
// WikiPayload payload for repository webhooks
420+
type WikiPayload struct {
421+
Action HookWikiAction `json:"action"`
422+
Repository *Repository `json:"repository"`
423+
Sender *User `json:"sender"`
424+
Page string `json:"page"`
425+
Comment string `json:"comment"`
426+
}
427+
428+
// JSONPayload JSON representation of the payload
429+
func (p *WikiPayload) JSONPayload() ([]byte, error) {
430+
return json.MarshalIndent(p, "", " ")
431+
}
432+
400433
//__________ .__ __
401434
//\______ \ ____ ______ ____ _____|__|/ |_ ___________ ___.__.
402435
// | _// __ \\____ \ / _ \/ ___/ \ __\/ _ \_ __ < | |

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,8 @@ settings.event_delete = Delete
19561956
settings.event_delete_desc = Branch or tag deleted.
19571957
settings.event_fork = Fork
19581958
settings.event_fork_desc = Repository forked.
1959+
settings.event_wiki = Wiki
1960+
settings.event_wiki_desc = Wiki page created, renamed, edited or deleted.
19591961
settings.event_release = Release
19601962
settings.event_release_desc = Release published, updated or deleted in a repository.
19611963
settings.event_push = Push

0 commit comments

Comments
 (0)