Compare commits
33 Commits
v1.2.0-rc1
...
v1.2.1
Author | SHA1 | Date | |
---|---|---|---|
|
46bb1cf026 | ||
|
13013e90f3 | ||
785ba171f4 | |||
|
fb80265b52 | ||
|
6fae585d28 | ||
670562a9c5 | |||
ed07d8a308 | |||
|
74399f333f | ||
|
d1cec5ecfa | ||
|
73ad7d2ef3 | ||
|
5b36379172 | ||
|
e38e502e20 | ||
|
3cc5b11b0d | ||
|
4c9bf91a2c | ||
03ff7687e0 | |||
f646154ead | |||
|
a6d2f47a2b | ||
|
1837194882 | ||
|
9ca26432f6 | ||
|
67595c0d0b | ||
|
6d03cf831e | ||
|
e232c49b10 | ||
|
25e71ad41e | ||
|
f014e42a06 | ||
|
d14a724b53 | ||
|
91788e0200 | ||
|
fc0c6f48c7 | ||
|
002fa73460 | ||
2fdc649202 | |||
|
0c910afe11 | ||
1cbe502cc2 | |||
|
f916aa0fe3 | ||
04728b5b91 |
91
.drone.yml
91
.drone.yml
@ -2,12 +2,13 @@ workspace:
|
||||
base: /srv/app
|
||||
path: src/code.gitea.io/gitea
|
||||
|
||||
pipeline:
|
||||
clone:
|
||||
image: plugins/git
|
||||
clone:
|
||||
git:
|
||||
image: plugins/git:1
|
||||
depth: 50
|
||||
tags: true
|
||||
|
||||
pipeline:
|
||||
build:
|
||||
image: webhippie/golang:edge
|
||||
pull: true
|
||||
@ -15,7 +16,6 @@ pipeline:
|
||||
TAGS: bindata sqlite
|
||||
GOPATH: /srv/app
|
||||
commands:
|
||||
- apk -U add openssh-client
|
||||
- make clean
|
||||
- make generate
|
||||
- make vet
|
||||
@ -34,35 +34,21 @@ pipeline:
|
||||
TAGS: bindata sqlite
|
||||
GOPATH: /srv/app
|
||||
commands:
|
||||
- apk -U add openssh-client
|
||||
- make test
|
||||
when:
|
||||
event: [ tag, pull_request ]
|
||||
|
||||
test-coverage:
|
||||
image: webhippie/golang:edge
|
||||
pull: true
|
||||
environment:
|
||||
TAGS: bindata sqlite
|
||||
GOPATH: /srv/app
|
||||
commands:
|
||||
- apk -U add openssh-client
|
||||
- go get github.com/wadey/gocovmerge
|
||||
- make test-coverage
|
||||
when:
|
||||
event: [ push ]
|
||||
branch: master
|
||||
|
||||
test-sqlite:
|
||||
image: webhippie/golang:edge
|
||||
pull: true
|
||||
environment:
|
||||
TAGS: bindata
|
||||
GOPATH: /srv/app
|
||||
commands:
|
||||
- echo "Needs to be fixed" # make test-sqlite
|
||||
when:
|
||||
event: [ push, tag, pull_request ]
|
||||
# Commented until db locking have been resolved!
|
||||
# test-sqlite:
|
||||
# image: webhippie/golang:edge
|
||||
# pull: true
|
||||
# environment:
|
||||
# TAGS: bindata
|
||||
# GOPATH: /srv/app
|
||||
# commands:
|
||||
# - make test-sqlite
|
||||
# when:
|
||||
# event: [ push, tag, pull_request ]
|
||||
|
||||
test-mysql:
|
||||
image: webhippie/golang:edge
|
||||
@ -97,25 +83,19 @@ pipeline:
|
||||
when:
|
||||
event: [ push, tag ]
|
||||
|
||||
# coverage:
|
||||
# image: plugins/coverage
|
||||
# server: https://coverage.gitea.io
|
||||
# when:
|
||||
# event: [ push ]
|
||||
# branch: master
|
||||
|
||||
docker:
|
||||
image: plugins/docker
|
||||
image: plugins/docker:17.05
|
||||
pull: true
|
||||
secrets: [ docker_username, docker_password ]
|
||||
repo: gitea/gitea
|
||||
tags: [ '${DRONE_TAG##v}' ]
|
||||
when:
|
||||
event: [ tag ]
|
||||
branch: [ refs/tags/* ]
|
||||
|
||||
docker:
|
||||
image: plugins/docker
|
||||
image: plugins/docker:17.05
|
||||
pull: true
|
||||
secrets: [ docker_username, docker_password ]
|
||||
repo: gitea/gitea
|
||||
tags: [ '${DRONE_BRANCH##release/v}' ]
|
||||
when:
|
||||
@ -123,8 +103,9 @@ pipeline:
|
||||
branch: [ release/* ]
|
||||
|
||||
docker:
|
||||
image: plugins/docker
|
||||
image: plugins/docker:17.05
|
||||
pull: true
|
||||
secrets: [ docker_username, docker_password ]
|
||||
repo: gitea/gitea
|
||||
tags: [ 'latest' ]
|
||||
when:
|
||||
@ -132,17 +113,24 @@ pipeline:
|
||||
branch: [ master ]
|
||||
|
||||
release:
|
||||
image: plugins/s3
|
||||
image: plugins/s3:1
|
||||
pull: true
|
||||
secrets: [ aws_access_key_id, aws_secret_access_key ]
|
||||
bucket: releases
|
||||
endpoint: https://storage.gitea.io
|
||||
path_style: true
|
||||
strip_prefix: dist/release/
|
||||
source: dist/release/*
|
||||
target: /gitea/${DRONE_TAG##v}
|
||||
when:
|
||||
event: [ tag ]
|
||||
branch: [ refs/tags/* ]
|
||||
|
||||
release:
|
||||
image: plugins/s3
|
||||
image: plugins/s3:1
|
||||
pull: true
|
||||
secrets: [ aws_access_key_id, aws_secret_access_key ]
|
||||
bucket: releases
|
||||
endpoint: https://storage.gitea.io
|
||||
path_style: true
|
||||
strip_prefix: dist/release/
|
||||
source: dist/release/*
|
||||
@ -152,7 +140,11 @@ pipeline:
|
||||
branch: [ release/* ]
|
||||
|
||||
release:
|
||||
image: plugins/s3
|
||||
image: plugins/s3:1
|
||||
pull: true
|
||||
secrets: [ aws_access_key_id, aws_secret_access_key ]
|
||||
bucket: releases
|
||||
endpoint: https://storage.gitea.io
|
||||
path_style: true
|
||||
strip_prefix: dist/release/
|
||||
source: dist/release/*
|
||||
@ -162,17 +154,18 @@ pipeline:
|
||||
branch: [ master ]
|
||||
|
||||
github:
|
||||
image: plugins/github-release
|
||||
image: plugins/github-release:1
|
||||
pull: true
|
||||
secrets: [ github_token ]
|
||||
files:
|
||||
- dist/release/*
|
||||
when:
|
||||
event: [ tag ]
|
||||
branch: [ refs/tags/* ]
|
||||
|
||||
discord:
|
||||
image: appleboy/drone-discord:0.0.4
|
||||
webhook_id: ${WEBHOOK_ID}
|
||||
webhook_token: ${WEBHOOK_TOKEN}
|
||||
image: appleboy/drone-discord:1.0.0
|
||||
pull: true
|
||||
secrets: [ discord_webhook_id, discord_webhook_token ]
|
||||
when:
|
||||
event: [ push, tag, pull_request ]
|
||||
status: [ changed, failure ]
|
||||
|
File diff suppressed because one or more lines are too long
329
CHANGELOG.md
329
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
7
Makefile
7
Makefile
@ -56,11 +56,8 @@ clean:
|
||||
$(GO) clean -i ./...
|
||||
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) integrations*.test
|
||||
|
||||
required-gofmt-version:
|
||||
@$(GO) version | grep -q '\(1.7\|1.8\)' || { echo "We require go version 1.7 or 1.8 to format code" >&2 && exit 1; }
|
||||
|
||||
.PHONY: fmt
|
||||
fmt: required-gofmt-version
|
||||
fmt:
|
||||
$(GOFMT) -w $(GOFILES)
|
||||
|
||||
.PHONY: vet
|
||||
@ -112,7 +109,7 @@ misspell:
|
||||
misspell -w -i unknwon $(GOFILES)
|
||||
|
||||
.PHONY: fmt-check
|
||||
fmt-check: required-gofmt-version
|
||||
fmt-check:
|
||||
# get all go files and run go fmt on them
|
||||
@diff=$$($(GOFMT) -d $(GOFILES)); \
|
||||
if [ -n "$$diff" ]; then \
|
||||
|
16
cmd/hook.go
16
cmd/hook.go
@ -126,15 +126,13 @@ func runHookPreReceive(c *cli.Context) error {
|
||||
log.GitLogger.Fatal(2, "retrieve protected branches information failed")
|
||||
}
|
||||
|
||||
if protectBranch != nil {
|
||||
if !protectBranch.CanPush {
|
||||
// check and deletion
|
||||
if newCommitID == git.EmptySHA {
|
||||
fail(fmt.Sprintf("branch %s is protected from deletion", branchName), "")
|
||||
} else {
|
||||
fail(fmt.Sprintf("protected branch %s can not be pushed to", branchName), "")
|
||||
//fail(fmt.Sprintf("branch %s is protected from force push", branchName), "")
|
||||
}
|
||||
if protectBranch != nil && protectBranch.IsProtected() {
|
||||
// check and deletion
|
||||
if newCommitID == git.EmptySHA {
|
||||
fail(fmt.Sprintf("branch %s is protected from deletion", branchName), "")
|
||||
} else if !protectBranch.CanPush {
|
||||
fail(fmt.Sprintf("protected branch %s can not be pushed to", branchName), "")
|
||||
//fail(fmt.Sprintf("branch %s is protected from force push", branchName), "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ func TestCreateFileOnProtectedBranch(t *testing.T) {
|
||||
req := NewRequestWithValues(t, "POST", "/user2/repo1/settings/branches?action=protected_branch", map[string]string{
|
||||
"_csrf": csrf,
|
||||
"branchName": "master",
|
||||
"canPush": "true",
|
||||
"canPush": "false",
|
||||
})
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
// Check if master branch has been locked successfully
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr, canPush bool) {
|
||||
func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr, isProtected bool) {
|
||||
reqURL := fmt.Sprintf("/api/internal/branch/%d/%s", repoID, url.QueryEscape(branchName))
|
||||
req := NewRequest(t, "GET", reqURL)
|
||||
t.Log(reqURL)
|
||||
@ -31,14 +31,14 @@ func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr,
|
||||
var branch models.ProtectedBranch
|
||||
t.Log(string(resp.Body))
|
||||
assert.NoError(t, json.Unmarshal(resp.Body, &branch))
|
||||
assert.Equal(t, canPush, branch.CanPush)
|
||||
assert.Equal(t, isProtected, branch.IsProtected())
|
||||
}
|
||||
}
|
||||
|
||||
func TestInternal_GetProtectedBranch(t *testing.T) {
|
||||
prepareTestEnv(t)
|
||||
|
||||
assertProtectedBranch(t, 1, "master", false, true)
|
||||
assertProtectedBranch(t, 1, "dev", false, true)
|
||||
assertProtectedBranch(t, 1, "lunny/dev", false, true)
|
||||
assertProtectedBranch(t, 1, "master", false, false)
|
||||
assertProtectedBranch(t, 1, "dev", false, false)
|
||||
assertProtectedBranch(t, 1, "lunny/dev", false, false)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ RUN_MODE = prod
|
||||
|
||||
[database]
|
||||
DB_TYPE = mysql
|
||||
HOST = 127.0.0.1:3306
|
||||
HOST = mysql:3306
|
||||
NAME = testgitea
|
||||
USER = root
|
||||
PASSWD =
|
||||
|
@ -3,7 +3,7 @@ RUN_MODE = prod
|
||||
|
||||
[database]
|
||||
DB_TYPE = postgres
|
||||
HOST = 127.0.0.1:5432
|
||||
HOST = pgsql:5432
|
||||
NAME = testgitea
|
||||
USER = postgres
|
||||
PASSWD = postgres
|
||||
|
@ -46,7 +46,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch strin
|
||||
func TestPullCreate(t *testing.T) {
|
||||
prepareTestEnv(t)
|
||||
session := loginUser(t, "user1")
|
||||
testRepoFork(t, session)
|
||||
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
|
||||
testEditFile(t, session, "user1", "repo1", "master", "README.md")
|
||||
testPullCreate(t, session, "user1", "repo1", "master")
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ func testPullCleanUp(t *testing.T, session *TestSession, user, repo, pullnum str
|
||||
func TestPullMerge(t *testing.T) {
|
||||
prepareTestEnv(t)
|
||||
session := loginUser(t, "user1")
|
||||
testRepoFork(t, session)
|
||||
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
|
||||
testEditFile(t, session, "user1", "repo1", "master", "README.md")
|
||||
|
||||
resp := testPullCreate(t, session, "user1", "repo1", "master")
|
||||
@ -61,7 +61,7 @@ func TestPullMerge(t *testing.T) {
|
||||
func TestPullCleanUpAfterMerge(t *testing.T) {
|
||||
prepareTestEnv(t)
|
||||
session := loginUser(t, "user1")
|
||||
testRepoFork(t, session)
|
||||
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
|
||||
testEditFileToNewBranch(t, session, "user1", "repo1", "master", "feature/test", "README.md")
|
||||
|
||||
resp := testPullCreate(t, session, "user1", "repo1", "feature/test")
|
||||
|
@ -5,19 +5,24 @@
|
||||
package integrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||
func testRepoFork(t *testing.T, session *TestSession, ownerName, repoName, forkOwnerName, forkRepoName string) *TestResponse {
|
||||
forkOwner := models.AssertExistsAndLoadBean(t, &models.User{Name: forkOwnerName}).(*models.User)
|
||||
|
||||
// Step0: check the existence of the to-fork repo
|
||||
req := NewRequest(t, "GET", "/user1/repo1")
|
||||
req := NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName)
|
||||
resp := session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// Step1: go to the main page of repo
|
||||
req = NewRequest(t, "GET", "/user2/repo1")
|
||||
req = NewRequestf(t, "GET", "/%s/%s", ownerName, repoName)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
// Step2: click the fork button
|
||||
@ -31,15 +36,17 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||
htmlDoc = NewHTMLParser(t, resp.Body)
|
||||
link, exists = htmlDoc.doc.Find("form.ui.form[action^=\"/repo/fork/\"]").Attr("action")
|
||||
assert.True(t, exists, "The template has changed")
|
||||
_, exists = htmlDoc.doc.Find(fmt.Sprintf(".owner.dropdown .item[data-value=\"%d\"]", forkOwner.ID)).Attr("data-value")
|
||||
assert.True(t, exists, fmt.Sprintf("Fork owner '%s' is not present in select box", forkOwnerName))
|
||||
req = NewRequestWithValues(t, "POST", link, map[string]string{
|
||||
"_csrf": htmlDoc.GetCSRF(),
|
||||
"uid": "1",
|
||||
"repo_name": "repo1",
|
||||
"uid": fmt.Sprintf("%d", forkOwner.ID),
|
||||
"repo_name": forkRepoName,
|
||||
})
|
||||
resp = session.MakeRequest(t, req, http.StatusFound)
|
||||
|
||||
// Step4: check the existence of the forked repo
|
||||
req = NewRequest(t, "GET", "/user1/repo1")
|
||||
req = NewRequestf(t, "GET", "/%s/%s", forkOwnerName, forkRepoName)
|
||||
resp = session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
return resp
|
||||
@ -48,5 +55,19 @@ func testRepoFork(t *testing.T, session *TestSession) *TestResponse {
|
||||
func TestRepoFork(t *testing.T) {
|
||||
prepareTestEnv(t)
|
||||
session := loginUser(t, "user1")
|
||||
testRepoFork(t, session)
|
||||
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
|
||||
}
|
||||
|
||||
func TestRepoForkToOrg(t *testing.T) {
|
||||
prepareTestEnv(t)
|
||||
session := loginUser(t, "user2")
|
||||
testRepoFork(t, session, "user2", "repo1", "user3", "repo1")
|
||||
|
||||
// Check that no more forking is allowed as user2 owns repository
|
||||
// and user3 organization that owner user2 is also now has forked this repository
|
||||
req := NewRequest(t, "GET", "/user2/repo1")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
_, exists := htmlDoc.doc.Find("a.ui.button[href^=\"/repo/fork/\"]").Attr("href")
|
||||
assert.False(t, exists, "Forking should not be allowed anymore")
|
||||
}
|
||||
|
@ -3,11 +3,6 @@ RUN_MODE = prod
|
||||
|
||||
[database]
|
||||
DB_TYPE = sqlite3
|
||||
HOST = 127.0.0.1:3306
|
||||
NAME = testgitea
|
||||
USER = gitea
|
||||
PASSWD =
|
||||
SSL_MODE = disable
|
||||
PATH = :memory:
|
||||
|
||||
[repository]
|
||||
|
2
main.go
2
main.go
@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
// Version holds the current Gitea version
|
||||
var Version = "1.1.0+dev"
|
||||
var Version = "1.2.0-dev"
|
||||
|
||||
// Tags holds the build tags used
|
||||
var Tags = ""
|
||||
|
@ -713,7 +713,6 @@ type GetFeedsOptions struct {
|
||||
IncludePrivate bool // include private actions
|
||||
OnlyPerformedBy bool // only actions performed by requested user
|
||||
IncludeDeleted bool // include deleted actions
|
||||
Collaborate bool // Include collaborative repositories
|
||||
}
|
||||
|
||||
// GetFeeds returns actions according to the provided options
|
||||
@ -733,13 +732,7 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
|
||||
cond = cond.And(builder.In("repo_id", repoIDs))
|
||||
}
|
||||
|
||||
var userIDCond builder.Cond = builder.Eq{"user_id": opts.RequestedUser.ID}
|
||||
if opts.Collaborate {
|
||||
userIDCond = userIDCond.Or(builder.Expr(
|
||||
"repo_id IN (SELECT repo_id FROM `access` WHERE access.user_id = ?)",
|
||||
opts.RequestedUser.ID))
|
||||
}
|
||||
cond = cond.And(userIDCond)
|
||||
cond = cond.And(builder.Eq{"user_id": opts.RequestedUser.ID})
|
||||
|
||||
if opts.OnlyPerformedBy {
|
||||
cond = cond.And(builder.Eq{"act_user_id": opts.RequestedUser.ID})
|
||||
|
@ -17,10 +17,10 @@ const (
|
||||
|
||||
// ProtectedBranch struct
|
||||
type ProtectedBranch struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"UNIQUE(s)"`
|
||||
BranchName string `xorm:"UNIQUE(s)"`
|
||||
CanPush bool
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RepoID int64 `xorm:"UNIQUE(s)"`
|
||||
BranchName string `xorm:"UNIQUE(s)"`
|
||||
CanPush bool `xorm:"NOT NULL DEFAULT false"`
|
||||
Created time.Time `xorm:"-"`
|
||||
CreatedUnix int64
|
||||
Updated time.Time `xorm:"-"`
|
||||
@ -38,6 +38,11 @@ func (protectBranch *ProtectedBranch) BeforeUpdate() {
|
||||
protectBranch.UpdatedUnix = time.Now().Unix()
|
||||
}
|
||||
|
||||
// IsProtected returns if the branch is protected
|
||||
func (protectBranch *ProtectedBranch) IsProtected() bool {
|
||||
return protectBranch.ID > 0
|
||||
}
|
||||
|
||||
// GetProtectedBranchByRepoID getting protected branch by repo ID
|
||||
func GetProtectedBranchByRepoID(RepoID int64) ([]*ProtectedBranch, error) {
|
||||
protectedBranches := make([]*ProtectedBranch, 0)
|
||||
|
@ -276,11 +276,7 @@ func DeleteGPGKey(doer *User, id int64) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = sess.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
// CommitVerification represents a commit validation of signature
|
||||
|
@ -572,11 +572,7 @@ func (issue *Issue) ReadBy(userID int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := setNotificationStatusReadIfUnread(x, userID, issue.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return setNotificationStatusReadIfUnread(x, userID, issue.ID)
|
||||
}
|
||||
|
||||
func updateIssueCols(e Engine, issue *Issue, cols ...string) error {
|
||||
|
@ -509,10 +509,7 @@ func SMTPAuth(a smtp.Auth, cfg *SMTPConfig) error {
|
||||
}
|
||||
|
||||
if ok, _ := c.Extension("AUTH"); ok {
|
||||
if err = c.Auth(a); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return c.Auth(a)
|
||||
}
|
||||
return ErrUnsupportedLoginType
|
||||
}
|
||||
|
@ -126,6 +126,12 @@ var migrations = []Migration{
|
||||
NewMigration("unescape user full names", unescapeUserFullNames),
|
||||
// v38 -> v39
|
||||
NewMigration("remove commits and settings unit types", removeCommitsUnitType),
|
||||
// v43 -> v44
|
||||
NewMigration("fix protected branch can push value to false", fixProtectedBranchCanPushValue),
|
||||
// v42 -> v43
|
||||
NewMigration("add tags to releases and sync existing repositories", releaseAddColumnIsTagAndSyncTags),
|
||||
// v44 -> v45
|
||||
NewMigration("remove duplicate unit types", removeDuplicateUnitTypes),
|
||||
}
|
||||
|
||||
// Migrate database to current version
|
||||
|
@ -10,20 +10,15 @@ import (
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
// UserV15 describes the added field for User
|
||||
type UserV15 struct {
|
||||
AllowCreateOrganization bool
|
||||
}
|
||||
|
||||
// TableName will be invoked by XORM to customrize the table name
|
||||
func (*UserV15) TableName() string {
|
||||
return "user"
|
||||
}
|
||||
|
||||
func createAllowCreateOrganizationColumn(x *xorm.Engine) error {
|
||||
if err := x.Sync2(new(UserV15)); err != nil {
|
||||
type User struct {
|
||||
KeepEmailPrivate bool
|
||||
AllowCreateOrganization bool
|
||||
}
|
||||
|
||||
if err := x.Sync2(new(User)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
} else if _, err = x.Where("type=0").Cols("allow_create_organization").Update(&UserV15{AllowCreateOrganization: true}); err != nil {
|
||||
} else if _, err = x.Where("`type` = 0").Cols("allow_create_organization").Update(&User{AllowCreateOrganization: true}); err != nil {
|
||||
return fmt.Errorf("set allow_create_organization: %v", err)
|
||||
}
|
||||
return nil
|
||||
|
@ -13,17 +13,6 @@ import (
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
// RepoUnit describes all units of a repository
|
||||
type RepoUnit struct {
|
||||
ID int64
|
||||
RepoID int64 `xorm:"INDEX(s)"`
|
||||
Type int `xorm:"INDEX(s)"`
|
||||
Index int
|
||||
Config map[string]string `xorm:"JSON"`
|
||||
CreatedUnix int64 `xorm:"INDEX CREATED"`
|
||||
Created time.Time `xorm:"-"`
|
||||
}
|
||||
|
||||
// Enumerate all the unit types
|
||||
const (
|
||||
V16UnitTypeCode = iota + 1 // 1 code
|
||||
@ -37,14 +26,25 @@ const (
|
||||
V16UnitTypeExternalTracker // 9 ExternalTracker
|
||||
)
|
||||
|
||||
// Repo describes a repository
|
||||
type Repo struct {
|
||||
ID int64
|
||||
EnableWiki, EnableExternalWiki, EnableIssues, EnableExternalTracker, EnablePulls bool
|
||||
ExternalWikiURL, ExternalTrackerURL, ExternalTrackerFormat, ExternalTrackerStyle string
|
||||
}
|
||||
|
||||
func addUnitsToTables(x *xorm.Engine) error {
|
||||
// RepoUnit describes all units of a repository
|
||||
type RepoUnit struct {
|
||||
ID int64
|
||||
RepoID int64 `xorm:"INDEX(s)"`
|
||||
Type int `xorm:"INDEX(s)"`
|
||||
Index int
|
||||
Config map[string]interface{} `xorm:"JSON"`
|
||||
CreatedUnix int64 `xorm:"INDEX CREATED"`
|
||||
Created time.Time `xorm:"-"`
|
||||
}
|
||||
|
||||
// Repo describes a repository
|
||||
type Repo struct {
|
||||
ID int64
|
||||
EnableWiki, EnableExternalWiki, EnableIssues, EnableExternalTracker, EnablePulls bool
|
||||
ExternalWikiURL, ExternalTrackerURL, ExternalTrackerFormat, ExternalTrackerStyle string
|
||||
}
|
||||
|
||||
var repos []Repo
|
||||
err := x.Table("repository").Select("*").Find(&repos)
|
||||
if err != nil {
|
||||
@ -95,7 +95,7 @@ func addUnitsToTables(x *xorm.Engine) error {
|
||||
continue
|
||||
}
|
||||
|
||||
var config = make(map[string]string)
|
||||
var config = make(map[string]interface{})
|
||||
switch i {
|
||||
case V16UnitTypeExternalTracker:
|
||||
config["ExternalTrackerURL"] = repo.ExternalTrackerURL
|
||||
@ -119,9 +119,5 @@ func addUnitsToTables(x *xorm.Engine) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := sess.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return sess.Commit()
|
||||
}
|
||||
|
@ -51,8 +51,5 @@ func useNewPublickeyFormat(x *xorm.Engine) error {
|
||||
}
|
||||
|
||||
f.Close()
|
||||
if err = os.Rename(tmpPath, fpath); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return os.Rename(tmpPath, fpath)
|
||||
}
|
||||
|
@ -7,16 +7,19 @@ package migrations
|
||||
import (
|
||||
"html"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func unescapeUserFullNames(x *xorm.Engine) (err error) {
|
||||
type User struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
FullName string
|
||||
}
|
||||
|
||||
const batchSize = 100
|
||||
for start := 0; ; start += batchSize {
|
||||
users := make([]*models.User, 0, batchSize)
|
||||
if err := x.Limit(start, batchSize).Find(users); err != nil {
|
||||
users := make([]*User, 0, batchSize)
|
||||
if err := x.Limit(batchSize, start).Find(&users); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(users) == 0 {
|
||||
@ -24,7 +27,7 @@ func unescapeUserFullNames(x *xorm.Engine) (err error) {
|
||||
}
|
||||
for _, user := range users {
|
||||
user.FullName = html.UnescapeString(user.FullName)
|
||||
if _, err := x.Cols("full_name").Update(user); err != nil {
|
||||
if _, err := x.ID(user.ID).Cols("full_name").Update(user); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -5,12 +5,26 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
|
||||
"github.com/go-xorm/core"
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func removeCommitsUnitType(x *xorm.Engine) (err error) {
|
||||
// RepoUnit describes all units of a repository
|
||||
type RepoUnit struct {
|
||||
ID int64
|
||||
RepoID int64 `xorm:"INDEX(s)"`
|
||||
Type int `xorm:"INDEX(s)"`
|
||||
Index int
|
||||
Config core.Conversion `xorm:"TEXT"`
|
||||
CreatedUnix int64 `xorm:"INDEX CREATED"`
|
||||
Created time.Time `xorm:"-"`
|
||||
}
|
||||
|
||||
// Update team unit types
|
||||
const batchSize = 100
|
||||
for start := 0; ; start += batchSize {
|
||||
@ -33,7 +47,7 @@ func removeCommitsUnitType(x *xorm.Engine) (err error) {
|
||||
}
|
||||
}
|
||||
team.UnitTypes = ut
|
||||
if _, err := x.Id(team.ID).Cols("unit_types").Update(team); err != nil {
|
||||
if _, err := x.ID(team.ID).Cols("unit_types").Update(team); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
57
models/migrations/v42.go
Normal file
57
models/migrations/v42.go
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/git"
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
// ReleaseV39 describes the added field for Release
|
||||
type ReleaseV39 struct {
|
||||
IsTag bool `xorm:"NOT NULL DEFAULT false"`
|
||||
}
|
||||
|
||||
// TableName will be invoked by XORM to customrize the table name
|
||||
func (*ReleaseV39) TableName() string {
|
||||
return "release"
|
||||
}
|
||||
|
||||
func releaseAddColumnIsTagAndSyncTags(x *xorm.Engine) error {
|
||||
if err := x.Sync2(new(ReleaseV39)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
}
|
||||
|
||||
// For the sake of SQLite3, we can't use x.Iterate here.
|
||||
offset := 0
|
||||
pageSize := 20
|
||||
for {
|
||||
repos := make([]*models.Repository, 0, pageSize)
|
||||
if err := x.Table("repository").Asc("id").Limit(pageSize, offset).Find(&repos); err != nil {
|
||||
return fmt.Errorf("select repos [offset: %d]: %v", offset, err)
|
||||
}
|
||||
for _, repo := range repos {
|
||||
gitRepo, err := git.OpenRepository(repo.RepoPath())
|
||||
if err != nil {
|
||||
log.Warn("OpenRepository: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if err = models.SyncReleasesWithTags(repo, gitRepo); err != nil {
|
||||
log.Warn("SyncReleasesWithTags: %v", err)
|
||||
}
|
||||
}
|
||||
if len(repos) < pageSize {
|
||||
break
|
||||
}
|
||||
offset += pageSize
|
||||
}
|
||||
return nil
|
||||
}
|
18
models/migrations/v43.go
Normal file
18
models/migrations/v43.go
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/models"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func fixProtectedBranchCanPushValue(x *xorm.Engine) error {
|
||||
_, err := x.Cols("can_push").Update(&models.ProtectedBranch{
|
||||
CanPush: false,
|
||||
})
|
||||
return err
|
||||
}
|
69
models/migrations/v44.go
Normal file
69
models/migrations/v44.go
Normal file
@ -0,0 +1,69 @@
|
||||
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-xorm/xorm"
|
||||
)
|
||||
|
||||
func removeDuplicateUnitTypes(x *xorm.Engine) error {
|
||||
// RepoUnit describes all units of a repository
|
||||
type RepoUnit struct {
|
||||
RepoID int64
|
||||
Type int
|
||||
}
|
||||
|
||||
// Enumerate all the unit types
|
||||
const (
|
||||
UnitTypeCode = iota + 1 // 1 code
|
||||
UnitTypeIssues // 2 issues
|
||||
UnitTypePullRequests // 3 PRs
|
||||
UnitTypeReleases // 4 Releases
|
||||
UnitTypeWiki // 5 Wiki
|
||||
UnitTypeExternalWiki // 6 ExternalWiki
|
||||
UnitTypeExternalTracker // 7 ExternalTracker
|
||||
)
|
||||
|
||||
var externalIssueRepoUnits []RepoUnit
|
||||
err := x.Where("type = ?", UnitTypeExternalTracker).Find(&externalIssueRepoUnits)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Query repositories: %v", err)
|
||||
}
|
||||
|
||||
var externalWikiRepoUnits []RepoUnit
|
||||
err = x.Where("type = ?", UnitTypeExternalWiki).Find(&externalWikiRepoUnits)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Query repositories: %v", err)
|
||||
}
|
||||
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, repoUnit := range externalIssueRepoUnits {
|
||||
if _, err = sess.Delete(&RepoUnit{
|
||||
RepoID: repoUnit.RepoID,
|
||||
Type: UnitTypeIssues,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Delete repo unit: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, repoUnit := range externalWikiRepoUnits {
|
||||
if _, err = sess.Delete(&RepoUnit{
|
||||
RepoID: repoUnit.RepoID,
|
||||
Type: UnitTypeWiki,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("Delete repo unit: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return sess.Commit()
|
||||
}
|
@ -235,11 +235,7 @@ func DeleteOrganization(org *User) (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
if err = sess.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
func deleteOrg(e *xorm.Session, u *User) error {
|
||||
@ -675,7 +671,7 @@ func (env *accessibleReposEnv) MirrorRepoIDs() ([]int64, error) {
|
||||
Table("repository").
|
||||
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?", true).
|
||||
Where(env.cond()).
|
||||
GroupBy("`repository`.id").
|
||||
GroupBy("`repository`.id, `repository`.updated_unix").
|
||||
OrderBy("updated_unix DESC").
|
||||
Cols("`repository`.id").
|
||||
Find(&repoIDs)
|
||||
|
@ -34,7 +34,8 @@ type Release struct {
|
||||
NumCommitsBehind int64 `xorm:"-"`
|
||||
Note string `xorm:"TEXT"`
|
||||
IsDraft bool `xorm:"NOT NULL DEFAULT false"`
|
||||
IsPrerelease bool
|
||||
IsPrerelease bool `xorm:"NOT NULL DEFAULT false"`
|
||||
IsTag bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
Attachments []*Attachment `xorm:"-"`
|
||||
|
||||
@ -139,17 +140,18 @@ func createTag(gitRepo *git.Repository, rel *Release) error {
|
||||
}
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
commit, err := gitRepo.GetTagCommit(rel.TagName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetTagCommit: %v", err)
|
||||
}
|
||||
rel.LowerTagName = strings.ToLower(rel.TagName)
|
||||
}
|
||||
commit, err := gitRepo.GetTagCommit(rel.TagName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetTagCommit: %v", err)
|
||||
}
|
||||
|
||||
rel.Sha1 = commit.ID.String()
|
||||
rel.NumCommits, err = commit.CommitsCount()
|
||||
if err != nil {
|
||||
return fmt.Errorf("CommitsCount: %v", err)
|
||||
}
|
||||
rel.Sha1 = commit.ID.String()
|
||||
rel.CreatedUnix = commit.Author.When.Unix()
|
||||
rel.NumCommits, err = commit.CommitsCount()
|
||||
if err != nil {
|
||||
return fmt.Errorf("CommitsCount: %v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -236,6 +238,7 @@ func GetReleaseByID(id int64) (*Release, error) {
|
||||
// FindReleasesOptions describes the conditions to Find releases
|
||||
type FindReleasesOptions struct {
|
||||
IncludeDrafts bool
|
||||
IncludeTags bool
|
||||
TagNames []string
|
||||
}
|
||||
|
||||
@ -246,6 +249,9 @@ func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond {
|
||||
if !opts.IncludeDrafts {
|
||||
cond = cond.And(builder.Eq{"is_draft": false})
|
||||
}
|
||||
if !opts.IncludeTags {
|
||||
cond = cond.And(builder.Eq{"is_tag": false})
|
||||
}
|
||||
if len(opts.TagNames) > 0 {
|
||||
cond = cond.And(builder.In("tag_name", opts.TagNames))
|
||||
}
|
||||
@ -361,6 +367,8 @@ func UpdateRelease(gitRepo *git.Repository, rel *Release, attachmentUUIDs []stri
|
||||
if err = createTag(gitRepo, rel); err != nil {
|
||||
return err
|
||||
}
|
||||
rel.LowerTagName = strings.ToLower(rel.TagName)
|
||||
|
||||
_, err = x.Id(rel.ID).AllCols().Update(rel)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -397,11 +405,64 @@ func DeleteReleaseByID(id int64, u *User, delTag bool) error {
|
||||
if err != nil && !strings.Contains(stderr, "not found") {
|
||||
return fmt.Errorf("git tag -d: %v - %s", err, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err = x.Id(rel.ID).Delete(new(Release)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
if _, err = x.Id(rel.ID).Delete(new(Release)); err != nil {
|
||||
return fmt.Errorf("Delete: %v", err)
|
||||
}
|
||||
} else {
|
||||
rel.IsTag = true
|
||||
rel.IsDraft = false
|
||||
rel.IsPrerelease = false
|
||||
rel.Title = ""
|
||||
rel.Note = ""
|
||||
|
||||
if _, err = x.Id(rel.ID).AllCols().Update(rel); err != nil {
|
||||
return fmt.Errorf("Update: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SyncReleasesWithTags synchronizes release table with repository tags
|
||||
func SyncReleasesWithTags(repo *Repository, gitRepo *git.Repository) error {
|
||||
existingRelTags := make(map[string]struct{})
|
||||
opts := FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
|
||||
for page := 1; ; page++ {
|
||||
rels, err := GetReleasesByRepoID(repo.ID, opts, page, 100)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetReleasesByRepoID: %v", err)
|
||||
}
|
||||
if len(rels) == 0 {
|
||||
break
|
||||
}
|
||||
for _, rel := range rels {
|
||||
if rel.IsDraft {
|
||||
continue
|
||||
}
|
||||
commitID, err := gitRepo.GetTagCommitID(rel.TagName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetTagCommitID: %v", err)
|
||||
}
|
||||
if !gitRepo.IsTagExist(rel.TagName) || commitID != rel.Sha1 {
|
||||
if err := pushUpdateDeleteTag(repo, gitRepo, rel.TagName); err != nil {
|
||||
return fmt.Errorf("pushUpdateDeleteTag: %v", err)
|
||||
}
|
||||
} else {
|
||||
existingRelTags[strings.ToLower(rel.TagName)] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
tags, err := gitRepo.GetTags()
|
||||
if err != nil {
|
||||
return fmt.Errorf("GetTags: %v", err)
|
||||
}
|
||||
for _, tagName := range tags {
|
||||
if _, ok := existingRelTags[strings.ToLower(tagName)]; !ok {
|
||||
if err := pushUpdateAddTag(repo, gitRepo, tagName); err != nil {
|
||||
return fmt.Errorf("pushUpdateAddTag: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user