Skip to content

Commit 038a042

Browse files
committed
Merge remote-tracking branch 'origin/release/v1.18' into backport-22535-v1.18
2 parents 30017e3 + 1ae2525 commit 038a042

File tree

8 files changed

+68
-4
lines changed

8 files changed

+68
-4
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ This changelog goes through all the changes that have been made in each release
44
without substantial changes to our git log; to see the highlights of what has
55
been added to each release, please refer to the [blog](https://blog.gitea.io).
66

7+
## [1.18.2](https://github.com/go-gitea/gitea/releases/tag/v1.18.2) - 2023-01-19
8+
9+
* BUGFIXES
10+
* Fix issue not auto-closing when it includes a reference to a branch (#22514) (#22521)
11+
* Fix invalid issue branch reference if not specified in template (#22513) (#22520)
12+
* Fix 500 error viewing pull request when fork has pull requests disabled (#22512) (#22515)
13+
* Reliable selection of admin user (#22509) (#22511)
14+
* Set disable_gravatar/enable_federated_avatar when offline mode is true (#22479) (#22496)
15+
* BUILD
16+
* cgo cross-compile for freebsd (#22397) (#22519)
17+
718
## [1.18.1](https://github.com/go-gitea/gitea/releases/tag/v1.18.1) - 2023-01-17
819

920
* API

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
733733
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
734734

735735
.PHONY: release
736-
release: frontend generate release-windows release-linux release-darwin release-copy release-compress vendor release-sources release-docs release-check
736+
release: frontend generate release-windows release-linux release-darwin release-freebsd release-copy release-compress vendor release-sources release-docs release-check
737737

738738
$(DIST_DIRS):
739739
mkdir -p $(DIST_DIRS)
@@ -762,6 +762,13 @@ ifeq ($(CI),true)
762762
cp /build/* $(DIST)/binaries
763763
endif
764764

765+
.PHONY: release-freebsd
766+
release-freebsd: | $(DIST_DIRS)
767+
CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'freebsd/amd64' -out gitea-$(VERSION) .
768+
ifeq ($(CI),true)
769+
cp /build/* $(DIST)/binaries
770+
endif
771+
765772
.PHONY: release-copy
766773
release-copy: | $(DIST_DIRS)
767774
cd $(DIST); for file in `find . -type f -name "*"`; do cp $${file} ./release/; done;

models/system/setting.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ func Init() error {
269269
if setting_module.OfflineMode {
270270
disableGravatar = true
271271
enableFederatedAvatar = false
272+
if !GetSettingBool(KeyPictureDisableGravatar) {
273+
if err := SetSettingNoVersion(KeyPictureDisableGravatar, "true"); err != nil {
274+
return fmt.Errorf("Failed to set setting %q: %w", KeyPictureDisableGravatar, err)
275+
}
276+
}
277+
if GetSettingBool(KeyPictureEnableFederatedAvatar) {
278+
if err := SetSettingNoVersion(KeyPictureEnableFederatedAvatar, "false"); err != nil {
279+
return fmt.Errorf("Failed to set setting %q: %w", KeyPictureEnableFederatedAvatar, err)
280+
}
281+
}
272282
}
273283

274284
if enableFederatedAvatar || !disableGravatar {

models/user/user.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1227,7 +1227,10 @@ func GetUserByOpenID(uri string) (*User, error) {
12271227
// GetAdminUser returns the first administrator
12281228
func GetAdminUser() (*User, error) {
12291229
var admin User
1230-
has, err := db.GetEngine(db.DefaultContext).Where("is_admin=?", true).Get(&admin)
1230+
has, err := db.GetEngine(db.DefaultContext).
1231+
Where("is_admin=?", true).
1232+
Asc("id"). // Reliably get the admin with the lowest ID.
1233+
Get(&admin)
12311234
if err != nil {
12321235
return nil, err
12331236
} else if !has {

routers/web/admin/config.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
package admin
77

88
import (
9+
"fmt"
910
"net/http"
1011
"net/url"
1112
"os"
13+
"strconv"
1214
"strings"
1315

1416
system_model "code.gitea.io/gitea/models/system"
@@ -202,6 +204,16 @@ func ChangeConfig(ctx *context.Context) {
202204
value := ctx.FormString("value")
203205
version := ctx.FormInt("version")
204206

207+
if check, ok := changeConfigChecks[key]; ok {
208+
if err := check(ctx, value); err != nil {
209+
log.Warn("refused to set setting: %v", err)
210+
ctx.JSON(http.StatusOK, map[string]string{
211+
"err": ctx.Tr("admin.config.set_setting_failed", key),
212+
})
213+
return
214+
}
215+
}
216+
205217
if err := system_model.SetSetting(&system_model.Setting{
206218
SettingKey: key,
207219
SettingValue: value,
@@ -218,3 +230,18 @@ func ChangeConfig(ctx *context.Context) {
218230
"version": version + 1,
219231
})
220232
}
233+
234+
var changeConfigChecks = map[string]func(ctx *context.Context, newValue string) error{
235+
system_model.KeyPictureDisableGravatar: func(_ *context.Context, newValue string) error {
236+
if v, _ := strconv.ParseBool(newValue); setting.OfflineMode && !v {
237+
return fmt.Errorf("%q should be true when OFFLINE_MODE is true", system_model.KeyPictureDisableGravatar)
238+
}
239+
return nil
240+
},
241+
system_model.KeyPictureEnableFederatedAvatar: func(_ *context.Context, newValue string) error {
242+
if v, _ := strconv.ParseBool(newValue); setting.OfflineMode && v {
243+
return fmt.Errorf("%q cannot be false when OFFLINE_MODE is true", system_model.KeyPictureEnableFederatedAvatar)
244+
}
245+
return nil
246+
},
247+
}

routers/web/repo/issue.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
786786
}
787787

788788
}
789-
if !strings.HasPrefix(template.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/<ref>
789+
790+
if template.Ref != "" && !strings.HasPrefix(template.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/<ref>
790791
template.Ref = git.BranchPrefix + template.Ref
791792
}
792793
ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0

services/issue/commit.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
repo_model "code.gitea.io/gitea/models/repo"
2020
user_model "code.gitea.io/gitea/models/user"
2121
"code.gitea.io/gitea/modules/container"
22+
"code.gitea.io/gitea/modules/git"
2223
"code.gitea.io/gitea/modules/log"
2324
"code.gitea.io/gitea/modules/references"
2425
"code.gitea.io/gitea/modules/repository"
@@ -176,7 +177,8 @@ func UpdateIssuesCommit(doer *user_model.User, repo *repo_model.Repository, comm
176177
if !repo.CloseIssuesViaCommitInAnyBranch {
177178
// If the issue was specified to be in a particular branch, don't allow commits in other branches to close it
178179
if refIssue.Ref != "" {
179-
if branchName != refIssue.Ref {
180+
issueBranchName := strings.TrimPrefix(refIssue.Ref, git.BranchPrefix)
181+
if branchName != issueBranchName {
180182
continue
181183
}
182184
// Otherwise, only process commits to the default branch

services/pull/update.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func IsUserAllowedToUpdate(ctx context.Context, pull *issues_model.PullRequest,
109109
if pr.ProtectedBranch == nil {
110110
prUnit, err := pr.BaseRepo.GetUnit(unit.TypePullRequests)
111111
if err != nil {
112+
if repo_model.IsErrUnitTypeNotExist(err) {
113+
return false, false, nil
114+
}
112115
log.Error("pr.BaseRepo.GetUnit(unit.TypePullRequests): %v", err)
113116
return false, false, err
114117
}

0 commit comments

Comments
 (0)