Compare commits

..

33 Commits

Author SHA1 Message Date
Lauris BH
46bb1cf026 Changelog for v1.2.1 (#2716) 2017-10-16 16:27:22 +02:00
Lauris BH
13013e90f3 Fix PR, milestone and label functionality if issue unit is disabled (#2710) (#2714)
* Fix PR, milestone and label functionality if issue unit is disabled or not assigned to user

* Fix multi-actions in PR page

* Change error message

* Fix comment update and delete functionality in PR
2017-10-16 16:59:01 +03:00
785ba171f4 Fix plain readme didn't render correctly on repo home page (#2705) (#2712)
* fix plain readme didn't render correctly on repo home page

* fix missing render

* remove unused template variables
2017-10-16 03:30:11 -05:00
Lauris BH
fb80265b52 Fix so that user can still fork his own repository to owned organizations (#2699) (#2707)
* Fix so that user can still fork his own repository to his organizations

* Fix to only use owned organizations

* Add integration test for forking own repository to owned organization
2017-10-15 19:40:33 +03:00
David Schneiderbauer
6fae585d28 fix .netrc authentication (#2700) (#2708)
* provide both possible authentication solutions

Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
2017-10-15 18:50:28 +03:00
670562a9c5 Fix slice out of bounds error in mailer (#2479) (#2696) 2017-10-13 22:59:03 +03:00
ed07d8a308 Add release notes for v1.2.0 (#2683)
* add release notes for v1.2.0

* improve release notes for v1.2.0
2017-10-12 14:13:12 +08:00
David Schneiderbauer
74399f333f Backport of migration fixes (#2604) (#2677)
* Rewrite migrations to not depend on future code changes (#2604)

* v38 migration used an outdated version of RepoUnit model (#2602)

* change repoUnit model in migration

* fix v16 migration repo_unit table

* fix lint error

* move type definition inside function

* Fix migration from Gogs

* Refactor code

* add error check

* Additiomal fixes for migrations

* Add back nil check

* replace deprecated .Id with .ID

Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>

* change string map to interface map

Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
2017-10-09 16:08:22 +03:00
David Schneiderbauer
d1cec5ecfa fix panic on gogs webhook creation (#2675) (#2676)
* fix panic on gogs webhook creation

Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>

* fix panic in gogs webhook edit

Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
2017-10-09 08:58:49 +08:00
Lauris BH
73ad7d2ef3 Fixes 500 error on dashboard when using MSSQL (#2504) (#2662)
MSSQL rejects the query:
  SELECT "repository"."id" FROM "repository"
  INNER JOIN "team_repo" ON "team_repo".repo_id="repository".id AND
  "repository".is_mirror=1
  WHERE (
    ("repository".owner_id=2 AND "repository".is_private=0)
        OR team_repo.team_id IN (1)
        )
        GROUP BY "repository".id ORDER BY updated_unix DESC

when the order by term (updated_unix) is not included in the group by
term.
2017-10-05 21:08:40 +03:00
Lauris BH
5b36379172 Fix go get response if only app URL is custom in configuration (#2634) (#2640)
* Fix go get response if only app URL is custom in configuration

* Rewrite to update Domain setting to match AppURL
2017-10-03 06:29:19 +03:00
David Schneiderbauer
e38e502e20 Fix deletion of unprotected branches (#2630)
* fix deletion of unprotected branches

* fmt fix

* changed internal protected branch api

* fix lint error

Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
2017-10-02 23:23:41 +03:00
David Schneiderbauer
3cc5b11b0d Backport of 2611 / Fix doubled issue tab introduced in migration v16 (#2622)
Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
2017-10-01 09:18:49 +03:00
David Schneiderbauer
4c9bf91a2c v38 migration used an outdated version of RepoUnit model (#2602)
* change repoUnit model in migration

* fix v16 migration repo_unit table

* fix lint error

* move type definition inside function

Signed-off-by: David Schneiderbauer <dschneiderbauer@gmail.com>
2017-09-25 19:53:55 +03:00
03ff7687e0 fix go get subpackage bug (#2584) (#2589)
* fix go get subpackage bug

* merge the duplicated funtions
2017-09-23 16:58:17 +03:00
f646154ead add secrets for github release (#2588) 2017-09-23 20:17:51 +08:00
Lauris BH
a6d2f47a2b Add changelog for v1.2.0-rc4 (#2587) 2017-09-23 13:50:35 +03:00
Lauris BH
1837194882 Backport changes for latest drone (#2586) 2017-09-23 17:33:52 +08:00
Jonas Franz
9ca26432f6 Removing .drone.yml.sig (#2579)
Signed-off-by: Jonas Franz <info@jonasfranz.software>
2017-09-23 09:17:32 +08:00
Lauris BH
67595c0d0b Fix drone for tags (#2573) (#2576) 2017-09-22 20:00:52 +03:00
Lauris BH
6d03cf831e Add changelog for v1.2.0-rc3 (#2563) 2017-09-21 10:00:37 +03:00
Lauris BH
e232c49b10 Sync releases table with tags on push and for mirrors (#2459) (#2554)
* Sync releases table with tags on push and for mirrors

* Code style fixes

* Fix api to return only releases

* Optimize release creation and update
Minimize posibility of race conditions

* Fix release lower tag name updating

* handle tag reference update by addionally comparing commit id
2017-09-21 01:08:22 +03:00
Lauris BH
25e71ad41e Fix adding branch as protected to not allow pushing to it (#2556)
* Fix adding branch as protected to not allow pushing to it

* Fix can_push value to false in protected_branch (#2560)

* Fix integration test
2017-09-20 20:14:09 +03:00
Ethan Koenig
f014e42a06 Backport: Fix lint, fmt and integration testing errors (#2553)
* Fix lint errors

* Fix fmt errors (#2544)

* Hotfix for integration testing (#2473)

* Hotfix for integration testing
2017-09-20 19:30:20 +03:00
Lauris BH
d14a724b53 Remove go version check for make fmt (#2558) (#2561) 2017-09-20 20:42:08 +08:00
Jonas Franz
91788e0200 Restricting access to fork functioanlity to users with Code access (#2542)
Signed-off-by: Jonas Franz <info@jonasfranz.software>
2017-09-19 01:12:29 +02:00
Lauris BH
fc0c6f48c7 Add changelog for release v1.2.0-rc2 (#2469) 2017-09-06 14:05:35 +03:00
Lauris BH
002fa73460 Fix migration from pre-v15 to 1.2.0 (#2460) (#2465) 2017-09-05 21:03:30 +08:00
2fdc649202 bug fixed 2017-09-04 14:28:50 +08:00
Lauris BH
0c910afe11 Fix releases to be counted from database not tags (#2389) (#2424) 2017-08-30 09:31:32 +08:00
1cbe502cc2 fix duplicated feed (#2370) 2017-08-28 19:16:25 +02:00
Sandro Santilli
f916aa0fe3 Set version to 1.2.0-dev
1.2.0-dev is less than 1.2.0, according to semver
2017-08-27 23:02:48 +02:00
04728b5b91 fix wrong changelog title (#2395) 2017-08-25 22:34:50 +08:00
61 changed files with 1079 additions and 595 deletions

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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 \

View File

@ -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), "")
}
}
}

View File

@ -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

View File

@ -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)
}

View File

@ -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 =

View File

@ -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

View File

@ -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")
}

View File

@ -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")

View File

@ -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")
}

View File

@ -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]

View File

@ -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 = ""

View File

@ -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})

View File

@ -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)

View File

@ -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

View File

@ -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 {

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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()
}

View File

@ -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)
}

View File

@ -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
}
}

View File

@ -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
View 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
View 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
View 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()
}

View File

@ -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)

View File

@ -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