Skip to content

Commit e166d49

Browse files
authored
Merge branch 'master' into oauth2-auto-register
2 parents 7b2ff29 + b56c19d commit e166d49

Some content is hidden

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

72 files changed

+592
-113
lines changed

.github/issue_template.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
<!-- In addition, if your problem relates to git commands set `RUN_MODE=dev` at the top of app.ini -->
3131

3232
## Description
33+
<!-- If using a proxy or a CDN (e.g. CloudFlare) in front of gitea, please
34+
disable the proxy/CDN fully and connect to gitea directly to confirm
35+
the issue still persists without those services. -->
3336

3437
...
3538

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ release-windows: | $(DIST_DIRS)
573573
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
574574
GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
575575
fi
576-
@echo "Warning: windows version is built using golang 1.14"
577576
CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -buildmode exe -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
578577
ifeq ($(CI),drone)
579578
cp /build/* $(DIST)/binaries
@@ -709,7 +708,7 @@ pr\#%: clean-all
709708
golangci-lint:
710709
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
711710
export BINARY="golangci-lint"; \
712-
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.35.2; \
711+
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.37.0; \
713712
fi
714713
golangci-lint run --timeout 10m
715714

docs/content/doc/usage/command-line.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Generates a self-signed SSL certificate. Outputs to `cert.pem` and `key.pem` in
232232
directory and will overwrite any existing files.
233233

234234
- Options:
235-
- `--host value`: Comma seperated hostnames and ips which this certificate is valid for.
235+
- `--host value`: Comma separated hostnames and ips which this certificate is valid for.
236236
Wildcards are supported. Required.
237237
- `--ecdsa-curve value`: ECDSA curve to use to generate a key. Optional. Valid options
238238
are P224, P256, P384, P521.

integrations/api_admin_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,18 @@ func TestAPIEditUser(t *testing.T) {
192192
errMap := make(map[string]interface{})
193193
json.Unmarshal(resp.Body.Bytes(), &errMap)
194194
assert.EqualValues(t, "email is not allowed to be empty string", errMap["message"].(string))
195+
196+
user2 := models.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
197+
assert.Equal(t, false, user2.IsRestricted)
198+
bTrue := true
199+
req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
200+
// required
201+
LoginName: "user2",
202+
SourceID: 0,
203+
// to change
204+
Restricted: &bTrue,
205+
})
206+
session.MakeRequest(t, req, http.StatusOK)
207+
user2 = models.AssertExistsAndLoadBean(t, &models.User{LoginName: "user2"}).(*models.User)
208+
assert.Equal(t, true, user2.IsRestricted)
195209
}

integrations/api_settings_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ func TestAPIExposedSettings(t *testing.T) {
4343

4444
DecodeJSON(t, resp, &repo)
4545
assert.EqualValues(t, &api.GeneralRepoSettings{
46-
MirrorsDisabled: setting.Repository.DisableMirrors,
47-
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
48-
MigrationsDisabled: setting.Repository.DisableMigrations,
46+
MirrorsDisabled: setting.Repository.DisableMirrors,
47+
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
48+
MigrationsDisabled: setting.Repository.DisableMigrations,
49+
TimeTrackingDisabled: false,
50+
LFSDisabled: !setting.LFS.StartServer,
4951
}, repo)
5052

5153
attachment := new(api.GeneralAttachmentSettings)

models/action.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,13 @@ func (a *Action) GetIssueContent() string {
289289

290290
// GetFeedsOptions options for retrieving feeds
291291
type GetFeedsOptions struct {
292-
RequestedUser *User // the user we want activity for
293-
RequestedTeam *Team // the team we want activity for
294-
Actor *User // the user viewing the activity
295-
IncludePrivate bool // include private actions
296-
OnlyPerformedBy bool // only actions performed by requested user
297-
IncludeDeleted bool // include deleted actions
292+
RequestedUser *User // the user we want activity for
293+
RequestedTeam *Team // the team we want activity for
294+
Actor *User // the user viewing the activity
295+
IncludePrivate bool // include private actions
296+
OnlyPerformedBy bool // only actions performed by requested user
297+
IncludeDeleted bool // include deleted actions
298+
Date string // the day we want activity for: YYYY-MM-DD
298299
}
299300

300301
// GetFeeds returns actions according to the provided options
@@ -380,5 +381,17 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
380381
cond = cond.And(builder.Eq{"is_deleted": false})
381382
}
382383

384+
if opts.Date != "" {
385+
dateLow, err := time.Parse("2006-01-02", opts.Date)
386+
if err != nil {
387+
log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
388+
} else {
389+
dateHigh := dateLow.Add(86399000000000) // 23h59m59s
390+
391+
cond = cond.And(builder.Gte{"created_unix": dateLow.Unix()})
392+
cond = cond.And(builder.Lte{"created_unix": dateHigh.Unix()})
393+
}
394+
}
395+
383396
return cond, nil
384397
}

models/action_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestAction_GetRepoLink(t *testing.T) {
2626
repo := AssertExistsAndLoadBean(t, &Repository{}).(*Repository)
2727
owner := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
2828
action := &Action{RepoID: repo.ID}
29-
setting.AppSubURL = "/suburl/"
29+
setting.AppSubURL = "/suburl"
3030
expected := path.Join(setting.AppSubURL, owner.Name, repo.Name)
3131
assert.Equal(t, expected, action.GetRepoLink())
3232
}

models/issue_comment.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ type Comment struct {
136136
MilestoneID int64
137137
OldMilestone *Milestone `xorm:"-"`
138138
Milestone *Milestone `xorm:"-"`
139+
TimeID int64
140+
Time *TrackedTime `xorm:"-"`
139141
AssigneeID int64
140142
RemovedAssignee bool
141143
Assignee *User `xorm:"-"`
@@ -541,6 +543,16 @@ func (c *Comment) LoadDepIssueDetails() (err error) {
541543
return err
542544
}
543545

546+
// LoadTime loads the associated time for a CommentTypeAddTimeManual
547+
func (c *Comment) LoadTime() error {
548+
if c.Time != nil || c.TimeID == 0 {
549+
return nil
550+
}
551+
var err error
552+
c.Time, err = GetTrackedTimeByID(c.TimeID)
553+
return err
554+
}
555+
544556
func (c *Comment) loadReactions(e Engine, repo *Repository) (err error) {
545557
if c.Reactions != nil {
546558
return nil
@@ -692,6 +704,7 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
692704
MilestoneID: opts.MilestoneID,
693705
OldProjectID: opts.OldProjectID,
694706
ProjectID: opts.ProjectID,
707+
TimeID: opts.TimeID,
695708
RemovedAssignee: opts.RemovedAssignee,
696709
AssigneeID: opts.AssigneeID,
697710
AssigneeTeamID: opts.AssigneeTeamID,
@@ -859,6 +872,7 @@ type CreateCommentOptions struct {
859872
MilestoneID int64
860873
OldProjectID int64
861874
ProjectID int64
875+
TimeID int64
862876
AssigneeID int64
863877
AssigneeTeamID int64
864878
RemovedAssignee bool

models/issue_stopwatch.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error {
100100
Repo: issue.Repo,
101101
Content: SecToTime(timediff),
102102
Type: CommentTypeStopTracking,
103+
TimeID: tt.ID,
103104
}); err != nil {
104105
return err
105106
}

models/issue_tracked_time.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ func AddTime(user *User, issue *Issue, amount int64, created time.Time) (*Tracke
162162
Doer: user,
163163
Content: SecToTime(amount),
164164
Type: CommentTypeAddTimeManual,
165+
TimeID: t.ID,
165166
}); err != nil {
166167
return nil, err
167168
}

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ var migrations = []Migration{
292292
NewMigration("Add Sorting to ProjectBoard table", addSortingColToProjectBoard),
293293
// v172 -> v173
294294
NewMigration("Add sessions table for go-chi/session", addSessionTable),
295+
// v173 -> v174
296+
NewMigration("Add time_id column to Comment", addTimeIDCommentColumn),
295297
}
296298

297299
// GetCurrentDBVersion returns the current db version

models/migrations/v166.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ func recalculateUserEmptyPWD(x *xorm.Engine) (err error) {
106106
}
107107

108108
// delete salt and algo where password is empty
109-
if _, err = sess.Where(builder.Eq{"passwd": ""}.And(builder.Neq{"salt": ""}.Or(builder.Neq{"passwd_hash_algo": ""}))).
110-
Cols("salt", "passwd_hash_algo").Update(&User{}); err != nil {
111-
return err
112-
}
109+
_, err = sess.Where(builder.Eq{"passwd": ""}.And(builder.Neq{"salt": ""}.Or(builder.Neq{"passwd_hash_algo": ""}))).
110+
Cols("salt", "passwd_hash_algo").Update(&User{})
113111

114-
return sess.Commit()
112+
return err
115113
}

models/migrations/v173.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"fmt"
9+
10+
"xorm.io/xorm"
11+
)
12+
13+
func addTimeIDCommentColumn(x *xorm.Engine) error {
14+
type Comment struct {
15+
TimeID int64
16+
}
17+
18+
if err := x.Sync2(new(Comment)); err != nil {
19+
return fmt.Errorf("Sync2: %v", err)
20+
}
21+
return nil
22+
}

models/notification.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package models
66

77
import (
88
"fmt"
9-
"path"
9+
"strconv"
1010

1111
"code.gitea.io/gitea/modules/log"
1212
"code.gitea.io/gitea/modules/setting"
@@ -413,7 +413,7 @@ func (n *Notification) HTMLURL() string {
413413

414414
// APIURL formats a URL-string to the notification
415415
func (n *Notification) APIURL() string {
416-
return setting.AppURL + path.Join("api/v1/notifications/threads", fmt.Sprintf("%d", n.ID))
416+
return setting.AppURL + "api/v1/notifications/threads/" + strconv.FormatInt(n.ID, 10)
417417
}
418418

419419
// NotificationList contains a list of notifications

models/pull.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"code.gitea.io/gitea/modules/log"
1414
"code.gitea.io/gitea/modules/setting"
1515
"code.gitea.io/gitea/modules/timeutil"
16+
"code.gitea.io/gitea/modules/util"
1617
)
1718

1819
// PullRequestType defines pull request type
@@ -638,3 +639,27 @@ func (pr *PullRequest) updateCommitDivergence(e Engine, ahead, behind int) error
638639
func (pr *PullRequest) IsSameRepo() bool {
639640
return pr.BaseRepoID == pr.HeadRepoID
640641
}
642+
643+
// GetBaseBranchHTMLURL returns the HTML URL of the base branch
644+
func (pr *PullRequest) GetBaseBranchHTMLURL() string {
645+
if err := pr.LoadBaseRepo(); err != nil {
646+
log.Error("LoadBaseRepo: %v", err)
647+
return ""
648+
}
649+
if pr.BaseRepo == nil {
650+
return ""
651+
}
652+
return pr.BaseRepo.HTMLURL() + "/src/branch/" + util.PathEscapeSegments(pr.BaseBranch)
653+
}
654+
655+
// GetHeadBranchHTMLURL returns the HTML URL of the head branch
656+
func (pr *PullRequest) GetHeadBranchHTMLURL() string {
657+
if err := pr.LoadHeadRepo(); err != nil {
658+
log.Error("LoadHeadRepo: %v", err)
659+
return ""
660+
}
661+
if pr.HeadRepo == nil {
662+
return ""
663+
}
664+
return pr.HeadRepo.HTMLURL() + "/src/branch/" + util.PathEscapeSegments(pr.HeadBranch)
665+
}

models/repo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func (repo *Repository) ColorFormat(s fmt.State) {
264264
repo.Name)
265265
}
266266

267-
// IsBeingMigrated indicates that repository is being migtated
267+
// IsBeingMigrated indicates that repository is being migrated
268268
func (repo *Repository) IsBeingMigrated() bool {
269269
return repo.Status == RepositoryBeingMigrated
270270
}
@@ -318,7 +318,7 @@ func (repo *Repository) CommitLink(commitID string) (result string) {
318318

319319
// APIURL returns the repository API URL
320320
func (repo *Repository) APIURL() string {
321-
return setting.AppURL + path.Join("api/v1/repos", repo.FullName())
321+
return setting.AppURL + "api/v1/repos/" + repo.FullName()
322322
}
323323

324324
// GetCommitsCountCacheKey returns cache key used for commits count caching.
@@ -613,7 +613,7 @@ func (repo *Repository) getReviewers(e Engine, doerID, posterID int64) ([]*User,
613613
// * for private repositories this returns all users that have read access or higher to the repository.
614614
// * for public repositories this returns all users that have write access or higher to the repository,
615615
// and all repo watchers.
616-
// TODO: may be we should hava a busy choice for users to block review request to them.
616+
// TODO: may be we should have a busy choice for users to block review request to them.
617617
func (repo *Repository) GetReviewers(doerID, posterID int64) ([]*User, error) {
618618
return repo.getReviewers(x, doerID, posterID)
619619
}

models/user_avatar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (u *User) generateRandomAvatar(e Engine) error {
6363
// the local explore page. Function returns immediately.
6464
// When applicable, the link is for an avatar of the indicated size (in pixels).
6565
func (u *User) SizedRelAvatarLink(size int) string {
66-
return strings.TrimSuffix(setting.AppSubURL, "/") + "/user/avatar/" + u.Name + "/" + strconv.Itoa(size)
66+
return setting.AppSubURL + "/user/avatar/" + u.Name + "/" + strconv.Itoa(size)
6767
}
6868

6969
// RealSizedAvatarLink returns a link to the user's avatar. When

modules/context/context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ func (ctx *Context) HTML(status int, name base.TplName) {
188188
return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms"
189189
}
190190
if err := ctx.Render.HTML(ctx.Resp, status, string(name), ctx.Data); err != nil {
191+
if status == http.StatusInternalServerError && name == base.TplName("status/500") {
192+
ctx.PlainText(http.StatusInternalServerError, []byte("Unable to find status/500 template"))
193+
return
194+
}
191195
ctx.ServerError("Render failed", err)
192196
}
193197
}

modules/convert/user.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ func ToUser(user *models.User, signed, authed bool) *api.User {
1717
return nil
1818
}
1919
result := &api.User{
20-
ID: user.ID,
21-
UserName: user.Name,
22-
FullName: markup.Sanitize(user.FullName),
23-
Email: user.GetEmail(),
24-
AvatarURL: user.AvatarLink(),
25-
Created: user.CreatedUnix.AsTime(),
20+
ID: user.ID,
21+
UserName: user.Name,
22+
FullName: markup.Sanitize(user.FullName),
23+
Email: user.GetEmail(),
24+
AvatarURL: user.AvatarLink(),
25+
Created: user.CreatedUnix.AsTime(),
26+
Restricted: user.IsRestricted,
2627
}
2728
// hide primary email if API caller is anonymous or user keep email private
2829
if signed && (!user.KeepEmailPrivate || authed) {

modules/git/repo_commit_nogogit.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package git
88

99
import (
1010
"bufio"
11+
"errors"
1112
"fmt"
1213
"io"
1314
"io/ioutil"
@@ -70,10 +71,15 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
7071
bufReader := bufio.NewReader(stdoutReader)
7172
_, typ, size, err := ReadBatchLine(bufReader)
7273
if err != nil {
74+
if errors.Is(err, io.EOF) {
75+
return nil, ErrNotExist{ID: id.String()}
76+
}
7377
return nil, err
7478
}
7579

7680
switch typ {
81+
case "missing":
82+
return nil, ErrNotExist{ID: id.String()}
7783
case "tag":
7884
// then we need to parse the tag
7985
// and load the commit

0 commit comments

Comments
 (0)