Skip to content

Commit 73d0c80

Browse files
authored
Merge pull request #4 from lyleshaw/main
[Feature] MVP 级功能实现
2 parents 9dca719 + bbdfa8a commit 73d0c80

File tree

25 files changed

+10109
-0
lines changed

25 files changed

+10109
-0
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
LarkAppId=cli_xxx
2+
LarkAppSecret=xxx
3+
VerificationToken=xxx
4+
EncryptKey=xxx

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
*.dll
55
*.so
66
*.dylib
7+
.env
8+
.idea
9+
.DS_Store
10+
common.yaml
711

812
# Test binary, built with `go test -c`
913
*.test

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# ospp-cr-bot
2+
23
开源之夏 - 一种通用的 Code Review 机器人

cmd/main.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package main
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/config"
6+
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/constants"
7+
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/eventListener"
8+
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/pushChannel/lark"
9+
"github.com/lyleshaw/ospp-cr-bot/pkg/utils/log"
10+
"github.com/sirupsen/logrus"
11+
)
12+
13+
var (
14+
isDebug bool
15+
)
16+
17+
func init() {
18+
initLog()
19+
config.InitConfig()
20+
config.MsgQueue = make(map[string]constants.MsgType)
21+
}
22+
23+
func initLog() {
24+
if isDebug {
25+
logrus.SetLevel(logrus.DebugLevel)
26+
log.Infof("Log level is: %s.", logrus.GetLevel())
27+
} else {
28+
logrus.SetLevel(logrus.InfoLevel)
29+
}
30+
}
31+
32+
func main() {
33+
router := gin.Default()
34+
router.POST("/github/webhook", eventListener.GitHubWebHook)
35+
router.POST("/api/lark/callback", lark.Callback)
36+
router.POST("/api/lark/cardCallback", lark.CardCallback)
37+
38+
err := router.Run(":3000")
39+
if err != nil {
40+
return
41+
}
42+
return
43+
}

common.yaml.example

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
tasks:
2+
- name: "Task 1"
3+
repo: lyleshaw/repoTest
4+
repoType: github
5+
receiver: oc_xxxxxxxx
6+
pushChannel: lark
7+
8+
maps:
9+
- name: "1"
10+
github: lyleshaw
11+
lark: ou_xxxxxx
12+
role: member
13+
boss: 0
14+
- name: "2"
15+
github: abc
16+
lark: ou_xxxxxx
17+
role: contributor
18+
boss: lyleshaw

go.mod

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module github.com/lyleshaw/ospp-cr-bot
2+
3+
go 1.17
4+
5+
require (
6+
github.com/faabiosr/cachego v0.15.0
7+
github.com/fastwego/feishu v1.0.0-beta.4
8+
github.com/gin-gonic/gin v1.7.7
9+
github.com/sirupsen/logrus v1.8.1
10+
github.com/spf13/viper v1.11.0
11+
github.com/valyala/fasttemplate v1.2.1
12+
gopkg.in/gookit/color.v1 v1.1.6
13+
gopkg.in/yaml.v2 v2.4.0
14+
)
15+
16+
require (
17+
github.com/fsnotify/fsnotify v1.5.1 // indirect
18+
github.com/gin-contrib/sse v0.1.0 // indirect
19+
github.com/go-playground/locales v0.13.0 // indirect
20+
github.com/go-playground/universal-translator v0.17.0 // indirect
21+
github.com/go-playground/validator/v10 v10.4.1 // indirect
22+
github.com/golang/protobuf v1.5.2 // indirect
23+
github.com/hashicorp/hcl v1.0.0 // indirect
24+
github.com/json-iterator/go v1.1.12 // indirect
25+
github.com/leodido/go-urn v1.2.0 // indirect
26+
github.com/magiconair/properties v1.8.6 // indirect
27+
github.com/mattn/go-isatty v0.0.14 // indirect
28+
github.com/mitchellh/mapstructure v1.4.3 // indirect
29+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
30+
github.com/modern-go/reflect2 v1.0.2 // indirect
31+
github.com/pelletier/go-toml v1.9.4 // indirect
32+
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
33+
github.com/spf13/afero v1.8.2 // indirect
34+
github.com/spf13/cast v1.4.1 // indirect
35+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
36+
github.com/spf13/pflag v1.0.5 // indirect
37+
github.com/subosito/gotenv v1.2.0 // indirect
38+
github.com/ugorji/go/codec v1.1.7 // indirect
39+
github.com/valyala/bytebufferpool v1.0.0 // indirect
40+
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
41+
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
42+
golang.org/x/text v0.3.7 // indirect
43+
google.golang.org/protobuf v1.28.0 // indirect
44+
gopkg.in/ini.v1 v1.66.4 // indirect
45+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
46+
)

go.sum

Lines changed: 874 additions & 0 deletions
Large diffs are not rendered by default.

internal/pkg/config/config.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package config
2+
3+
import (
4+
"fmt"
5+
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/constants"
6+
"gopkg.in/yaml.v2"
7+
"io/ioutil"
8+
)
9+
10+
var (
11+
Cfg *Config
12+
LarkMaps map[string]Maps
13+
MsgQueue map[string]constants.MsgType
14+
)
15+
16+
type Config struct {
17+
Tasks []Tasks `yaml:"tasks"`
18+
Maps []Maps `yaml:"maps"`
19+
}
20+
type Tasks struct {
21+
Name string `yaml:"name"`
22+
Repo string `yaml:"repo"`
23+
Receiver string `yaml:"receiver"`
24+
ReceiverType string `yaml:"receiverType"`
25+
PushChannel string `yaml:"pushChannel"`
26+
}
27+
28+
type Maps struct {
29+
Github string `yaml:"github"`
30+
Lark string `yaml:"lark"`
31+
Role string `yaml:"role"`
32+
Boss string `yaml:"boss"`
33+
}
34+
35+
func InitConfig() {
36+
config, err := ioutil.ReadFile("./common.yaml")
37+
if err != nil {
38+
fmt.Print(err)
39+
}
40+
41+
err = yaml.Unmarshal(config, &Cfg)
42+
if err != nil {
43+
fmt.Println("error")
44+
}
45+
46+
if err != nil {
47+
fmt.Println("error")
48+
}
49+
50+
LarkMaps = make(map[string]Maps)
51+
for _, i := range Cfg.Maps {
52+
LarkMaps[i.Github] = i
53+
}
54+
}
55+
56+
func QueryReceiveIDByRepo(repo string) (string, error) {
57+
for _, task := range Cfg.Tasks {
58+
if task.Repo == repo {
59+
return task.Receiver, nil
60+
}
61+
}
62+
return "", fmt.Errorf("repo not found")
63+
}
64+
65+
func QueryGithubIdByLarkId(larkId string) (string, error) {
66+
for _, i := range Cfg.Maps {
67+
if i.Lark == larkId {
68+
return i.Github, nil
69+
}
70+
}
71+
return "", fmt.Errorf("larkId not found")
72+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package constants
2+
3+
import "time"
4+
5+
type MsgType int
6+
7+
const (
8+
READ MsgType = 0
9+
Unread1 MsgType = 1
10+
Unread2 MsgType = 2
11+
Unread3 MsgType = 3
12+
)
13+
14+
const (
15+
TimeUnread1 = 30 * time.Minute // PR/Issue 消息第一次发送消息后若未读,经过 TimeUnread1 后重发
16+
TimeUnread2 = 30 * time.Minute // PR/Issue 消息第二次发送消息后若未读,经过 TimeUnread2 后发送给上级
17+
TimeUnread3 = 11 * time.Hour // PR/Issue 消息第三次发送消息后若未读,经过 TimeUnread3 后抄送群聊
18+
CommentUnread = 1 * time.Hour // Comment 消息第一次发送后若未读,经过 CommentUnread 后抄送群聊
19+
)

0 commit comments

Comments
 (0)