Skip to content

Commit 9ce8ce8

Browse files
authored
Merge branch 'master' into docs/update-examples
2 parents 2ac7b84 + 43c2c25 commit 9ce8ce8

File tree

7 files changed

+70
-15
lines changed

7 files changed

+70
-15
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- When it's added the `-v` verbose flag, gitbase will use `debug` as logging level, ignoring any other passed ([#935](https://github.com/src-d/gitbase/pull/935))
12+
13+
### Fixed
14+
15+
- If using docker image, and `info` logging level, it will be now used instead of `debug` ([#935](https://github.com/src-d/gitbase/pull/935))
16+
17+
918
## [0.24.0-beta1] - 2019-07-08
1019

1120
### Added

cmd/gitbase/command/server.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ type Server struct {
8383
MetricsPort int `long:"metrics-port" env:"GITBASE_METRICS_PORT" default:"2112" description:"Port where the server is going to expose prometheus metrics"`
8484
ReadOnly bool `short:"r" long:"readonly" description:"Only allow read queries. This disables creating and deleting indexes as well. Cannot be used with --user-file." env:"GITBASE_READONLY"`
8585
SkipGitErrors bool // SkipGitErrors disables failing when Git errors are found.
86-
Verbose bool `short:"v" description:"Activates the verbose mode"`
87-
LogLevel string `long:"log-level" env:"GITBASE_LOG_LEVEL" choice:"info" choice:"debug" choice:"warning" choice:"error" choice:"fatal" default:"info" description:"logging level"`
86+
Verbose bool `short:"v" description:"Activates the verbose mode (equivalent to debug logging level), overwriting any passed logging level"`
87+
LogLevel string `long:"log-level" env:"GITBASE_LOG_LEVEL" choice:"info" choice:"debug" choice:"warning" choice:"error" choice:"fatal" default:"info" description:"logging level; ignored if using -v verbose flag"`
8888
}
8989

9090
type jaegerLogrus struct {
@@ -138,11 +138,18 @@ func (c *Server) Execute(args []string) error {
138138

139139
// info is the default log level
140140
if c.LogLevel != "info" {
141-
level, err := logrus.ParseLevel(c.LogLevel)
142-
if err != nil {
143-
return fmt.Errorf("cannot parse log level: %s", err.Error())
141+
if c.Verbose {
142+
logrus.Infof(
143+
"ignoring passed '%s' log-level, using requesed '-v' verbose flag instead",
144+
c.LogLevel,
145+
)
146+
} else {
147+
level, err := logrus.ParseLevel(c.LogLevel)
148+
if err != nil {
149+
return fmt.Errorf("cannot parse log level: %s", err.Error())
150+
}
151+
logrus.SetLevel(level)
144152
}
145-
logrus.SetLevel(level)
146153
}
147154

148155
var err error

docs/using-gitbase/configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Help Options:
117117
-r, --readonly Only allow read queries. This disables creating and
118118
deleting indexes as well. Cannot be used with
119119
--user-file. [$GITBASE_READONLY]
120-
-v Activates the verbose mode
120+
-v Activates the verbose mode (equivalent to debug
121+
logging level), overwriting any passed logging level
121122
--log-level=[info|debug|warning|error|fatal] logging level (default: info) [$GITBASE_LOG_LEVEL]
122123
```

docs/using-gitbase/functions.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ Also, if you want to retrieve values from a non common property, you can pass it
169169

170170
> uast_extract(nodes_column, 'some-property')
171171
172+
## How to use `loc`
173+
174+
`loc` will return statistics about the lines of code in a file, such as the code lines, comment lines, etc.
175+
176+
It requires a file path and a file content.
177+
178+
> loc(file_path, blob_content)
179+
180+
The result of this function is a JSON document with the following shape:
181+
182+
```
183+
{
184+
"Code": code lines,
185+
"Comment": comment lines,
186+
"Blank": blank lines,
187+
"Name": file name,
188+
"Lang": language
189+
}
190+
```
191+
172192
## How to use `commit_file_stats`
173193

174194
`commit_file_stats` will return statistics about the line changes in all files in the given range of commits classifying them in 4 categories: code, comments, blank lines and other.

init.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ user=${GITBASE_USER}
1010
password=${GITBASE_PASSWORD}
1111
EOT
1212

13-
/tini -s -- /bin/gitbase server -v \
13+
export GITBASE_LOG_LEVEL=${GITBASE_LOG_LEVEL:-debug}
14+
15+
/tini -s -- /bin/gitbase server \
1416
--host=0.0.0.0 \
1517
--port=3306 \
1618
--user="$GITBASE_USER" \
1719
--password="$GITBASE_PASSWORD" \
1820
--directories="$GITBASE_REPOS" \
19-
$SIVA_ARGS
21+
$SIVA_ARGS

internal/function/loc.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ func (f *LOC) WithChildren(children ...sql.Expression) (sql.Expression, error) {
5252
return NewLOC(children...)
5353
}
5454

55+
// LocFile is the result of the LOC function for each file.
56+
type LocFile struct {
57+
Code int32 `json:"Code"`
58+
Comments int32 `json:"Comment"`
59+
Blanks int32 `json:"Blank"`
60+
Name string `json:"Name"`
61+
Lang string `json:"Language"`
62+
}
63+
5564
// Eval implements the Expression interface.
5665
func (f *LOC) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
5766
span, ctx := ctx.Span("gitbase.LOC")
@@ -70,11 +79,19 @@ func (f *LOC) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
7079
return nil, nil
7180
}
7281

73-
return gocloc.AnalyzeReader(
82+
file := gocloc.AnalyzeReader(
7483
path,
7584
languages.Langs[lang],
7685
bytes.NewReader(blob), &gocloc.ClocOptions{},
77-
), nil
86+
)
87+
88+
return LocFile{
89+
Code: file.Code,
90+
Comments: file.Comments,
91+
Blanks: file.Blanks,
92+
Name: file.Name,
93+
Lang: file.Lang,
94+
}, nil
7895
}
7996

8097
func (f *LOC) getInputValues(ctx *sql.Context, row sql.Row) (string, []byte, error) {

internal/function/loc_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ package function
33
import (
44
"testing"
55

6-
"github.com/hhatto/gocloc"
7-
"github.com/stretchr/testify/require"
8-
"gopkg.in/src-d/go-errors.v1"
96
"github.com/src-d/go-mysql-server/sql"
107
"github.com/src-d/go-mysql-server/sql/expression"
8+
"github.com/stretchr/testify/require"
9+
"gopkg.in/src-d/go-errors.v1"
1110
)
1211

1312
func TestLoc(t *testing.T) {
@@ -22,7 +21,7 @@ func TestLoc(t *testing.T) {
2221
{"too few args given", sql.NewRow("foo.foobar"), nil, nil},
2322
{"too many args given", sql.NewRow("foo.rb", "bar", "baz"), nil, sql.ErrInvalidArgumentNumber},
2423
{"invalid blob type given", sql.NewRow("foo", 5), nil, sql.ErrInvalidType},
25-
{"path and blob are given", sql.NewRow("foo", "#!/usr/bin/env python\n\nprint 'foo'"), &gocloc.ClocFile{
24+
{"path and blob are given", sql.NewRow("foo", "#!/usr/bin/env python\n\nprint 'foo'"), LocFile{
2625
Code: 2, Comments: 0, Blanks: 1, Name: "foo", Lang: "Python",
2726
}, nil},
2827
}

0 commit comments

Comments
 (0)