mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09:00
Adds a repository-level **"Restrict to collaborators"** option under the Issues and Pull Request unit settings. When enabled, only users with collaborator access to the base repository (owner, team members, or explicit collaborators) can open issues or pull requests against it. Public repositories often need to be visible/cloneable by everyone, but owners may want to limit who can open pull requests (e.g. restrict to an internal team while still keeping the code public) * Fixes: https://github.com/go-gitea/gitea/issues/40015 * Fixes: https://github.com/go-gitea/gitea/issues/31890 * Fixes: https://github.com/go-gitea/gitea/issues/28021 * Fixes: https://github.com/go-gitea/gitea/issues/14801 --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestErrorTranslatable(t *testing.T) {
|
|
var err error
|
|
|
|
err = ErrorWrapTranslatable(io.EOF, "key", 1)
|
|
assert.ErrorIs(t, err, io.EOF)
|
|
assert.Equal(t, "EOF", err.Error())
|
|
wrapped, ok := err.(*errorTranslatableWrapper)
|
|
require.True(t, ok)
|
|
assert.Equal(t, "key", wrapped.trKey)
|
|
assert.Equal(t, []any{1}, wrapped.trArgs)
|
|
|
|
err = ErrorWrap(err, "new msg %d", 100)
|
|
assert.ErrorIs(t, err, io.EOF)
|
|
assert.Equal(t, "new msg 100", err.Error())
|
|
|
|
errTr := ErrorAsTranslatable(err)
|
|
assert.Equal(t, "EOF", errTr.Error())
|
|
wrapped, ok = errTr.(*errorTranslatableWrapper)
|
|
require.True(t, ok)
|
|
assert.Equal(t, "key", wrapped.trKey)
|
|
|
|
errTr = ErrorAsTranslatable(nil)
|
|
assert.True(t, errTr == nil) //nolint:testifylint // assert golang nil interface wrapper
|
|
}
|
|
|
|
func TestErrorUnwrapForUser(t *testing.T) {
|
|
err := NewNotExistErrorf("test msg")
|
|
msg, code := ErrorUnwrapForUser(err)
|
|
assert.Equal(t, "test msg", msg)
|
|
assert.Equal(t, 404, code)
|
|
|
|
err = fmt.Errorf("other wrapper: %w", err)
|
|
msg, code = ErrorUnwrapForUser(err)
|
|
assert.Equal(t, "other wrapper: test msg", msg)
|
|
assert.Equal(t, 404, code)
|
|
|
|
msg, code = ErrorUnwrapForUser(io.EOF)
|
|
assert.Equal(t, "", msg)
|
|
assert.Equal(t, 0, code)
|
|
}
|