Skip to content

Commit

Permalink
Merge branch 'master' into fix_8872
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Nov 9, 2019
2 parents 527fb48 + d2aee2a commit 7c721df
Show file tree
Hide file tree
Showing 19 changed files with 279 additions and 119 deletions.
4 changes: 4 additions & 0 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ DELIVER_TIMEOUT = 5
SKIP_TLS_VERIFY = false
; Number of history information in each page
PAGING_NUM = 10
; Proxy server URL, support http://, https//, socks://, blank will follow environment http_proxy/https_proxy
PROXY_URL =
; Comma separated list of host names requiring proxy. Glob patterns (*) are accepted; use ** to match all hosts.
PROXY_HOSTS =

[mailer]
ENABLED = false
Expand Down
2 changes: 2 additions & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ relation to port exhaustion.
- `DELIVER_TIMEOUT`: **5**: Delivery timeout (sec) for shooting webhooks.
- `SKIP_TLS_VERIFY`: **false**: Allow insecure certification.
- `PAGING_NUM`: **10**: Number of webhook history events that are shown in one page.
- `PROXY_URL`: ****: Proxy server URL, support http://, https//, socks://, blank will follow environment http_proxy/https_proxy
- `PROXY_HOSTS`: ****: Comma separated list of host names requiring proxy. Glob patterns (*) are accepted; use ** to match all hosts.

## Mailer (`mailer`)

Expand Down
2 changes: 2 additions & 0 deletions docs/content/doc/advanced/config-cheat-sheet.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ menu:
- `DELIVER_TIMEOUT`: 请求webhooks的超时时间,单位秒。
- `SKIP_TLS_VERIFY`: 是否允许不安全的证书。
- `PAGING_NUM`: 每页显示的Webhook 历史数量。
- `PROXY_URL`: ****: 代理服务器网址,支持 http://, https//, socks://, 为空将使用环境变量中的 http_proxy/https_proxy 设置。
- `PROXY_HOSTS`: ****: 逗号分隔的需要代理的域名或IP地址。支持 * 号匹配符,使用 ** 匹配所有域名和IP地址。

## Mailer (`mailer`)

Expand Down
36 changes: 36 additions & 0 deletions docs/content/doc/advanced/third-party-tools.zh-cn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
date: "2019-03-11T21:45:00+00:00"
title: "高级: 第三方工具"
slug: "third-party-tools"
weight: 50
toc: true
draft: false
menu:
sidebar:
parent: "advanced"
name: "第三方工具"
weight: 50
identifier: "third-party-tools"
---

# 第三方工具列表
**注意:** 这些工具并没有经过Gitea的检验,在这里列出它们只是为了便捷.

*此列表并不是完整的列表,可以随时咨询如何添加!*

### 持续集成
[BuildKite 连接器](https://github.com/techknowlogick/gitea-buildkite-connector)
[Jenkins 插件](https://github.com/jenkinsci/gitea-plugin)
[Gitea搭配Drone](https://docs.drone.io/installation/gitea)


### 迁移
[Gitea安装脚本](https://git.coolaj86.com/coolaj86/gitea-installer.sh)
[GitHub迁移](https://gitea.com/gitea/migrator)


### 移动端
[安卓客户端GitNex](https://gitlab.com/mmarif4u/gitnex)

### 编辑器扩展
- [Gitea的Visual Studio扩展](https://github.com/maikebing/Gitea.VisualStudio)[Visual Studio 扩展市场](https://marketplace.visualstudio.com/items?itemName=MysticBoy.GiteaExtensionforVisualStudio) 下载
2 changes: 1 addition & 1 deletion integrations/api_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func testAPIRepoMigrateConflict(t *testing.T, u *url.URL) {
resp := httpContext.Session.MakeRequest(t, req, http.StatusConflict)
respJSON := map[string]string{}
DecodeJSON(t, resp, &respJSON)
assert.Equal(t, respJSON["message"], "The repository with the same name already exists.")
assert.Equal(t, "The repository with the same name already exists.", respJSON["message"])
})
}

Expand Down
43 changes: 0 additions & 43 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,49 +283,6 @@ func (a *Action) GetIssueContent() string {
return issue.Content
}

func newRepoAction(e Engine, u *User, repo *Repository) (err error) {
if err = notifyWatchers(e, &Action{
ActUserID: u.ID,
ActUser: u,
OpType: ActionCreateRepo,
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
}); err != nil {
return fmt.Errorf("notify watchers '%d/%d': %v", u.ID, repo.ID, err)
}

log.Trace("action.newRepoAction: %s/%s", u.Name, repo.Name)
return err
}

// NewRepoAction adds new action for creating repository.
func NewRepoAction(u *User, repo *Repository) (err error) {
return newRepoAction(x, u, repo)
}

func renameRepoAction(e Engine, actUser *User, oldRepoName string, repo *Repository) (err error) {
if err = notifyWatchers(e, &Action{
ActUserID: actUser.ID,
ActUser: actUser,
OpType: ActionRenameRepo,
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
Content: oldRepoName,
}); err != nil {
return fmt.Errorf("notify watchers: %v", err)
}

log.Trace("action.renameRepoAction: %s/%s", actUser.Name, repo.Name)
return nil
}

// RenameRepoAction adds new action for renaming a repository.
func RenameRepoAction(actUser *User, oldRepoName string, repo *Repository) error {
return renameRepoAction(x, actUser, oldRepoName, repo)
}

// PushCommit represents a commit in a push operation.
type PushCommit struct {
Sha1 string
Expand Down
53 changes: 0 additions & 53 deletions models/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package models

import (
"path"
"strings"
"testing"

"code.gitea.io/gitea/modules/setting"
Expand All @@ -28,58 +27,6 @@ func TestAction_GetRepoLink(t *testing.T) {
assert.Equal(t, expected, action.GetRepoLink())
}

func TestNewRepoAction(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
repo := AssertExistsAndLoadBean(t, &Repository{OwnerID: user.ID}).(*Repository)
repo.Owner = user

actionBean := &Action{
OpType: ActionCreateRepo,
ActUserID: user.ID,
RepoID: repo.ID,
ActUser: user,
Repo: repo,
IsPrivate: repo.IsPrivate,
}

AssertNotExistsBean(t, actionBean)
assert.NoError(t, NewRepoAction(user, repo))
AssertExistsAndLoadBean(t, actionBean)
CheckConsistencyFor(t, &Action{})
}

func TestRenameRepoAction(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())

user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
repo := AssertExistsAndLoadBean(t, &Repository{OwnerID: user.ID}).(*Repository)
repo.Owner = user

oldRepoName := repo.Name
const newRepoName = "newRepoName"
repo.Name = newRepoName
repo.LowerName = strings.ToLower(newRepoName)

actionBean := &Action{
OpType: ActionRenameRepo,
ActUserID: user.ID,
ActUser: user,
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
Content: oldRepoName,
}
AssertNotExistsBean(t, actionBean)
assert.NoError(t, RenameRepoAction(user, oldRepoName, repo))
AssertExistsAndLoadBean(t, actionBean)

_, err := x.ID(repo.ID).Cols("name", "lower_name").Update(repo)
assert.NoError(t, err)
CheckConsistencyFor(t, &Action{})
}

func TestPushCommits_ToAPIPayloadCommits(t *testing.T) {
pushCommits := NewPushCommits()
pushCommits.Commits = []*PushCommit{
Expand Down
17 changes: 15 additions & 2 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1469,8 +1469,15 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
return fmt.Errorf("watchRepo: %v", err)
}
}
if err = newRepoAction(e, doer, repo); err != nil {
return fmt.Errorf("newRepoAction: %v", err)
if err = notifyWatchers(e, &Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: ActionCreateRepo,
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
}); err != nil {
return fmt.Errorf("notify watchers '%d/%d': %v", doer.ID, repo.ID, err)
}

if err = copyDefaultWebhooksToRepo(e, repo.ID); err != nil {
Expand Down Expand Up @@ -2833,3 +2840,9 @@ func (repo *Repository) GetTreePathLock(treePath string) (*LFSLock, error) {
}
return nil, nil
}

// UpdateRepositoryCols updates repository's columns
func UpdateRepositoryCols(repo *Repository, cols ...string) error {
_, err := x.ID(repo.ID).Cols(cols...).Update(repo)
return err
}
18 changes: 17 additions & 1 deletion modules/notification/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
_ base.Notifier = &actionNotifier{}
)

// NewNotifier create a new webhookNotifier notifier
// NewNotifier create a new actionNotifier notifier
func NewNotifier() base.Notifier {
return &actionNotifier{}
}
Expand Down Expand Up @@ -75,3 +75,19 @@ func (a *actionNotifier) NotifyNewPullRequest(pull *models.PullRequest) {
log.Error("NotifyWatchers: %v", err)
}
}

func (a *actionNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
if err := models.NotifyWatchers(&models.Action{
ActUserID: doer.ID,
ActUser: doer,
OpType: models.ActionRenameRepo,
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
Content: oldName,
}); err != nil {
log.Error("notify watchers: %v", err)
} else {
log.Trace("action.renameRepoAction: %s/%s", doer.Name, repo.Name)
}
}
47 changes: 47 additions & 0 deletions modules/notification/action/action_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2019 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 action

import (
"path/filepath"
"strings"
"testing"

"code.gitea.io/gitea/models"
"github.com/stretchr/testify/assert"
)

func TestMain(m *testing.M) {
models.MainTest(m, filepath.Join("..", "..", ".."))
}

func TestRenameRepoAction(t *testing.T) {
assert.NoError(t, models.PrepareTestDatabase())

user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
repo := models.AssertExistsAndLoadBean(t, &models.Repository{OwnerID: user.ID}).(*models.Repository)
repo.Owner = user

oldRepoName := repo.Name
const newRepoName = "newRepoName"
repo.Name = newRepoName
repo.LowerName = strings.ToLower(newRepoName)

actionBean := &models.Action{
OpType: models.ActionRenameRepo,
ActUserID: user.ID,
ActUser: user,
RepoID: repo.ID,
Repo: repo,
IsPrivate: repo.IsPrivate,
Content: oldRepoName,
}
models.AssertNotExistsBean(t, actionBean)

NewNotifier().NotifyRenameRepository(user, repo, oldRepoName)

models.AssertExistsAndLoadBean(t, actionBean)
models.CheckConsistencyFor(t, &models.Action{})
}
1 change: 1 addition & 0 deletions modules/notification/base/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Notifier interface {
NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository)
NotifyDeleteRepository(doer *models.User, repo *models.Repository)
NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository)
NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string)

NotifyNewIssue(*models.Issue)
NotifyIssueChangeStatus(*models.User, *models.Issue, bool)
Expand Down
4 changes: 4 additions & 0 deletions modules/notification/base/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (*NullNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repo
func (*NullNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
}

// NotifyRenameRepository places a place holder function
func (*NullNotifier) NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
}

// NotifyNewRelease places a place holder function
func (*NullNotifier) NotifyNewRelease(rel *models.Release) {
}
Expand Down
7 changes: 7 additions & 0 deletions modules/notification/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ func NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
}
}

// NotifyRenameRepository notifies repository renamed
func NotifyRenameRepository(doer *models.User, repo *models.Repository, oldName string) {
for _, notifier := range notifiers {
notifier.NotifyRenameRepository(doer, repo, oldName)
}
}

// NotifyNewRelease notifies new release to notifiers
func NotifyNewRelease(rel *models.Release) {
for _, notifier := range notifiers {
Expand Down
21 changes: 21 additions & 0 deletions modules/setting/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

package setting

import (
"net/url"

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

var (
// Webhook settings
Webhook = struct {
Expand All @@ -12,11 +18,16 @@ var (
SkipTLSVerify bool
Types []string
PagingNum int
ProxyURL string
ProxyURLFixed *url.URL
ProxyHosts []string
}{
QueueLength: 1000,
DeliverTimeout: 5,
SkipTLSVerify: false,
PagingNum: 10,
ProxyURL: "",
ProxyHosts: []string{},
}
)

Expand All @@ -27,4 +38,14 @@ func newWebhookService() {
Webhook.SkipTLSVerify = sec.Key("SKIP_TLS_VERIFY").MustBool()
Webhook.Types = []string{"gitea", "gogs", "slack", "discord", "dingtalk", "telegram", "msteams"}
Webhook.PagingNum = sec.Key("PAGING_NUM").MustInt(10)
Webhook.ProxyURL = sec.Key("PROXY_URL").MustString("")
if Webhook.ProxyURL != "" {
var err error
Webhook.ProxyURLFixed, err = url.Parse(Webhook.ProxyURL)
if err != nil {
log.Error("Webhook PROXY_URL is not valid")
Webhook.ProxyURL = ""
}
}
Webhook.ProxyHosts = sec.Key("PROXY_HOSTS").Strings(",")
}
2 changes: 0 additions & 2 deletions modules/task/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ func runMigrateTask(t *models.Task) (err error) {
opts.MigrateToRepoID = t.RepoID
repo, err := migrations.MigrateRepository(t.Doer, t.Owner.Name, *opts)
if err == nil {
notification.NotifyMigrateRepository(t.Doer, t.Owner, repo)

log.Trace("Repository migrated [%d]: %s/%s", repo.ID, t.Owner.Name, repo.Name)
return nil
}
Expand Down
Loading

0 comments on commit 7c721df

Please sign in to comment.