Skip to content

Commit 38353f3

Browse files
committed
Merge remote-tracking branch 'origin/main' into migration-checks
2 parents e32d0a3 + 0887459 commit 38353f3

File tree

25 files changed

+1163
-261
lines changed

25 files changed

+1163
-261
lines changed

.drone.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ steps:
9090
- name: checks-backend
9191
image: golang:1.19
9292
commands:
93+
- curl -sL https://deb.nodesource.com/setup_18.x | bash - && apt-get -qqy install nodejs
9394
- make checks-backend
95+
environment:
96+
DEBIAN_FRONTEND: noninteractive
9497
depends_on: [deps-backend]
9598
volumes:
9699
- name: deps
@@ -722,12 +725,13 @@ steps:
722725
pull: always
723726
commands:
724727
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
725-
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
728+
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get -qqy install nodejs
726729
- export PATH=$PATH:$GOPATH/bin
727730
- make release
728731
environment:
729732
GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not
730733
TAGS: bindata sqlite sqlite_unlock_notify
734+
DEBIAN_FRONTEND: noninteractive
731735
volumes:
732736
- name: deps
733737
path: /go
@@ -842,12 +846,13 @@ steps:
842846
pull: always
843847
commands:
844848
# Upgrade to node 18 once https://github.com/techknowlogick/xgo/issues/163 is resolved
845-
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get install -y nodejs
849+
- curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get -qqy install nodejs
846850
- export PATH=$PATH:$GOPATH/bin
847851
- make release
848852
environment:
849853
GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not
850854
TAGS: bindata sqlite sqlite_unlock_notify
855+
DEBIAN_FRONTEND: noninteractive
851856
depends_on: [fetch-tags]
852857
volumes:
853858
- name: deps

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ cpu.out
9595
!/web_src/fomantic/build/themes/default/assets/fonts/outline-icons.woff2
9696
/VERSION
9797
/.air
98+
/.go-licenses
9899

99100
# Snapcraft
100101
snap/.snapcraft/

Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3434
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/[email protected]
3535
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]
3636
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
37+
GO_LICENSES_PACKAGE ?= github.com/google/[email protected]
3738

3839
DOCKER_IMAGE ?= gitea/gitea
3940
DOCKER_TAG ?= latest
@@ -114,13 +115,16 @@ SVG_DEST_DIR := public/img/svg
114115

115116
AIR_TMP_DIR := .air
116117

118+
GO_LICENSE_TMP_DIR := .go-licenses
119+
GO_LICENSE_FILE := assets/go-licenses.json
120+
117121
TAGS ?=
118122
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
119123
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
120124

121125
TEST_TAGS ?= sqlite sqlite_unlock_notify
122126

123-
TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR)
127+
TAR_EXCLUDES := .git data indexers queues log node_modules $(EXECUTABLE) $(FOMANTIC_WORK_DIR)/node_modules $(DIST) $(MAKE_EVIDENCE_DIR) $(AIR_TMP_DIR) $(GO_LICENSE_TMP_DIR)
124128

125129
GO_DIRS := cmd tests models modules routers build services tools
126130

@@ -199,8 +203,9 @@ help:
199203
@echo " - generate-swagger generate the swagger spec from code comments"
200204
@echo " - swagger-validate check if the swagger spec is valid"
201205
@echo " - golangci-lint run golangci-lint linter"
206+
@echo " - go-licenses regenerate go licenses"
202207
@echo " - vet examines Go source code and reports suspicious constructs"
203-
@echo " - tidy run go mod tidy"
208+
@echo " - tidy run go mod tidy and regenerate go licenses"
204209
@echo " - test[\#TestSpecificName] run unit test"
205210
@echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
206211
@echo " - pr#<index> build and start gitea from a PR with integration test data loaded"
@@ -393,6 +398,7 @@ unit-test-coverage:
393398
tidy:
394399
$(eval MIN_GO_VERSION := $(shell grep -Eo '^go\s+[0-9]+\.[0-9.]+' go.mod | cut -d' ' -f2))
395400
$(GO) mod tidy -compat=$(MIN_GO_VERSION)
401+
@$(MAKE) --no-print-directory assets/go-licenses.json
396402

397403
.PHONY: vendor
398404
vendor: tidy
@@ -407,6 +413,14 @@ tidy-check: tidy
407413
exit 1; \
408414
fi
409415

416+
.PHONY: go-licenses
417+
go-licenses: assets/go-licenses.json
418+
419+
assets/go-licenses.json: go.mod go.sum build/generate-go-licenses.js
420+
-$(GO) run $(GO_LICENSES_PACKAGE) save . --force --save_path="$(GO_LICENSE_TMP_DIR)" 2>/dev/null
421+
node build/generate-go-licenses.js "$(GO_LICENSE_TMP_DIR)" "$(GO_LICENSE_FILE)"
422+
@rm -rf "$(GO_LICENSE_TMP_DIR)"
423+
410424
generate-ini-sqlite:
411425
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
412426
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
@@ -782,6 +796,7 @@ deps-backend:
782796
$(GO) install $(MISSPELL_PACKAGE)
783797
$(GO) install $(SWAGGER_PACKAGE)
784798
$(GO) install $(XGO_PACKAGE)
799+
$(GO) install $(GO_LICENSES_PACKAGE)
785800

786801
node_modules: package-lock.json
787802
npm install --no-save

assets/go-licenses.json

Lines changed: 762 additions & 0 deletions
Large diffs are not rendered by default.

build/generate-go-licenses.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env node
2+
import fastGlob from 'fast-glob';
3+
import {fileURLToPath} from 'url';
4+
import {readFileSync, writeFileSync} from 'fs';
5+
import wrapAnsi from 'wrap-ansi';
6+
import {join, dirname} from 'path';
7+
8+
const base = process.argv[2];
9+
const out = process.argv[3];
10+
11+
function exit(err) {
12+
if (err) console.error(err);
13+
process.exit(err ? 1 : 0);
14+
}
15+
16+
async function main() {
17+
const data = fastGlob.sync('**/*', {
18+
cwd: fileURLToPath(new URL(`../${base}`, import.meta.url)),
19+
}).filter((path) => {
20+
return /\/((UN)?LICEN(S|C)E|COPYING|NOTICE)/i.test(path);
21+
}).sort().map((path) => {
22+
return {
23+
name: dirname(path),
24+
body: wrapAnsi(readFileSync(join(base, path), 'utf8') || '', 80)
25+
};
26+
});
27+
writeFileSync(out, JSON.stringify(data, null, 2));
28+
}
29+
30+
main().then(exit).catch(exit);
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
date: " 2022-09-01T20:50:42+0000"
3+
title: "Usage: Agit Setup"
4+
slug: "agit-setup"
5+
weight: 12
6+
toc: false
7+
draft: false
8+
menu:
9+
sidebar:
10+
parent: "usage"
11+
name: "Agit Setup"
12+
weight: 12
13+
identifier: "agit-setup"
14+
---
15+
16+
# Agit Setup
17+
18+
In Gitea `1.13`, support for [agit](https://git-repo.info/en/2020/03/agit-flow-and-git-repo/) was added.
19+
20+
## Creating PRs with Agit
21+
22+
Agit allows to create PRs while pushing code to the remote repo. \
23+
This can be done by pushing to the branch followed by a specific refspec (a location identifier known to git). \
24+
The following example illustrates this:
25+
26+
```shell
27+
git push origin HEAD:refs/for/master
28+
```
29+
30+
The command has the following structure:
31+
32+
- `HEAD`: The target branch
33+
- `refs/<for|draft|for-review>/<branch>`: The target PR type
34+
- `for`: Create a normal PR with `<branch>` as the target branch
35+
- `draft`/ `for-review`: Currently ignored silently
36+
- `<branch>/<session>`: The target branch to open the PR
37+
- `-o <topic|title|description>`: Options for the PR
38+
- `title`: The PR title
39+
- `topic`: The branch name the PR should be opened for
40+
- `description`: The PR description
41+
- `force-push`: confirm force update the target branch
42+
43+
Here's another advanced example for creating a new PR targeting `master` with `topic`, `title`, and `description`:
44+
45+
```shell
46+
git push origin HEAD:refs/for/master -o topic="Topic of my PR" -o title="Title of the PR" -o description="# The PR Description\nThis can be **any** markdown content.\n- [x] Ok"
47+
```

models/activities/action.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ func (a *Action) TableIndices() []*schemas.Index {
9898
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
9999
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
100100

101-
return []*schemas.Index{actUserIndex, repoIndex}
101+
indices := []*schemas.Index{actUserIndex, repoIndex}
102+
if setting.Database.UsePostgreSQL {
103+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
104+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
105+
indices = append(indices, cudIndex)
106+
}
107+
108+
return indices
102109
}
103110

104111
// GetOpType gets the ActionType of this action.

models/migrations/v218.go

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

77
import (
8+
"code.gitea.io/gitea/modules/setting"
89
"code.gitea.io/gitea/modules/timeutil"
910

1011
"xorm.io/xorm"
@@ -37,8 +38,14 @@ func (*improveActionTableIndicesAction) TableIndices() []*schemas.Index {
3738

3839
actUserIndex := schemas.NewIndex("au_r_c_u_d", schemas.IndexType)
3940
actUserIndex.AddColumn("act_user_id", "repo_id", "created_unix", "user_id", "is_deleted")
40-
41-
return []*schemas.Index{actUserIndex, repoIndex}
41+
indices := []*schemas.Index{actUserIndex, repoIndex}
42+
if setting.Database.UsePostgreSQL {
43+
cudIndex := schemas.NewIndex("c_u_d", schemas.IndexType)
44+
cudIndex.AddColumn("created_unix", "user_id", "is_deleted")
45+
indices = append(indices, cudIndex)
46+
}
47+
48+
return indices
4249
}
4350

4451
func improveActionTableIndices(x *xorm.Engine) error {

models/packages/package.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,16 @@ func FindUnreferencedPackages(ctx context.Context) ([]*Package, error) {
224224
Find(&ps)
225225
}
226226

227-
// HasOwnerPackages tests if a user/org has packages
227+
// HasOwnerPackages tests if a user/org has accessible packages
228228
func HasOwnerPackages(ctx context.Context, ownerID int64) (bool, error) {
229-
return db.GetEngine(ctx).Where("owner_id = ?", ownerID).Exist(&Package{})
229+
return db.GetEngine(ctx).
230+
Table("package_version").
231+
Join("INNER", "package", "package.id = package_version.package_id").
232+
Where(builder.Eq{
233+
"package_version.is_internal": false,
234+
"package.owner_id": ownerID,
235+
}).
236+
Exist(&PackageVersion{})
230237
}
231238

232239
// HasRepositoryPackages tests if a repository has packages

models/packages/package_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2022 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 packages_test
6+
7+
import (
8+
"path/filepath"
9+
"testing"
10+
11+
"code.gitea.io/gitea/models/db"
12+
packages_model "code.gitea.io/gitea/models/packages"
13+
"code.gitea.io/gitea/models/unittest"
14+
user_model "code.gitea.io/gitea/models/user"
15+
16+
_ "code.gitea.io/gitea/models"
17+
18+
"github.com/stretchr/testify/assert"
19+
)
20+
21+
func TestMain(m *testing.M) {
22+
unittest.MainTest(m, &unittest.TestOptions{
23+
GiteaRootPath: filepath.Join("..", ".."),
24+
})
25+
}
26+
27+
func TestHasOwnerPackages(t *testing.T) {
28+
assert.NoError(t, unittest.PrepareTestDatabase())
29+
30+
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
31+
32+
p, err := packages_model.TryInsertPackage(db.DefaultContext, &packages_model.Package{
33+
OwnerID: owner.ID,
34+
LowerName: "package",
35+
})
36+
assert.NotNil(t, p)
37+
assert.NoError(t, err)
38+
39+
// A package without package versions gets automatically cleaned up and should return false
40+
has, err := packages_model.HasOwnerPackages(db.DefaultContext, owner.ID)
41+
assert.False(t, has)
42+
assert.NoError(t, err)
43+
44+
pv, err := packages_model.GetOrInsertVersion(db.DefaultContext, &packages_model.PackageVersion{
45+
PackageID: p.ID,
46+
LowerVersion: "internal",
47+
IsInternal: true,
48+
})
49+
assert.NotNil(t, pv)
50+
assert.NoError(t, err)
51+
52+
// A package with an internal package version gets automaticaly cleaned up and should return false
53+
has, err = packages_model.HasOwnerPackages(db.DefaultContext, owner.ID)
54+
assert.False(t, has)
55+
assert.NoError(t, err)
56+
57+
pv, err = packages_model.GetOrInsertVersion(db.DefaultContext, &packages_model.PackageVersion{
58+
PackageID: p.ID,
59+
LowerVersion: "normal",
60+
IsInternal: false,
61+
})
62+
assert.NotNil(t, pv)
63+
assert.NoError(t, err)
64+
65+
// A package with a normal package version should return true
66+
has, err = packages_model.HasOwnerPackages(db.DefaultContext, owner.ID)
67+
assert.True(t, has)
68+
assert.NoError(t, err)
69+
}

options/license/Fair

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ Fair License
55
Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument.
66

77
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
8-
9-
[2004, Fair License: rhid.com/fair (this URL no longer works)]

options/license/Python-2.0.1

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,3 @@ FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
191191
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
192192
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
193193
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
194-
195-
ZERO-CLAUSE BSD LICENSE FOR CODE IN THE PYTHON DOCUMENTATION
196-
----------------------------------------------------------------------
197-
198-
Permission to use, copy, modify, and/or distribute this software for any
199-
purpose with or without fee is hereby granted.
200-
201-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
202-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
203-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
204-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
205-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
206-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
207-
PERFORMANCE OF THIS SOFTWARE.

options/license/Spencer-86

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ Permission is granted to anyone to use this software for any purpose on any comp
77
2. The origin of this software must not be misrepresented, either by explicit claim or by omission.
88

99
3. Altered versions must be plainly marked as such, and must not be misrepresented as being the original software.
10-
11-
Beware that some of this code is subtly aware of the way operator precedence is structured in regular expressions. Serious changes in regular-expression syntax might require a total rethink.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
As a special exception, if you link this library with other files to produce an executable, this library does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License."
1+
As a special exception, if you link this library with other files to produce an executable, this library does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License.

templates/org/team/teams.tmpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
</div>
3333
<div class="ui attached segment members">
3434
{{range .Members}}
35-
<a href="{{.HomeLink}}" title="{{.Name}}">
36-
{{avatar .}}
37-
</a>
35+
{{template "shared/user/avatarlink" .}}
3836
{{end}}
3937
</div>
4038
<div class="ui bottom attached header">

templates/repo/diff/comments.tmpl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
{{if .OriginalAuthor}}
66
<span class="avatar"><img src="{{AppSubUrl}}/assets/img/avatar_default.png"></span>
77
{{else}}
8-
<a class="avatar" {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>
9-
{{avatar .Poster}}
10-
</a>
8+
{{template "shared/user/avatarlink" .Poster}}
119
{{end}}
1210
<div class="content comment-container">
1311
<div class="ui top attached header comment-header df ac sb">
@@ -27,9 +25,7 @@
2725
</span>
2826
{{else}}
2927
<span class="text grey">
30-
<a {{if gt .Poster.ID 0}}href="{{.Poster.HomeLink}}"{{end}}>
31-
{{.Poster.GetDisplayName}}
32-
</a>
28+
{{template "shared/user/namelink" .Poster}}
3329
{{$.root.locale.Tr "repo.issues.commented_at" (.HashTag|Escape) $createdStr | Safe}}
3430
</span>
3531
{{end}}

0 commit comments

Comments
 (0)