Skip to content

Commit e2292c7

Browse files
authored
Merge branch 'master' into feature/issue-5092
2 parents 53c0181 + aeb5655 commit e2292c7

File tree

17 files changed

+106
-59
lines changed

17 files changed

+106
-59
lines changed

.drone.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pipeline:
5656
event: [ push, tag, pull_request ]
5757

5858
build-without-gcc:
59-
image: golang:1.11
59+
image: golang:1.9
6060
pull: true
6161
commands:
6262
- go build -o gitea_no_gcc # test if build succeeds without the sqlite tag
@@ -117,18 +117,18 @@ pipeline:
117117
when:
118118
event: [ tag ]
119119

120-
test-sqlite:
121-
image: golang:1.11
122-
pull: true
123-
group: test
124-
environment:
125-
TAGS: bindata
126-
commands:
127-
- curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
128-
- apt-get install -y git-lfs
129-
- make test-sqlite
130-
when:
131-
event: [ push, tag, pull_request ]
120+
# test-sqlite:
121+
# image: golang:1.11
122+
# pull: true
123+
# group: test
124+
# environment:
125+
# TAGS: bindata
126+
# commands:
127+
# - curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
128+
# - apt-get install -y git-lfs
129+
# - make test-sqlite
130+
# when:
131+
# event: [ push, tag, pull_request ]
132132

133133
test-mysql:
134134
image: golang:1.11

Gopkg.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ignored = ["google.golang.org/appengine*"]
4141

4242
[[override]]
4343
name = "github.com/mattn/go-sqlite3"
44-
revision = "f3aa5ce89995fab8c7777f7821f689d9ac81c80f"
44+
revision = "c7c4067b79cc51e6dfdcef5c702e74b1e0fa7c75"
4545

4646
[[override]]
4747
name = "github.com/gorilla/mux"

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ MAX_DISPLAY_FILE_SIZE = 8388608
8585
SHOW_USER_EMAIL = true
8686
; Set the default theme for the Gitea install
8787
DEFAULT_THEME = gitea
88+
; Set the color range to use for heatmap (default to `['#f4f4f4', '#459928']` but can use `['#2d303b', '#80bb46']` with the theme `arc-green`)
89+
HEATMAP_COLOR_RANGE = `['#f4f4f4', '#459928']`
8890

8991
[ui.admin]
9092
; Number of users that are displayed on one page

models/notification.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ func createOrUpdateIssueNotifications(e Engine, issue *Issue, notificationAuthor
123123

124124
for _, watch := range watches {
125125
issue.Repo.Units = nil
126-
if issue.IsPull && !issue.Repo.CheckUnitUser(watch.UserID, false, UnitTypePullRequests) {
126+
if issue.IsPull && !issue.Repo.checkUnitUser(e, watch.UserID, false, UnitTypePullRequests) {
127127
continue
128128
}
129-
if !issue.IsPull && !issue.Repo.CheckUnitUser(watch.UserID, false, UnitTypeIssues) {
129+
if !issue.IsPull && !issue.Repo.checkUnitUser(e, watch.UserID, false, UnitTypeIssues) {
130130
continue
131131
}
132132

models/org_team.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,11 @@ func (t *Team) RemoveRepository(repoID int64) error {
215215

216216
// UnitEnabled returns if the team has the given unit type enabled
217217
func (t *Team) UnitEnabled(tp UnitType) bool {
218-
if err := t.getUnits(x); err != nil {
218+
return t.unitEnabled(x, tp)
219+
}
220+
221+
func (t *Team) unitEnabled(e Engine, tp UnitType) bool {
222+
if err := t.getUnits(e); err != nil {
219223
log.Warn("Error loading repository (ID: %d) units: %s", t.ID, err.Error())
220224
}
221225

models/repo.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ func (repo *Repository) getUnits(e Engine) (err error) {
321321

322322
// CheckUnitUser check whether user could visit the unit of this repository
323323
func (repo *Repository) CheckUnitUser(userID int64, isAdmin bool, unitType UnitType) bool {
324-
if err := repo.getUnitsByUserID(x, userID, isAdmin); err != nil {
324+
return repo.checkUnitUser(x, userID, isAdmin, unitType)
325+
}
326+
327+
func (repo *Repository) checkUnitUser(e Engine, userID int64, isAdmin bool, unitType UnitType) bool {
328+
if err := repo.getUnitsByUserID(e, userID, isAdmin); err != nil {
325329
return false
326330
}
327331

@@ -369,7 +373,7 @@ func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) (
369373
var newRepoUnits = make([]*RepoUnit, 0, len(repo.Units))
370374
for _, u := range repo.Units {
371375
for _, team := range teams {
372-
if team.UnitEnabled(u.Type) {
376+
if team.unitEnabled(e, u.Type) {
373377
newRepoUnits = append(newRepoUnits, u)
374378
break
375379
}

models/user_heatmap.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type UserHeatmapData struct {
1616
}
1717

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

32-
err = x.Select(groupBy+" as timestamp, count(user_id) as contributions").
33+
err := x.Select(groupBy+" as timestamp, count(user_id) as contributions").
3334
Table("action").
3435
Where("user_id = ?", user.ID).
3536
And("created_unix > ?", (util.TimeStampNow() - 31536000)).
3637
GroupBy("timestamp").
3738
OrderBy("timestamp").
3839
Find(&hdata)
39-
return
40+
return hdata, err
4041
}

models/user_heatmap_test.go

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,48 @@
55
package models
66

77
import (
8-
"github.com/stretchr/testify/assert"
8+
"encoding/json"
99
"testing"
10+
11+
"github.com/stretchr/testify/assert"
1012
)
1113

1214
func TestGetUserHeatmapDataByUser(t *testing.T) {
15+
testCases := []struct {
16+
userID int64
17+
CountResult int
18+
JSONResult string
19+
}{
20+
{2, 1, `[{"timestamp":1540080000,"contributions":1}]`},
21+
{3, 0, `[]`},
22+
}
1323
// Prepare
1424
assert.NoError(t, PrepareTestDatabase())
1525

16-
// Insert some action
17-
user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
18-
19-
// get the action for comparison
20-
actions, err := GetFeeds(GetFeedsOptions{
21-
RequestedUser: user,
22-
RequestingUserID: user.ID,
23-
IncludePrivate: true,
24-
OnlyPerformedBy: false,
25-
IncludeDeleted: true,
26-
})
27-
assert.NoError(t, err)
28-
29-
// Get the heatmap and compare
30-
heatmap, err := GetUserHeatmapDataByUser(user)
31-
assert.NoError(t, err)
32-
assert.Equal(t, len(actions), len(heatmap))
26+
for _, tc := range testCases {
27+
28+
// Insert some action
29+
user := AssertExistsAndLoadBean(t, &User{ID: tc.userID}).(*User)
30+
31+
// get the action for comparison
32+
actions, err := GetFeeds(GetFeedsOptions{
33+
RequestedUser: user,
34+
RequestingUserID: user.ID,
35+
IncludePrivate: true,
36+
OnlyPerformedBy: false,
37+
IncludeDeleted: true,
38+
})
39+
assert.NoError(t, err)
40+
41+
// Get the heatmap and compare
42+
heatmap, err := GetUserHeatmapDataByUser(user)
43+
assert.NoError(t, err)
44+
assert.Equal(t, len(actions), len(heatmap))
45+
assert.Equal(t, tc.CountResult, len(heatmap))
46+
47+
//Test JSON rendering
48+
jsonData, err := json.Marshal(heatmap)
49+
assert.NoError(t, err)
50+
assert.Equal(t, tc.JSONResult, string(jsonData))
51+
}
3352
}

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ var (
300300
MaxDisplayFileSize int64
301301
ShowUserEmail bool
302302
DefaultTheme string
303+
HeatmapColorRange string
303304

304305
Admin struct {
305306
UserPagingNum int
@@ -326,6 +327,7 @@ var (
326327
ThemeColorMetaTag: `#6cc644`,
327328
MaxDisplayFileSize: 8388608,
328329
DefaultTheme: `gitea`,
330+
HeatmapColorRange: `['#f4f4f4', '#459928']`,
329331
Admin: struct {
330332
UserPagingNum int
331333
RepoPagingNum int

modules/templates/helper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ func NewFuncMap() []template.FuncMap {
193193
"DefaultTheme": func() string {
194194
return setting.UI.DefaultTheme
195195
},
196+
"HeatmapColorRange": func() string {
197+
return setting.UI.HeatmapColorRange
198+
},
196199
"dict": func(values ...interface{}) (map[string]interface{}, error) {
197200
if len(values) == 0 {
198201
return nil, errors.New("invalid dict call")

options/locale/locale_ja-JP.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ starred=スター付きリポジトリ
320320
following=フォロー中
321321
follow=フォロー
322322
unfollow=フォロー解除
323+
heatmap.loading=ヒートマップを読み込み中…
323324

324325
form.name_reserved=ユーザー名 '%s' は予約されています。
325326
form.name_pattern_not_allowed='%s' の形式はユーザー名に使用できません。

options/locale/locale_pt-BR.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sign_in=Acessar
88
sign_in_with=Acessar com
99
sign_out=Sair
1010
sign_up=Cadastrar
11-
link_account=Conectar Conta
11+
link_account=Conectar conta
1212
link_account_signin_or_signup=Acesse para conectar sua conta existente à sua nova conta, ou cadastre-se para uma nova conta.
1313
register=Cadastrar
1414
website=Site
@@ -320,6 +320,7 @@ starred=Repositórios favoritos
320320
following=Seguindo
321321
follow=Seguir
322322
unfollow=Deixar de seguir
323+
heatmap.loading=Carregando mapa de calor...
323324

324325
form.name_reserved=O nome de usuário '%s' está reservado.
325326
form.name_pattern_not_allowed=O padrão de '%s' não é permitido em um nome de usuário.

templates/base/footer.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
var heatmap = calendarHeatmap()
6666
.data(chartData)
6767
.selector('#user-heatmap')
68-
.colorRange(['#f4f4f4', '#459928'])
68+
.colorRange({{SafeJS HeatmapColorRange}})
6969
.tooltipEnabled(true);
7070
heatmap();
7171
});

vendor/github.com/go-macaron/session/file.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)