Skip to content

Commit

Permalink
feat add feature/develop for collecting git metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Apr 17, 2024
1 parent bdb107b commit 3ebc974
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/tools/gittar/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Conf struct {

// metrics
RefreshPersonalContributorDuration time.Duration `default:"12h" env:"REFRESH_PERSONAL_CONTRIBUTOR_DURATION"`
MetricTargetBranches []string `env:"METRIC_TARGET_BRANCHES" default:"[\"master\",\"main\",\"dev\",\"develop\",\"release\",\"feature/develop\"]"`

// AI
AIProxyURL string `env:"AI_PROXY_URL"`
Expand Down Expand Up @@ -215,6 +216,10 @@ func RefreshPersonalContributorDuration() time.Duration {
return cfg.RefreshPersonalContributorDuration
}

func MetricTargetBranches() []string {
return cfg.MetricTargetBranches
}

func DiceCluster() string {
return os.Getenv(apistructs.DICE_CLUSTER_NAME.String())
}
29 changes: 29 additions & 0 deletions internal/tools/gittar/conf/conf_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package conf

import (
"testing"

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

func TestLoad(t *testing.T) {
Load()
branches := MetricTargetBranches()
assert.Equal(t, 6, len(branches))
assert.Equal(t, "master", branches[0])
assert.Equal(t, "feature/develop", branches[5])
}
5 changes: 2 additions & 3 deletions internal/tools/gittar/metrics/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (

var (
defaultBranch = "master"
targetBranch = []string{"master", "Master", "main", "Main", "dev", "Dev", "develop", "Develop", "release", "Release"}
)

var (
Expand Down Expand Up @@ -101,7 +100,7 @@ func NewPersonalMetric(author *gitmodule.Signature, repo *models.Repo) *Personal
}

func IsValidBranch(s string, prefixes ...string) bool {
if !strutil.HasPrefixes(s, prefixes...) {
if !strutil.HasPrefixes(strutil.ToLower(s), prefixes...) {
return false
}
return true
Expand Down Expand Up @@ -181,7 +180,7 @@ func (c *Collector) IterateRepos(req apistructs.GittarListRepoRequest) ([]*Perso
}
var allSourceCommit []*gitmodule.Commit
for _, branch := range branches {
if !IsValidBranch(branch, targetBranch...) {
if !IsValidBranch(branch, conf.MetricTargetBranches()...) {
continue
}
SourceCommit, err := gitRepository.GetBranchCommit(branch)
Expand Down

0 comments on commit 3ebc974

Please sign in to comment.