Skip to content

Changes from Gitea 1.4 to DCS 1.4 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: gitea-v1.4-jan-31
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _test

# IntelliJ
.idea
*.iml

# MS VSCode
.vscode
Expand Down
39 changes: 39 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
language: go

go_import_path: code.gitea.io/gitea

go:
- 1.8
- 1.9

env:
TAGS: cert sqlite pam miniwinsvc

install:
- sudo add-apt-repository -y ppa:git-core/ppa
- sudo apt-get update -y
- sudo apt-get install -y git libpam-dev

script:
- make clean
- make vet
# - make lint
- make test
- make test-vendor
- make build TAGS=redis
- make test-mysql TEST_MYSQL_HOST=127.0.0.1:3306

jobs:
include:
- stage: coverage
if: type = push
go: 1.8
install:
- go get github.com/wadey/gocovmerge
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
script:
- make unit-test-coverage
- make integration-test-coverage TEST_MYSQL_HOST=127.0.0.1:3306
- make coverage
- goveralls -coverprofile=coverage.all;
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
[简体中文](https://github.com/go-gitea/gitea/blob/master/README_ZH.md)
# Gitea - Git with a cup of tea - DCS Version

# Gitea - Git with a cup of tea

[![Build Status](https://drone.gitea.io/api/badges/go-gitea/gitea/status.svg)](https://drone.gitea.io/go-gitea/gitea)
[![Join the Discord chat at https://discord.gg/NsatcWJ](https://img.shields.io/discord/322538954119184384.svg)](https://discord.gg/NsatcWJ)
[![Join the Matrix chat at https://matrix.to/#/#gitea:matrix.org](https://img.shields.io/badge/matrix-%23gitea%3Amatrix.org-7bc9a4.svg)](https://matrix.to/#/#gitea:matrix.org)
[![Build Status](https://travis-ci.org/unfoldingWord-dev/gogs.svg?branch=master)](https://travis-ci.org/unfoldingWord-dev/gogs)
[![Join the chat at https://gitter.im/go-gitea/gitea](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/go-gitea/gitea?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![](https://images.microbadger.com/badges/image/gitea/gitea.svg)](https://microbadger.com/images/gitea/gitea "Get your own image badge on microbadger.com")
[![codecov](https://codecov.io/gh/go-gitea/gitea/branch/master/graph/badge.svg)](https://codecov.io/gh/go-gitea/gitea)
[![Go Report Card](https://goreportcard.com/badge/code.gitea.io/gitea)](https://goreportcard.com/report/code.gitea.io/gitea)
[![Coverage Status](https://coveralls.io/repos/github/unfoldingWord-dev/gogs/badge.svg?branch=develop)](https://coveralls.io/github/unfoldingWord-dev/gogs?branch=develop)
[![Go Report Card](https://goreportcard.com/badge/github.com/unfoldingWord-dev)](https://goreportcard.com/report/github.com/unfoldingWord-dev/gogs)
[![GoDoc](https://godoc.org/code.gitea.io/gitea?status.svg)](https://godoc.org/code.gitea.io/gitea)
[![Release](https://github-release-version.herokuapp.com/github/go-gitea/gitea/release.svg?style=flat)](https://github.com/go-gitea/gitea/releases/latest)
[![Help Contribute to Open Source](https://www.codetriage.com/go-gitea/gitea/badges/users.svg)](https://www.codetriage.com/go-gitea/gitea)
Expand Down
4 changes: 3 additions & 1 deletion integrations/explore_repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
func TestExploreRepos(t *testing.T) {
prepareTestEnv(t)

// we (Door43) require authentication to view /explore/... pages
sess := loginUser(t, "user2")
req := NewRequest(t, "GET", "/explore/repos")
MakeRequest(t, req, http.StatusOK)
sess.MakeRequest(t, req, http.StatusOK)
}
2 changes: 2 additions & 0 deletions integrations/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ func TestGit(t *testing.T) {
sshWrapper.Close()
defer os.RemoveAll(sshWrapper.Name())

os.Setenv("GIT_SSH_VARIANT", "ssh")

//Setup clone folder
dstPath, err := ioutil.TempDir("", "repo-tmp-18")
assert.NoError(t, err)
Expand Down
22 changes: 22 additions & 0 deletions integrations/google_analytics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package integrations

import (
"net/http"
"testing"

"code.gitea.io/gitea/modules/setting"

"github.com/stretchr/testify/assert"
)

func TestGoogleAnalytics(t *testing.T) {
// test that the google analytics javascript is included in HTML
prepareTestEnv(t)
setting.Google.GATrackingID = "UA-012345-6"

req := NewRequest(t, "GET", "/")
resp := MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
scripts := htmlDoc.doc.Find("script").Text()
assert.Contains(t, scripts, setting.Google.GATrackingID)
}
25 changes: 19 additions & 6 deletions integrations/links_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ func TestLinksNoLogin(t *testing.T) {
prepareTestEnv(t)

var links = []string{
"/explore/repos",
"/explore/repos?q=test&tab=",
"/explore/users",
"/explore/users?q=test&tab=",
"/explore/organizations",
"/explore/organizations?q=test&tab=",
"/",
"/user/sign_up",
"/user/login",
Expand All @@ -43,6 +37,25 @@ func TestLinksNoLogin(t *testing.T) {
}
}

func TestLinksRequireLogin(t *testing.T) {
prepareTestEnv(t)

var links = []string{
"/explore/repos",
"/explore/repos?q=test&tab=",
"/explore/users",
"/explore/users?q=test&tab=",
"/explore/organizations",
"/explore/organizations?q=test&tab=",
}

for _, link := range links {
req := NewRequest(t, "GET", link)
resp := MakeRequest(t, req, http.StatusFound)
assert.EqualValues(t, "/user/login", test.RedirectURL(resp))
}
}

func TestRedirectsNoLogin(t *testing.T) {
prepareTestEnv(t)

Expand Down
3 changes: 1 addition & 2 deletions integrations/mysql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ SSL_MODE = disable

[indexer]
ISSUE_INDEXER_PATH = integrations/indexers-mysql/issues.bleve
REPO_INDEXER_ENABLED = true
REPO_INDEXER_PATH = integrations/indexers-mysql/repos.bleve
REPO_INDEXER_ENABLED = false

[repository]
ROOT = integrations/gitea-integration-mysql/gitea-repositories
Expand Down
3 changes: 1 addition & 2 deletions integrations/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ SSL_MODE = disable

[indexer]
ISSUE_INDEXER_PATH = integrations/indexers-pgsql/issues.bleve
REPO_INDEXER_ENABLED = true
REPO_INDEXER_PATH = integrations/indexers-pgsql/repos.bleve
REPO_INDEXER_ENABLED = false

[repository]
ROOT = integrations/gitea-integration-pgsql/gitea-repositories
Expand Down
35 changes: 0 additions & 35 deletions integrations/repo_search_test.go

This file was deleted.

3 changes: 1 addition & 2 deletions integrations/sqlite.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ PATH = integrations/gitea-integration-sqlite/gitea.db

[indexer]
ISSUE_INDEXER_PATH = integrations/indexers-sqlite/issues.bleve
REPO_INDEXER_ENABLED = true
REPO_INDEXER_PATH = integrations/indexers-sqlite/repos.bleve
REPO_INDEXER_ENABLED = false

[repository]
ROOT = integrations/gitea-integration-sqlite/gitea-repositories
Expand Down
25 changes: 24 additions & 1 deletion models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRep
return fmt.Errorf("getRepoInitFile[%s]: %v", opts.License, err)
}

if err = ioutil.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0644); err != nil {
if err = ioutil.WriteFile(filepath.Join(tmpDir, "LICENSE.md"), data, 0644); err != nil {
return fmt.Errorf("write LICENSE: %v", err)
}
}
Expand Down Expand Up @@ -1358,6 +1358,29 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
return fmt.Errorf("newRepoAction: %v", err)
}

w := &Webhook{
RepoID: repo.ID,
URL: "https://api.door43.org/client/webhook",
ContentType: ContentTypeJSON,
Secret: "",
HookEvent: &HookEvent{
PushOnly: true,
SendEverything: true,
ChooseEvents: false,
HookEvents: HookEvents{
Create: false,
Push: false,
PullRequest: false,
},
},
IsActive: true,
HookTaskType: GITEA,
OrgID: 0,
}
if err := w.UpdateEvent(); err == nil {
CreateWebhook(w)
}

return nil
}

Expand Down
86 changes: 86 additions & 0 deletions models/repo_scrub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package models

import (
"fmt"

"code.gitea.io/git"
"code.gitea.io/gitea/modules/scrub"

"github.com/Unknwon/com"
)

// ScrubSensitiveDataOptions options for scrubbing sensitive data
type ScrubSensitiveDataOptions struct {
LastCommitID string
CommitMessage string
}

// ScrubSensitiveData removes names and email addresses from the manifest|project|package|status.json files and scrubs previous history.
func (repo *Repository) ScrubSensitiveData(doer *User, opts ScrubSensitiveDataOptions) error {
repoWorkingPool.CheckIn(com.ToStr(repo.ID))
defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))

localPath := repo.LocalCopyPath()

if err := repo.DiscardLocalRepoBranchChanges("master"); err != nil {
return fmt.Errorf("DiscardLocalRepoBranchChanges: %v", err)
} else if err = repo.UpdateLocalCopyBranch("master"); err != nil {
return fmt.Errorf("UpdateLocalCopyBranch: %v", err)
}

if err := scrub.ScrubJsonFiles(localPath); err == nil {
if err := git.AddChanges(localPath, true); err != nil {
return fmt.Errorf("AddChanges: %v", err)
} else if err := git.CommitChanges(localPath, git.CommitChangesOptions{
Committer: doer.NewGitSig(),
Message: opts.CommitMessage,
}); err != nil {
return fmt.Errorf("CommitChanges: %v", err)
} else if err := git.Push(localPath, git.PushOptions{
Remote: "origin",
Branch: "master",
Force: true,
}); err != nil {
return fmt.Errorf("PushForce: %v", err)
}
gitRepo, err := git.OpenRepository(repo.RepoPath())
if err != nil {
return fmt.Errorf("OpenRepository: %v", err)
}
commit, err := gitRepo.GetBranchCommit("master")
if err != nil {
return fmt.Errorf("GetBranchCommit [branch: %s]: %v", "master", err)
}
// Simulate push event.
pushCommits := &PushCommits{
Len: 1,
Commits: []*PushCommit{CommitToPushCommit(commit)},
}
oldCommitID := opts.LastCommitID
if err := CommitRepoAction(CommitRepoActionOptions{
PusherName: doer.Name,
RepoOwnerID: repo.MustOwner().ID,
RepoName: repo.Name,
RefFullName: git.BranchPrefix + "master",
OldCommitID: oldCommitID,
NewCommitID: commit.ID.String(),
Commits: pushCommits,
}); err != nil {
return fmt.Errorf("CommitRepoAction: %v", err)
}
} else {
return err
}

if err := repo.DiscardLocalRepoBranchChanges("master"); err != nil {
return fmt.Errorf("DiscardLocalRepoBranchChanges: %v", err)
} else if err = repo.UpdateLocalCopyBranch("master"); err != nil {
return fmt.Errorf("UpdateLocalCopyBranch: %v", err)
}

if err := scrub.ScrubCommitNameAndEmail(localPath, "Door43", "[email protected]"); err != nil {
return err
}

return nil
}
15 changes: 12 additions & 3 deletions models/unit_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package models

import (
"fmt"
"io/ioutil"
"net/url"
"os"
"path/filepath"
"testing"
Expand All @@ -17,7 +19,6 @@ import (
"github.com/go-xorm/xorm"
"github.com/stretchr/testify/assert"
"gopkg.in/testfixtures.v2"
"net/url"
)

// NonexistentID an ID that will never exist
Expand All @@ -41,8 +42,16 @@ func MainTest(m *testing.M, pathToGiteaRoot string) {
setting.RunUser = "runuser"
setting.SSH.Port = 3000
setting.SSH.Domain = "try.gitea.io"
setting.RepoRootPath = filepath.Join(os.TempDir(), "repos")
setting.AppDataPath = filepath.Join(os.TempDir(), "appdata")
setting.RepoRootPath, err = ioutil.TempDir(os.TempDir(), "repos")
if err != nil {
fmt.Fprintf(os.Stderr, "TempDir: %v\n", err)
os.Exit(1)
}
setting.AppDataPath, err = ioutil.TempDir(os.TempDir(), "appdata")
if err != nil {
fmt.Fprintf(os.Stderr, "TempDir: %v\n", err)
os.Exit(1)
}
setting.AppWorkPath = pathToGiteaRoot
setting.StaticRootPath = pathToGiteaRoot
setting.GravatarSourceURL, err = url.Parse("https://secure.gravatar.com/avatar/")
Expand Down
2 changes: 1 addition & 1 deletion modules/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{}
// NotFound displays a 404 (Not Found) page and prints the given error, if any.
func (ctx *Context) NotFound(title string, err error) {
if err != nil {
log.Error(4, "%s: %v", title, err)
log.Error(4, "(%s %s) %s: %v", ctx.Req.Method, ctx.Req.URL.String(), title, err)
if macaron.Env != macaron.PROD {
ctx.Data["ErrorMsg"] = err
}
Expand Down
Loading