generated from B1NARY-GR0UP/.github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add org and group contribution analysis
- Loading branch information
1 parent
0b50b4e
commit 16f6941
Showing
6 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2024 BINARY Members | ||
// | ||
// 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 cron | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
type User struct { | ||
ID string | ||
Name string | ||
Count int | ||
} | ||
|
||
func Test1(t *testing.T) { | ||
m := make(map[string]User) | ||
if _, ok := m["1"]; !ok { | ||
m["1"] = User{ID: "1", Name: "lorain", Count: 0} | ||
} | ||
fmt.Println(m) // 0 | ||
if v, ok := m["1"]; ok { | ||
v.Count += 10 | ||
} | ||
fmt.Println(m) // 0 | ||
} | ||
|
||
func Test2(t *testing.T) { | ||
m := make(map[string]User) | ||
if _, ok := m["1"]; !ok { | ||
m["1"] = User{ID: "1", Name: "lorain", Count: 0} | ||
} | ||
fmt.Println(m) // 0 | ||
if v, ok := m["1"]; ok { | ||
v.Count += 10 | ||
m["1"] = v | ||
} | ||
fmt.Println(m) // 10 | ||
} | ||
|
||
func Test3(t *testing.T) { | ||
m := make(map[string]*User) | ||
if _, ok := m["1"]; !ok { | ||
m["1"] = &User{ID: "1", Name: "lorain", Count: 0} | ||
} | ||
fmt.Println(m) // 0 | ||
if v, ok := m["1"]; ok { | ||
v.Count += 10 | ||
} | ||
fmt.Println(m["1"].Count) // 10 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2024 BINARY Members | ||
// | ||
// 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 model | ||
|
||
import "gorm.io/gorm" | ||
|
||
type AnalyzedOrgContribution struct { | ||
gorm.Model | ||
|
||
Login string | ||
NodeID string | ||
|
||
OrgLogin string | ||
OrgNodeID string | ||
|
||
Contributions int | ||
} | ||
|
||
type AnalyzedGroupContribution struct { | ||
gorm.Model | ||
|
||
Login string | ||
NodeID string | ||
|
||
GroupName string | ||
|
||
Contributions int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 BINARY Members | ||
// | ||
// 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 storage | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/B1NARY-GR0UP/openalysis/model" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func CreateAnalyzedOrgContributions(ctx context.Context, db *gorm.DB, contributions map[string]model.AnalyzedOrgContribution) error { | ||
if len(contributions) == 0 { | ||
return nil | ||
} | ||
var cs []model.AnalyzedOrgContribution | ||
for _, contribution := range contributions { | ||
cs = append(cs, contribution) | ||
} | ||
return db.WithContext(ctx).Create(&cs).Error | ||
} | ||
|
||
func CreateAnalyzedGroupContributions(ctx context.Context, db *gorm.DB, contributions map[string]model.AnalyzedGroupContribution) error { | ||
if len(contributions) == 0 { | ||
return nil | ||
} | ||
var cs []model.AnalyzedGroupContribution | ||
for _, contribution := range contributions { | ||
cs = append(cs, contribution) | ||
} | ||
return db.WithContext(ctx).Create(&cs).Error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters