Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* upstream/main:
  Test query must have "order by" explicitly to avoid unstable results (go-gitea#24963)
  Help to recover from corrupted levelqueue (go-gitea#24912)
  [skip ci] Updated translations via Crowdin
  Remove meta tags `theme-color` and `default-theme` (go-gitea#24960)
  Add dark mode to API Docs (go-gitea#24971)
  Update JS dependencies (go-gitea#24969)
  Replace Fomantic reset module with our own (go-gitea#24948)
  simple docs fixes: 'pull request' page (en-us & zh-tw) link path to 'issue-pull-request-templates' (go-gitea#24961)
  Remove reference to caddy v1 in docs (go-gitea#24962)
  Improve and fix bugs surrounding reactions (go-gitea#24760)
  Use `[git.config]` for reflog cleaning up (go-gitea#24958)
  Improve logger Pause handling (go-gitea#24946)
  Do not output "Trace" level logs from process manager by default (go-gitea#24952)
  Make the 500 page load themes (go-gitea#24953)
  [skip ci] Updated translations via Crowdin
  docs: remove an extraneous whitespace (go-gitea#24949)
  Show `bot` label next to username when rendering autor link if the user is a bot (go-gitea#24943)
  Improve some Forms (go-gitea#24878)
  Improve queue and logger context (go-gitea#24924)
  Fix ref type error (go-gitea#24941)
  • Loading branch information
zjjhot committed May 29, 2023
2 parents f90f495 + ad13df3 commit 4825cb5
Show file tree
Hide file tree
Showing 98 changed files with 1,749 additions and 1,383 deletions.
12 changes: 2 additions & 10 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -693,17 +693,13 @@ LEVEL = Info
;PULL = 300
;GC = 60

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Git Reflog timeout in days
;[git.reflog]
;ENABLED = true
;EXPIRATION = 90

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Git config options
;; This section only does "set" config, a removed config key from this section won't be removed from git config automatically. The format is `some.configKey = value`.
;[git.config]
;diff.algorithm = histogram
;core.logAllRefUpdates = true
;gc.reflogExpire = 90

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -1184,10 +1180,6 @@ LEVEL = Info
;; Number of line of codes shown for a code comment
;CODE_COMMENT_LINES = 4
;;
;; Value of `theme-color` meta tag, used by some mobile browers for chrome and
;; out-of-viewport areas. Default is unset which uses body color.
;THEME_COLOR_META_TAG =
;;
;; Max size of files to be displayed (default is 8MiB)
;MAX_DISPLAY_FILE_SIZE = 8388608
;;
Expand Down
8 changes: 2 additions & 6 deletions docs/content/doc/administration/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ The following configuration set `Content-Type: application/vnd.android.package-a
- `SHOW_USER_EMAIL`: **true**: Whether the email of the user should be shown in the Explore Users page.
- `THEMES`: **auto,gitea,arc-green**: All available themes. Allow users select personalized themes.
regardless of the value of `DEFAULT_THEME`.
- `THEME_COLOR_META_TAG`: **\<empty\>**: Value of `theme-color` meta tag, used by some mobile browsers for chrome and out-of-viewport areas. Default is unset which uses body color.
- `MAX_DISPLAY_FILE_SIZE`: **8388608**: Max size of files to be displayed (default is 8MiB)
- `REACTIONS`: All available reactions users can choose on issues/prs and comments
Values can be emoji alias (:smile:) or a unicode emoji.
Expand Down Expand Up @@ -1065,17 +1064,14 @@ Default templates for project boards:
- `PULL`: **300**: Git pull from internal repositories timeout seconds.
- `GC`: **60**: Git repository GC timeout seconds.

### Git - Reflog settings (`git.reflog`)

- `ENABLED`: **true** Set to true to enable Git to write changes to reflogs in each repo.
- `EXPIRATION`: **90** Reflog entry lifetime, in days. Entries are removed opportunistically by Git.

### Git - Config options (`git.config`)

The key/value pairs in this section will be used as git config.
This section only does "set" config, a removed config key from this section won't be removed from git config automatically. The format is `some.configKey = value`.

- `diff.algorithm`: **histogram**
- `core.logAllRefUpdates`: **true**
- `gc.reflogExpire`: **90**

## Metrics (`metrics`)

Expand Down
16 changes: 0 additions & 16 deletions docs/content/doc/administration/reverse-proxies.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,6 @@ git.example.com {
}
```

If you still use Caddy v1, use:

```apacheconf
git.example.com {
proxy / localhost:3000
}
```

## Caddy with a sub-path

In case you already have a site, and you want Gitea to share the domain name, you can setup Caddy to serve Gitea under a sub-path by adding the following to your server block in your Caddyfile:
Expand All @@ -212,14 +204,6 @@ git.example.com {
}
```

Or, for Caddy v1:

```apacheconf
git.example.com {
proxy /git/ localhost:3000
}
```

Then set `[server] ROOT_URL = http://git.example.com/git/` in your configuration.

## IIS
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/development/oauth2-provider.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ For public clients, a redirect URI of a loopback IP address such as `http://127.
1. Redirect to user to the authorization endpoint in order to get their consent for accessing the resources:

```curl
https://[YOUR-GITEA-URL]/login/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI& response_type=code&state=STATE
https://[YOUR-GITEA-URL]/login/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&response_type=code&state=STATE
```

The `CLIENT_ID` can be obtained by registering an application in the settings. The `STATE` is a random string that will be send back to your application after the user authorizes. The `state` parameter is optional but should be used to prevent CSRF attacks.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/doc/usage/pull-request.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ The first value of the list will be used in helpers.

## Pull Request Templates

You can find more information about pull request templates at the page [Issue and Pull Request templates](../issue-pull-request-templates).
You can find more information about pull request templates at the page [Issue and Pull Request templates](issue-pull-request-templates).
2 changes: 1 addition & 1 deletion docs/content/doc/usage/pull-request.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ WORK_IN_PROGRESS_PREFIXES=WIP:,[WIP]

## 合併請求範本

您可以在[問題與合併請求範本](../issue-pull-request-templates)找到更多關於合併請求範本的資訊。
您可以在[問題與合併請求範本](issue-pull-request-templates)找到更多關於合併請求範本的資訊。
44 changes: 27 additions & 17 deletions models/unittest/unit_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,52 @@ import (
const NonexistentID = int64(math.MaxInt64)

type testCond struct {
query interface{}
args []interface{}
query any
args []any
}

type testOrderBy string

// Cond create a condition with arguments for a test
func Cond(query interface{}, args ...interface{}) interface{} {
func Cond(query any, args ...any) any {
return &testCond{query: query, args: args}
}

func whereConditions(e db.Engine, conditions []interface{}) db.Engine {
// OrderBy creates "ORDER BY" a test query
func OrderBy(orderBy string) any {
return testOrderBy(orderBy)
}

func whereOrderConditions(e db.Engine, conditions []any) db.Engine {
orderBy := "id" // query must have the "ORDER BY", otherwise the result is not deterministic
for _, condition := range conditions {
switch cond := condition.(type) {
case *testCond:
e = e.Where(cond.query, cond.args...)
case testOrderBy:
orderBy = string(cond)
default:
e = e.Where(cond)
}
}
return e
return e.OrderBy(orderBy)
}

// LoadBeanIfExists loads beans from fixture database if exist
func LoadBeanIfExists(bean interface{}, conditions ...interface{}) (bool, error) {
func LoadBeanIfExists(bean any, conditions ...any) (bool, error) {
e := db.GetEngine(db.DefaultContext)
return whereConditions(e, conditions).Get(bean)
return whereOrderConditions(e, conditions).Get(bean)
}

// BeanExists for testing, check if a bean exists
func BeanExists(t assert.TestingT, bean interface{}, conditions ...interface{}) bool {
func BeanExists(t assert.TestingT, bean any, conditions ...any) bool {
exists, err := LoadBeanIfExists(bean, conditions...)
assert.NoError(t, err)
return exists
}

// AssertExistsAndLoadBean assert that a bean exists and load it from the test database
func AssertExistsAndLoadBean[T any](t assert.TestingT, bean T, conditions ...interface{}) T {
func AssertExistsAndLoadBean[T any](t assert.TestingT, bean T, conditions ...any) T {
exists, err := LoadBeanIfExists(bean, conditions...)
assert.NoError(t, err)
assert.True(t, exists,
Expand All @@ -64,9 +74,9 @@ func AssertExistsAndLoadBean[T any](t assert.TestingT, bean T, conditions ...int
}

// AssertExistsAndLoadMap assert that a row exists and load it from the test database
func AssertExistsAndLoadMap(t assert.TestingT, table string, conditions ...interface{}) map[string]string {
func AssertExistsAndLoadMap(t assert.TestingT, table string, conditions ...any) map[string]string {
e := db.GetEngine(db.DefaultContext).Table(table)
res, err := whereConditions(e, conditions).Query()
res, err := whereOrderConditions(e, conditions).Query()
assert.NoError(t, err)
assert.True(t, len(res) == 1,
"Expected to find one row in %s (with conditions %+v), but found %d",
Expand All @@ -84,36 +94,36 @@ func AssertExistsAndLoadMap(t assert.TestingT, table string, conditions ...inter
}

// GetCount get the count of a bean
func GetCount(t assert.TestingT, bean interface{}, conditions ...interface{}) int {
func GetCount(t assert.TestingT, bean any, conditions ...any) int {
e := db.GetEngine(db.DefaultContext)
count, err := whereConditions(e, conditions).Count(bean)
count, err := whereOrderConditions(e, conditions).Count(bean)
assert.NoError(t, err)
return int(count)
}

// AssertNotExistsBean assert that a bean does not exist in the test database
func AssertNotExistsBean(t assert.TestingT, bean interface{}, conditions ...interface{}) {
func AssertNotExistsBean(t assert.TestingT, bean any, conditions ...any) {
exists, err := LoadBeanIfExists(bean, conditions...)
assert.NoError(t, err)
assert.False(t, exists)
}

// AssertExistsIf asserts that a bean exists or does not exist, depending on
// what is expected.
func AssertExistsIf(t assert.TestingT, expected bool, bean interface{}, conditions ...interface{}) {
func AssertExistsIf(t assert.TestingT, expected bool, bean any, conditions ...any) {
exists, err := LoadBeanIfExists(bean, conditions...)
assert.NoError(t, err)
assert.Equal(t, expected, exists)
}

// AssertSuccessfulInsert assert that beans is successfully inserted
func AssertSuccessfulInsert(t assert.TestingT, beans ...interface{}) {
func AssertSuccessfulInsert(t assert.TestingT, beans ...any) {
err := db.Insert(db.DefaultContext, beans...)
assert.NoError(t, err)
}

// AssertCount assert the count of a bean
func AssertCount(t assert.TestingT, bean, expected interface{}) {
func AssertCount(t assert.TestingT, bean, expected any) {
assert.EqualValues(t, expected, GetCount(t, bean))
}

Expand Down
5 changes: 5 additions & 0 deletions models/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,11 @@ func (u *User) IsIndividual() bool {
return u.Type == UserTypeIndividual
}

// IsBot returns whether or not the user is of type bot
func (u *User) IsBot() bool {
return u.Type == UserTypeBot
}

// DisplayName returns full name if it's not empty,
// returns username otherwise.
func (u *User) DisplayName() string {
Expand Down
27 changes: 0 additions & 27 deletions modules/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,6 @@ func InitFull(ctx context.Context) (err error) {
return syncGitConfig()
}

func enableReflogs() error {
if err := configSet("core.logAllRefUpdates", "true"); err != nil {
return err
}
err := configSet("gc.reflogExpire", fmt.Sprintf("%d", setting.Git.Reflog.Expiration))
return err
}

func disableReflogs() error {
if err := configUnsetAll("core.logAllRefUpdates", "true"); err != nil {
return err
} else if err := configUnsetAll("gc.reflogExpire", ""); err != nil {
return err
}
return nil
}

// syncGitConfig only modifies gitconfig, won't change global variables (otherwise there will be data-race problem)
func syncGitConfig() (err error) {
if err = os.MkdirAll(HomeDir(), os.ModePerm); err != nil {
Expand Down Expand Up @@ -249,16 +232,6 @@ func syncGitConfig() (err error) {
return err
}

if setting.Git.Reflog.Enabled {
if err := enableReflogs(); err != nil {
return err
}
} else {
if err := disableReflogs(); err != nil {
return err
}
}

if CheckGitVersionAtLeast("2.10") == nil {
if err := configSet("receive.advertisePushOptions", "true"); err != nil {
return err
Expand Down
43 changes: 0 additions & 43 deletions modules/graceful/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,8 @@ package graceful

import (
"context"
"time"
)

// ChannelContext is a context that wraps a channel and error as a context
type ChannelContext struct {
done <-chan struct{}
err error
}

// NewChannelContext creates a ChannelContext from a channel and error
func NewChannelContext(done <-chan struct{}, err error) *ChannelContext {
return &ChannelContext{
done: done,
err: err,
}
}

// Deadline returns the time when work done on behalf of this context
// should be canceled. There is no Deadline for a ChannelContext
func (ctx *ChannelContext) Deadline() (deadline time.Time, ok bool) {
return deadline, ok
}

// Done returns the channel provided at the creation of this context.
// When closed, work done on behalf of this context should be canceled.
func (ctx *ChannelContext) Done() <-chan struct{} {
return ctx.done
}

// Err returns nil, if Done is not closed. If Done is closed,
// Err returns the error provided at the creation of this context
func (ctx *ChannelContext) Err() error {
select {
case <-ctx.done:
return ctx.err
default:
return nil
}
}

// Value returns nil for all calls as no values are or can be associated with this context
func (ctx *ChannelContext) Value(key interface{}) interface{} {
return nil
}

// ShutdownContext returns a context.Context that is Done at shutdown
// Callers using this context should ensure that they are registered as a running server
// in order that they are waited for.
Expand Down
Loading

0 comments on commit 4825cb5

Please sign in to comment.