Skip to content

Commit

Permalink
Merge branch 'master' into feature/issue-5092
Browse files Browse the repository at this point in the history
  • Loading branch information
xor-gate authored Oct 25, 2018
2 parents 53c0181 + aeb5655 commit e2292c7
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 59 deletions.
26 changes: 13 additions & 13 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pipeline:
event: [ push, tag, pull_request ]

build-without-gcc:
image: golang:1.11
image: golang:1.9
pull: true
commands:
- go build -o gitea_no_gcc # test if build succeeds without the sqlite tag
Expand Down Expand Up @@ -117,18 +117,18 @@ pipeline:
when:
event: [ tag ]

test-sqlite:
image: golang:1.11
pull: true
group: test
environment:
TAGS: bindata
commands:
- curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
- apt-get install -y git-lfs
- make test-sqlite
when:
event: [ push, tag, pull_request ]
# test-sqlite:
# image: golang:1.11
# pull: true
# group: test
# environment:
# TAGS: bindata
# commands:
# - curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
# - apt-get install -y git-lfs
# - make test-sqlite
# when:
# event: [ push, tag, pull_request ]

test-mysql:
image: golang:1.11
Expand Down
9 changes: 5 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ignored = ["google.golang.org/appengine*"]

[[override]]
name = "github.com/mattn/go-sqlite3"
revision = "f3aa5ce89995fab8c7777f7821f689d9ac81c80f"
revision = "c7c4067b79cc51e6dfdcef5c702e74b1e0fa7c75"

[[override]]
name = "github.com/gorilla/mux"
Expand Down
2 changes: 2 additions & 0 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ MAX_DISPLAY_FILE_SIZE = 8388608
SHOW_USER_EMAIL = true
; Set the default theme for the Gitea install
DEFAULT_THEME = gitea
; Set the color range to use for heatmap (default to `['#f4f4f4', '#459928']` but can use `['#2d303b', '#80bb46']` with the theme `arc-green`)
HEATMAP_COLOR_RANGE = `['#f4f4f4', '#459928']`

[ui.admin]
; Number of users that are displayed on one page
Expand Down
4 changes: 2 additions & 2 deletions models/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthor

for _, watch := range watches {
issue.Repo.Units = nil
if issue.IsPull && !issue.Repo.CheckUnitUser(watch.UserID, false, UnitTypePullRequests) {
if issue.IsPull && !issue.Repo.checkUnitUser(e, watch.UserID, false, UnitTypePullRequests) {
continue
}
if !issue.IsPull && !issue.Repo.CheckUnitUser(watch.UserID, false, UnitTypeIssues) {
if !issue.IsPull && !issue.Repo.checkUnitUser(e, watch.UserID, false, UnitTypeIssues) {
continue
}

Expand Down
6 changes: 5 additions & 1 deletion models/org_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ func (t *Team) RemoveRepository(repoID int64) error {

// UnitEnabled returns if the team has the given unit type enabled
func (t *Team) UnitEnabled(tp UnitType) bool {
if err := t.getUnits(x); err != nil {
return t.unitEnabled(x, tp)
}

func (t *Team) unitEnabled(e Engine, tp UnitType) bool {
if err := t.getUnits(e); err != nil {
log.Warn("Error loading repository (ID: %d) units: %s", t.ID, err.Error())
}

Expand Down
8 changes: 6 additions & 2 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ func (repo *Repository) getUnits(e Engine) (err error) {

// CheckUnitUser check whether user could visit the unit of this repository
func (repo *Repository) CheckUnitUser(userID int64, isAdmin bool, unitType UnitType) bool {
if err := repo.getUnitsByUserID(x, userID, isAdmin); err != nil {
return repo.checkUnitUser(x, userID, isAdmin, unitType)
}

func (repo *Repository) checkUnitUser(e Engine, userID int64, isAdmin bool, unitType UnitType) bool {
if err := repo.getUnitsByUserID(e, userID, isAdmin); err != nil {
return false
}

Expand Down Expand Up @@ -369,7 +373,7 @@ func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) (
var newRepoUnits = make([]*RepoUnit, 0, len(repo.Units))
for _, u := range repo.Units {
for _, team := range teams {
if team.UnitEnabled(u.Type) {
if team.unitEnabled(e, u.Type) {
newRepoUnits = append(newRepoUnits, u)
break
}
Expand Down
7 changes: 4 additions & 3 deletions models/user_heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type UserHeatmapData struct {
}

// GetUserHeatmapDataByUser returns an array of UserHeatmapData
func GetUserHeatmapDataByUser(user *User) (hdata []*UserHeatmapData, err error) {
func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
hdata := make([]*UserHeatmapData, 0)
var groupBy string
switch {
case setting.UseSQLite3:
Expand All @@ -29,12 +30,12 @@ func GetUserHeatmapDataByUser(user *User) (hdata []*UserHeatmapData, err error)
groupBy = "dateadd(DAY,0, datediff(day,0, dateadd(s, created_unix, '19700101')))"
}

err = x.Select(groupBy+" as timestamp, count(user_id) as contributions").
err := x.Select(groupBy+" as timestamp, count(user_id) as contributions").
Table("action").
Where("user_id = ?", user.ID).
And("created_unix > ?", (util.TimeStampNow() - 31536000)).
GroupBy("timestamp").
OrderBy("timestamp").
Find(&hdata)
return
return hdata, err
}
55 changes: 37 additions & 18 deletions models/user_heatmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,48 @@
package models

import (
"github.com/stretchr/testify/assert"
"encoding/json"
"testing"

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

func TestGetUserHeatmapDataByUser(t *testing.T) {
testCases := []struct {
userID int64
CountResult int
JSONResult string
}{
{2, 1, `[{"timestamp":1540080000,"contributions":1}]`},
{3, 0, `[]`},
}
// Prepare
assert.NoError(t, PrepareTestDatabase())

// Insert some action
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)

// get the action for comparison
actions, err := GetFeeds(GetFeedsOptions{
RequestedUser: user,
RequestingUserID: user.ID,
IncludePrivate: true,
OnlyPerformedBy: false,
IncludeDeleted: true,
})
assert.NoError(t, err)

// Get the heatmap and compare
heatmap, err := GetUserHeatmapDataByUser(user)
assert.NoError(t, err)
assert.Equal(t, len(actions), len(heatmap))
for _, tc := range testCases {

// Insert some action
user := AssertExistsAndLoadBean(t, &User{ID: tc.userID}).(*User)

// get the action for comparison
actions, err := GetFeeds(GetFeedsOptions{
RequestedUser: user,
RequestingUserID: user.ID,
IncludePrivate: true,
OnlyPerformedBy: false,
IncludeDeleted: true,
})
assert.NoError(t, err)

// Get the heatmap and compare
heatmap, err := GetUserHeatmapDataByUser(user)
assert.NoError(t, err)
assert.Equal(t, len(actions), len(heatmap))
assert.Equal(t, tc.CountResult, len(heatmap))

//Test JSON rendering
jsonData, err := json.Marshal(heatmap)
assert.NoError(t, err)
assert.Equal(t, tc.JSONResult, string(jsonData))
}
}
2 changes: 2 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ var (
MaxDisplayFileSize int64
ShowUserEmail bool
DefaultTheme string
HeatmapColorRange string

Admin struct {
UserPagingNum int
Expand All @@ -326,6 +327,7 @@ var (
ThemeColorMetaTag: `#6cc644`,
MaxDisplayFileSize: 8388608,
DefaultTheme: `gitea`,
HeatmapColorRange: `['#f4f4f4', '#459928']`,
Admin: struct {
UserPagingNum int
RepoPagingNum int
Expand Down
3 changes: 3 additions & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ func NewFuncMap() []template.FuncMap {
"DefaultTheme": func() string {
return setting.UI.DefaultTheme
},
"HeatmapColorRange": func() string {
return setting.UI.HeatmapColorRange
},
"dict": func(values ...interface{}) (map[string]interface{}, error) {
if len(values) == 0 {
return nil, errors.New("invalid dict call")
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_ja-JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ starred=スター付きリポジトリ
following=フォロー中
follow=フォロー
unfollow=フォロー解除
heatmap.loading=ヒートマップを読み込み中…

form.name_reserved=ユーザー名 '%s' は予約されています。
form.name_pattern_not_allowed='%s' の形式はユーザー名に使用できません。
Expand Down
3 changes: 2 additions & 1 deletion options/locale/locale_pt-BR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sign_in=Acessar
sign_in_with=Acessar com
sign_out=Sair
sign_up=Cadastrar
link_account=Conectar Conta
link_account=Conectar conta
link_account_signin_or_signup=Acesse para conectar sua conta existente à sua nova conta, ou cadastre-se para uma nova conta.
register=Cadastrar
website=Site
Expand Down Expand Up @@ -320,6 +320,7 @@ starred=Repositórios favoritos
following=Seguindo
follow=Seguir
unfollow=Deixar de seguir
heatmap.loading=Carregando mapa de calor...

form.name_reserved=O nome de usuário '%s' está reservado.
form.name_pattern_not_allowed=O padrão de '%s' não é permitido em um nome de usuário.
Expand Down
2 changes: 1 addition & 1 deletion templates/base/footer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
var heatmap = calendarHeatmap()
.data(chartData)
.selector('#user-heatmap')
.colorRange(['#f4f4f4', '#459928'])
.colorRange({{SafeJS HeatmapColorRange}})
.tooltipEnabled(true);
heatmap();
});
Expand Down
12 changes: 6 additions & 6 deletions vendor/github.com/go-macaron/session/file.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e2292c7

Please sign in to comment.