Skip to content

Commit

Permalink
Merge remote-tracking branch 'gitea/master' into develop
Browse files Browse the repository at this point in the history
Conflicts:
	templates/base/footer.tmpl
  • Loading branch information
Richard Mahn committed May 9, 2017
2 parents d830c55 + ab79069 commit 9cab194
Show file tree
Hide file tree
Showing 90 changed files with 13,073 additions and 212 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.4
FROM alpine:3.5
MAINTAINER Thomas Boerger <[email protected]>

EXPOSE 22 3000
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM aarch64/alpine:3.5
FROM multiarch/alpine:aarch64-v3.5

EXPOSE 22 3000

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.rpi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM hypriot/rpi-alpine-scratch:v3.4
FROM multiarch/alpine:armhf-v3.5
MAINTAINER Thomas Boerger <[email protected]>

EXPOSE 22 3000
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ release-windows:
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/karalabe/xgo; \
fi
xgo -dest $(DIST)/binaries -tags '$(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
ifeq ($(CI),drone)
mv /build/* $(DIST)/binaries
endif
Expand All @@ -150,7 +150,7 @@ release-linux:
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/karalabe/xgo; \
fi
xgo -dest $(DIST)/binaries -tags '$(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/*' -out gitea-$(VERSION) .
ifeq ($(CI),drone)
mv /build/* $(DIST)/binaries
endif
Expand All @@ -160,7 +160,7 @@ release-darwin:
@hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
go get -u github.com/karalabe/xgo; \
fi
xgo -dest $(DIST)/binaries -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
xgo -dest $(DIST)/binaries -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
ifeq ($(CI),drone)
mv /build/* $(DIST)/binaries
endif
Expand Down
2 changes: 0 additions & 2 deletions cmd/serv.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ func runServ(c *cli.Context) error {
fail("Internal error", "Failed to get repository owner (%s): %v", username, err)
}

os.Setenv(models.EnvRepoUserSalt, repoUser.Salt)

repo, err := models.GetRepositoryByName(repoUser.ID, reponame)
if err != nil {
if models.IsErrRepoNotExist(err) {
Expand Down
3 changes: 3 additions & 0 deletions conf/app.ini
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ ENABLE_CAPTCHA = true
; Default value for KeepEmailPrivate
; New user will get the value of this setting copied into their profile
DEFAULT_KEEP_EMAIL_PRIVATE = false
; Default value for AllowCreateOrganization
; New user will have rights set to create organizations depending on this setting
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
; Default value for the domain part of the user's email address in the git log
; if he has set KeepEmailPrivate true. The user's email replaced with a
; concatenation of the user name in lower case, "@" and NO_REPLY_ADDRESS.
Expand Down
90 changes: 7 additions & 83 deletions integrations/html_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,104 +7,28 @@ package integrations
import (
"bytes"

"golang.org/x/net/html"
"github.com/PuerkitoBio/goquery"
)

type HtmlDoc struct {
doc *html.Node
body *html.Node
doc *goquery.Document
}

func NewHtmlParser(content []byte) (*HtmlDoc, error) {
doc, err := html.Parse(bytes.NewReader(content))
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
if err != nil {
return nil, err
}

return &HtmlDoc{doc: doc}, nil
}

func (doc *HtmlDoc) GetBody() *html.Node {
if doc.body == nil {
var b *html.Node
var f func(*html.Node)
f = func(n *html.Node) {
if n.Type == html.ElementNode && n.Data == "body" {
b = n
return
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
f(c)
}
}
f(doc.doc)
if b != nil {
doc.body = b
} else {
doc.body = doc.doc
}
}
return doc.body
}

func (doc *HtmlDoc) GetAttribute(n *html.Node, key string) (string, bool) {
for _, attr := range n.Attr {
if attr.Key == key {
return attr.Val, true
}
}
return "", false
}

func (doc *HtmlDoc) checkAttr(n *html.Node, attr, val string) bool {
if n.Type == html.ElementNode {
s, ok := doc.GetAttribute(n, attr)
if ok && s == val {
return true
}
}
return false
}

func (doc *HtmlDoc) traverse(n *html.Node, attr, val string) *html.Node {
if doc.checkAttr(n, attr, val) {
return n
}

for c := n.FirstChild; c != nil; c = c.NextSibling {
result := doc.traverse(c, attr, val)
if result != nil {
return result
}
}

return nil
}

func (doc *HtmlDoc) GetElementById(id string) *html.Node {
return doc.traverse(doc.GetBody(), "id", id)
}

func (doc *HtmlDoc) GetInputValueById(id string) string {
inp := doc.GetElementById(id)
if inp == nil {
return ""
}

val, _ := doc.GetAttribute(inp, "value")
return val
}

func (doc *HtmlDoc) GetElementByName(name string) *html.Node {
return doc.traverse(doc.GetBody(), "name", name)
text, _ := doc.doc.Find("#" + id).Attr("value")
return text
}

func (doc *HtmlDoc) GetInputValueByName(name string) string {
inp := doc.GetElementByName(name)
if inp == nil {
return ""
}

val, _ := doc.GetAttribute(inp, "value")
return val
text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
return text
}
11 changes: 6 additions & 5 deletions integrations/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ func initIntegrationTest() {
if err != nil {
log.Fatalf("db.Query: %v", err)
}
if rows.Next() {
break // database already exists
}
if _, err = db.Exec("CREATE DATABASE testgitea"); err != nil {
log.Fatalf("db.Exec: %v", err)
defer rows.Close()

if !rows.Next() {
if _, err = db.Exec("CREATE DATABASE testgitea"); err != nil {
log.Fatalf("db.Exec: %v", err)
}
}
}
routers.GlobalInit()
Expand Down
45 changes: 45 additions & 0 deletions integrations/internal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 integrations

import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"testing"

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

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

func assertProtectedBranch(t *testing.T, repoID int64, branchName string, isErr, canPush bool) {
reqURL := fmt.Sprintf("/api/internal/branch/%d/%s", repoID, url.QueryEscape(branchName))
req, err := http.NewRequest("GET", reqURL, nil)
t.Log(reqURL)
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", setting.InternalToken))

assert.NoError(t, err)
resp := MakeRequest(req)
if isErr {
assert.EqualValues(t, 500, resp.HeaderCode)
} else {
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
var branch models.ProtectedBranch
t.Log(string(resp.Body))
assert.NoError(t, json.Unmarshal(resp.Body, &branch))
assert.Equal(t, canPush, branch.CanPush)
}
}

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)
}
1 change: 1 addition & 0 deletions integrations/mysql.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DISABLE_REGISTRATION = false
ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
NO_REPLY_ADDRESS = noreply.example.org

[picture]
Expand Down
1 change: 1 addition & 0 deletions integrations/pgsql.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DISABLE_REGISTRATION = false
ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
NO_REPLY_ADDRESS = noreply.example.org

[picture]
Expand Down
94 changes: 94 additions & 0 deletions integrations/repo_commits_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// 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 integrations

import (
"bytes"
"net/http"
"path"
"testing"

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

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

session := loginUser(t, "user2", "password")

// Request repository commits page
req, err := http.NewRequest("GET", "/user2/repo1/commits/master", nil)
assert.NoError(t, err)
resp := session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)

doc, err := NewHtmlParser(resp.Body)
assert.NoError(t, err)
commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
assert.True(t, exists)
assert.NotEmpty(t, commitURL)
}

func doTestRepoCommitWithStatus(t *testing.T, state string, classes ...string) {
prepareTestEnv(t)

session := loginUser(t, "user2", "password")

// Request repository commits page
req, err := http.NewRequest("GET", "/user2/repo1/commits/master", nil)
assert.NoError(t, err)
resp := session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)

doc, err := NewHtmlParser(resp.Body)
assert.NoError(t, err)
// Get first commit URL
commitURL, exists := doc.doc.Find("#commits-table tbody tr td.sha a").Attr("href")
assert.True(t, exists)
assert.NotEmpty(t, commitURL)

// Call API to add status for commit
req, err = http.NewRequest("POST", "/api/v1/repos/user2/repo1/statuses/"+path.Base(commitURL),
bytes.NewBufferString("{\"state\":\""+state+"\", \"target_url\": \"http://test.ci/\", \"description\": \"\", \"context\": \"testci\"}"))

assert.NoError(t, err)
req.Header.Add("Content-Type", "application/json")
resp = session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusCreated, resp.HeaderCode)

req, err = http.NewRequest("GET", "/user2/repo1/commits/master", nil)
assert.NoError(t, err)
resp = session.MakeRequest(t, req)
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)

doc, err = NewHtmlParser(resp.Body)
assert.NoError(t, err)
// Check if commit status is displayed in message column
sel := doc.doc.Find("#commits-table tbody tr td.message i.commit-status")
assert.Equal(t, sel.Length(), 1)
for _, class := range classes {
assert.True(t, sel.HasClass(class))
}
}

func TestRepoCommitsWithStatusPending(t *testing.T) {
doTestRepoCommitWithStatus(t, "pending", "circle", "yellow")
}

func TestRepoCommitsWithStatusSuccess(t *testing.T) {
doTestRepoCommitWithStatus(t, "success", "check", "green")
}

func TestRepoCommitsWithStatusError(t *testing.T) {
doTestRepoCommitWithStatus(t, "error", "warning", "red")
}

func TestRepoCommitsWithStatusFailure(t *testing.T) {
doTestRepoCommitWithStatus(t, "failure", "remove", "red")
}

func TestRepoCommitsWithStatusWarning(t *testing.T) {
doTestRepoCommitWithStatus(t, "warning", "warning", "sign", "yellow")
}
1 change: 1 addition & 0 deletions integrations/sqlite.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ DISABLE_REGISTRATION = false
ENABLE_CAPTCHA = false
REQUIRE_SIGNIN_VIEW = false
DEFAULT_KEEP_EMAIL_PRIVATE = false
DEFAULT_ALLOW_CREATE_ORGANIZATION = true
NO_REPLY_ADDRESS = noreply.example.org

[picture]
Expand Down
Loading

0 comments on commit 9cab194

Please sign in to comment.