Skip to content

Commit

Permalink
Merge branch 'master' into letsencrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
daviian authored Aug 21, 2018
2 parents 9042772 + 6c1a31f commit 3d84f1f
Show file tree
Hide file tree
Showing 22 changed files with 332 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

## 目标

Gitea的首要目标是创建一个极易安装,运行非常快速,安装和使用体验良好的自建 Git 服务。我们采用Go作为后端语言,这使我们只要生成一个可执行程序即可。并且他还支持跨平台,支持 Linux, macOS 和 Windows 以及各种架构,除了x86,amd64,还包括 ARM 和 PowerPC。
Gitea 的首要目标是创建一个极易安装,运行非常快速,安装和使用体验良好的自建 Git 服务。我们采用 Go 作为后端语言,这使我们只要生成一个可执行程序即可。并且他还支持跨平台,支持 Linux, macOS 和 Windows 以及各种架构,除了 x86,amd64,还包括 ARM 和 PowerPC。

如果您想试用一下,请访问 [在线Demo](https://try.gitea.io/)

Expand Down
1 change: 0 additions & 1 deletion docker/etc/ssh/sshd_config
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ AllowUsers git

Banner none
Subsystem sftp /usr/lib/ssh/sftp-server
UsePrivilegeSeparation no
2 changes: 1 addition & 1 deletion models/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {

// Insert the assignees
for _, assigneeID := range opts.AssigneeIDs {
err = opts.Issue.changeAssignee(e, doer, assigneeID)
err = opts.Issue.changeAssignee(e, doer, assigneeID, true)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions models/issue_assignees.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
return err
}

if err := issue.changeAssignee(sess, doer, assigneeID); err != nil {
if err := issue.changeAssignee(sess, doer, assigneeID, false); err != nil {
return err
}

return sess.Commit()
}

func (issue *Issue) changeAssignee(sess *xorm.Session, doer *User, assigneeID int64) (err error) {
func (issue *Issue) changeAssignee(sess *xorm.Session, doer *User, assigneeID int64, isCreate bool) (err error) {

// Update the assignee
removed, err := updateIssueAssignee(sess, issue, assigneeID)
Expand All @@ -161,6 +161,10 @@ func (issue *Issue) changeAssignee(sess *xorm.Session, doer *User, assigneeID in

mode, _ := accessLevel(sess, doer.ID, issue.Repo)
if issue.IsPull {
// if pull request is in the middle of creation - don't call webhook
if isCreate {
return nil
}
if err = issue.loadPullRequest(sess); err != nil {
return fmt.Errorf("loadPullRequest: %v", err)
}
Expand Down
11 changes: 3 additions & 8 deletions modules/validation/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package validation

import (
"fmt"
"net/url"
"regexp"
"strings"

Expand Down Expand Up @@ -70,13 +69,9 @@ func addValidURLBindingRule() {
},
IsValid: func(errs binding.Errors, name string, val interface{}) (bool, binding.Errors) {
str := fmt.Sprintf("%v", val)
if len(str) != 0 {
if u, err := url.ParseRequestURI(str); err != nil ||
(u.Scheme != "http" && u.Scheme != "https") ||
!validPort(portOnly(u.Host)) {
errs.Add([]string{name}, binding.ERR_URL, "Url")
return false, errs
}
if len(str) != 0 && !IsValidURL(str) {
errs.Add([]string{name}, binding.ERR_URL, "Url")
return false, errs
}

return true, errs
Expand Down
77 changes: 77 additions & 0 deletions modules/validation/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2018 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 validation

import (
"net"
"net/url"
"strings"

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

var loopbackIPBlocks []*net.IPNet

func init() {
for _, cidr := range []string{
"127.0.0.0/8", // IPv4 loopback
"::1/128", // IPv6 loopback
} {
if _, block, err := net.ParseCIDR(cidr); err == nil {
loopbackIPBlocks = append(loopbackIPBlocks, block)
}
}
}

func isLoopbackIP(ip string) bool {
pip := net.ParseIP(ip)
if pip == nil {
return false
}
for _, block := range loopbackIPBlocks {
if block.Contains(pip) {
return true
}
}
return false
}

// IsValidURL checks if URL is valid
func IsValidURL(uri string) bool {
if u, err := url.ParseRequestURI(uri); err != nil ||
(u.Scheme != "http" && u.Scheme != "https") ||
!validPort(portOnly(u.Host)) {
return false
}

return true
}

// IsAPIURL checks if URL is current Gitea instance API URL
func IsAPIURL(uri string) bool {
return strings.HasPrefix(strings.ToLower(uri), strings.ToLower(setting.AppURL+"api"))
}

// IsValidExternalURL checks if URL is valid external URL
func IsValidExternalURL(uri string) bool {
if !IsValidURL(uri) || IsAPIURL(uri) {
return false
}

u, err := url.ParseRequestURI(uri)
if err != nil {
return false
}

// Currently check only if not loopback IP is provided to keep compatibility
if isLoopbackIP(u.Hostname()) || strings.ToLower(u.Hostname()) == "localhost" {
return false
}

// TODO: Later it should be added to allow local network IP addreses
// only if allowed by special setting

return true
}
90 changes: 90 additions & 0 deletions modules/validation/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2018 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 validation

import (
"testing"

"github.com/stretchr/testify/assert"

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

func Test_IsValidURL(t *testing.T) {
cases := []struct {
description string
url string
valid bool
}{
{
description: "Empty URL",
url: "",
valid: false,
},
{
description: "Loobpack IPv4 URL",
url: "http://127.0.1.1:5678/",
valid: true,
},
{
description: "Loobpack IPv6 URL",
url: "https://[::1]/",
valid: true,
},
{
description: "Missing semicolon after schema",
url: "http//meh/",
valid: false,
},
}

for _, testCase := range cases {
t.Run(testCase.description, func(t *testing.T) {
assert.Equal(t, testCase.valid, IsValidURL(testCase.url))
})
}
}

func Test_IsValidExternalURL(t *testing.T) {
setting.AppURL = "https://try.gitea.io/"

cases := []struct {
description string
url string
valid bool
}{
{
description: "Current instance URL",
url: "https://try.gitea.io/test",
valid: true,
},
{
description: "Loobpack IPv4 URL",
url: "http://127.0.1.1:5678/",
valid: false,
},
{
description: "Current instance API URL",
url: "https://try.gitea.io/api/v1/user/follow",
valid: false,
},
{
description: "Local network URL",
url: "http://192.168.1.2/api/v1/user/follow",
valid: true,
},
{
description: "Local URL",
url: "http://LOCALHOST:1234/whatever",
valid: false,
},
}

for _, testCase := range cases {
t.Run(testCase.description, func(t *testing.T) {
assert.Equal(t, testCase.valid, IsValidExternalURL(testCase.url))
})
}
}
2 changes: 0 additions & 2 deletions options/locale/locale_de-DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,6 @@ settings.event_push=Push
settings.event_push_desc=Git push in ein Repository.
settings.event_repository=Repository
settings.event_repository_desc=Repository erstellt oder gelöscht.
settings.active=Event-Details mitversenden
settings.active_helper=Informationen über das auslösende Event mitversenden.
settings.add_hook_success=Webhook wurde hinzugefügt.
settings.update_webhook=Webhook aktualisieren
settings.update_hook_success=Webhook wurde aktualisiert.
Expand Down
8 changes: 6 additions & 2 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ issues.dependency.add_error_dep_not_exist = Dependency does not exist.
issues.dependency.add_error_dep_exists = Dependency already exists.
issues.dependency.add_error_cannot_create_circular = You cannot create a dependency with two issues blocking each other.
issues.dependency.add_error_dep_not_same_repo = Both issues must be in the same repository.
issues.review.self.approval = You cannot approve your own pull request.
issues.review.self.rejection = You cannot request changes on your own pull request.
issues.review.approve = "approved these changes %s"
issues.review.comment = "reviewed %s"
issues.review.content.empty = You need to leave a comment indicating the requested change(s).
Expand Down Expand Up @@ -987,6 +989,7 @@ settings.external_tracker_url = External Issue Tracker URL
settings.external_tracker_url_error = The external issue tracker URL is not a valid URL.
settings.external_tracker_url_desc = Visitors are redirected to the external issue tracker URL when clicking on the issues tab.
settings.tracker_url_format = External Issue Tracker URL Format
settings.tracker_url_format_error = The external issue tracker URL format is not a valid URL.
settings.tracker_issue_style = External Issue Tracker Number Format
settings.tracker_issue_style.numeric = Numeric
settings.tracker_issue_style.alphanumeric = Alphanumeric
Expand Down Expand Up @@ -1088,8 +1091,8 @@ settings.event_push = Push
settings.event_push_desc = Git push to a repository.
settings.event_repository = Repository
settings.event_repository_desc = Repository created or deleted.
settings.active = Include Event Details
settings.active_helper = Add information about the triggering event to requests.
settings.active = Active
settings.active_helper = Information about triggered events will be sent to this webhook URL.
settings.add_hook_success = The webhook has been added.
settings.update_webhook = Update Webhook
settings.update_hook_success = The webhook has been updated.
Expand Down Expand Up @@ -1311,6 +1314,7 @@ teams.search_repo_placeholder = Search repository…
teams.add_team_repository = Add Team Repository
teams.remove_repo = Remove
teams.add_nonexistent_repo = "The repository you're trying to add does not exist; please create it first."
teams.add_duplicate_users = User is already a team member.

[admin]
dashboard = Dashboard
Expand Down
2 changes: 0 additions & 2 deletions options/locale/locale_fr-FR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1054,8 +1054,6 @@ settings.event_push=Pousser
settings.event_push_desc=Git push vers un dépôt.
settings.event_repository=Dépôt
settings.event_repository_desc=Dépôt créé ou supprimé.
settings.active=Inclure les détails de l'événement
settings.active_helper=Ajouter des informations sur l’événement déclencheur aux requêtes.
settings.add_hook_success=Nouveau Webhook ajouté.
settings.update_webhook=Mettre à jour le Webhook
settings.update_hook_success=Webhook mis à jour.
Expand Down
2 changes: 0 additions & 2 deletions options/locale/locale_it-IT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,6 @@ settings.event_push=Push
settings.event_push_desc=Git push in un repository.
settings.event_repository=Repository
settings.event_repository_desc=Repository creato o eliminato.
settings.active=Includi dettagli evento
settings.active_helper=Aggiunge alle richieste informazioni riguardo la causa.
settings.add_hook_success=Il webhook è stato aggiunto.
settings.update_webhook=Aggiorna Webhook
settings.update_hook_success=Il webhook è stato aggiornato.
Expand Down
10 changes: 8 additions & 2 deletions options/locale/locale_lv-LV.ini
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ settings.external_tracker_url=Ārējā problēmu reģistra URL
settings.external_tracker_url_error=Nekorekts ārējā problēmu sekotāja URL.
settings.external_tracker_url_desc=Apmeklētāji tiks novirzīti uz ārējā problēmu sekotāja adresi, kad uzklikšķinās uz cilnes.
settings.tracker_url_format=Ārējā problēmu sekotāja adreses formāts
settings.tracker_url_format_error=Ārējā problēmu sekotāja URL formāts nav korekts URL.
settings.tracker_issue_style=Ārējā problēmu sekotāja numura formāts
settings.tracker_issue_style.numeric=Cipari
settings.tracker_issue_style.alphanumeric=Burti un cipari
Expand Down Expand Up @@ -1088,8 +1089,8 @@ settings.event_push=Izmaiņu nosūtīšana
settings.event_push_desc=Git izmaiņu nosūtīšana uz repozitoriju.
settings.event_repository=Repozitorijs
settings.event_repository_desc=Repozitorijs izveidots vai dzēsts.
settings.active=Iekļaut notikuma detaļas
settings.active_helper=Pievienot pieprasījumam informāciju par notikuma izcelsmi.
settings.active=Aktīvs
settings.active_helper=Informācija par notikumiem tiks nosūtīta uz šo tīmekļa āķa URL.
settings.add_hook_success=Tīmekļa āķis tika pievienots.
settings.update_webhook=Mainīt tīmekļa āķi
settings.update_hook_success=Tīmekļa āķis tika atjaunots.
Expand Down Expand Up @@ -1152,6 +1153,11 @@ diff.data_not_available=Satura salīdzināšana nav pieejama
diff.show_diff_stats=Rādīt salīdzināšanas statistiku
diff.show_split_view=Dalītais skats
diff.show_unified_view=Apvienotais skats
diff.whitespace_button=Atstarpes
diff.whitespace_show_everything=Rādīt visas izmaiņas
diff.whitespace_ignore_all_whitespace=Ignorēt atstarpes salīdzinot rindas
diff.whitespace_ignore_amount_changes=Ignorēt atstarpju daudzuma izmaiņas
diff.whitespace_ignore_at_eol=Ignorēt atstarpju izmaiņas rindu beigās
diff.stats_desc=<strong>%d mainītis faili</strong> ar <strong>%d papildinājumiem</strong> un <strong>%d dzēšanām</strong>
diff.bin=Binārs
diff.view_file=Parādīt failu
Expand Down
10 changes: 8 additions & 2 deletions options/locale/locale_pt-BR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ settings.external_tracker_url=URL do issue tracker externo
settings.external_tracker_url_error=A URL do issue tracker externo não é válida.
settings.external_tracker_url_desc=Visitantes são redirecionados para a URL do issue tracker externo ao clicar na aba de issues.
settings.tracker_url_format=Formato de URL do issue tracker externo
settings.tracker_url_format_error=O formato da URL do issue tracker externo não é válido.
settings.tracker_issue_style=Formato de número do issue tracker externo
settings.tracker_issue_style.numeric=Numérico
settings.tracker_issue_style.alphanumeric=Alfanumérico
Expand Down Expand Up @@ -1088,8 +1089,8 @@ settings.event_push=Push
settings.event_push_desc=Git push para o repositório.
settings.event_repository=Repositório
settings.event_repository_desc=Repositório criado ou excluído.
settings.active=Incluir detalhes do evento
settings.active_helper=Adicione informações sobre o evento de acionamento para requisições.
settings.active=Ativo
settings.active_helper=Informações sobre eventos disparados serão enviadas para esta URL do webhook.
settings.add_hook_success=O webhook foi adicionado.
settings.update_webhook=Atualizar webhook
settings.update_hook_success=O webhook foi atualizado.
Expand Down Expand Up @@ -1152,6 +1153,11 @@ diff.data_not_available=Conteúdo de diff não disponível
diff.show_diff_stats=Mostrar estatísticas do Diff
diff.show_split_view=Visão dividida
diff.show_unified_view=Visão unificada
diff.whitespace_button=Espaço em branco
diff.whitespace_show_everything=Mostrar todas as alterações
diff.whitespace_ignore_all_whitespace=Ignorar todas as alterações de espaço em branco
diff.whitespace_ignore_amount_changes=Ignorar alterações na quantidade de espaço em branco
diff.whitespace_ignore_at_eol=Ignorar alterações com espaço em branco no final da linha
diff.stats_desc=<strong> %d arquivos alterados</strong> com <strong>%d adições</strong> e <strong>%d exclusões</strong>
diff.bin=BIN
diff.view_file=Ver arquivo
Expand Down
Loading

0 comments on commit 3d84f1f

Please sign in to comment.