Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LarkAppId=cli_xxx
LarkAppSecret=xxx
VerificationToken=xxx
EncryptKey=xxx
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
*.dll
*.so
*.dylib
.env
.idea
.DS_Store
common.yaml

# Test binary, built with `go test -c`
*.test
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# ospp-cr-bot

开源之夏 - 一种通用的 Code Review 机器人
43 changes: 43 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"github.com/gin-gonic/gin"
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/config"
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/constants"
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/eventListener"
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/pushChannel/lark"
"github.com/lyleshaw/ospp-cr-bot/pkg/utils/log"
"github.com/sirupsen/logrus"
)

var (
isDebug bool
)

func init() {
initLog()
config.InitConfig()
config.MsgQueue = make(map[string]constants.MsgType)
}

func initLog() {
if isDebug {
logrus.SetLevel(logrus.DebugLevel)
log.Infof("Log level is: %s.", logrus.GetLevel())
} else {
logrus.SetLevel(logrus.InfoLevel)
}
}

func main() {
router := gin.Default()
router.POST("/github/webhook", eventListener.GitHubWebHook)
router.POST("/api/lark/callback", lark.Callback)
router.POST("/api/lark/cardCallback", lark.CardCallback)

err := router.Run(":3000")
if err != nil {
return
}
return
}
18 changes: 18 additions & 0 deletions common.yaml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tasks:
- name: "Task 1"
repo: lyleshaw/repoTest
repoType: github
receiver: oc_xxxxxxxx
pushChannel: lark

maps:
- name: "1"
github: lyleshaw
lark: ou_xxxxxx
role: member
boss: 0
- name: "2"
github: abc
lark: ou_xxxxxx
role: contributor
boss: lyleshaw
46 changes: 46 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module github.com/lyleshaw/ospp-cr-bot

go 1.17

require (
github.com/faabiosr/cachego v0.15.0
github.com/fastwego/feishu v1.0.0-beta.4
github.com/gin-gonic/gin v1.7.7
github.com/sirupsen/logrus v1.8.1
github.com/spf13/viper v1.11.0
github.com/valyala/fasttemplate v1.2.1
gopkg.in/gookit/color.v1 v1.1.6
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
874 changes: 874 additions & 0 deletions go.sum

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package config

import (
"fmt"
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/constants"
"gopkg.in/yaml.v2"
"io/ioutil"
)

var (
Cfg *Config
LarkMaps map[string]Maps
MsgQueue map[string]constants.MsgType
)

type Config struct {
Tasks []Tasks `yaml:"tasks"`
Maps []Maps `yaml:"maps"`
}
type Tasks struct {
Name string `yaml:"name"`
Repo string `yaml:"repo"`
Receiver string `yaml:"receiver"`
ReceiverType string `yaml:"receiverType"`
PushChannel string `yaml:"pushChannel"`
}

type Maps struct {
Github string `yaml:"github"`
Lark string `yaml:"lark"`
Role string `yaml:"role"`
Boss string `yaml:"boss"`
}

func InitConfig() {
config, err := ioutil.ReadFile("./common.yaml")
if err != nil {
fmt.Print(err)
}

err = yaml.Unmarshal(config, &Cfg)
if err != nil {
fmt.Println("error")
}

if err != nil {
fmt.Println("error")
}

LarkMaps = make(map[string]Maps)
for _, i := range Cfg.Maps {
LarkMaps[i.Github] = i
}
}

func QueryReceiveIDByRepo(repo string) (string, error) {
for _, task := range Cfg.Tasks {
if task.Repo == repo {
return task.Receiver, nil
}
}
return "", fmt.Errorf("repo not found")
}

func QueryGithubIdByLarkId(larkId string) (string, error) {
for _, i := range Cfg.Maps {
if i.Lark == larkId {
return i.Github, nil
}
}
return "", fmt.Errorf("larkId not found")
}
19 changes: 19 additions & 0 deletions internal/pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package constants

import "time"

type MsgType int

const (
READ MsgType = 0
Unread1 MsgType = 1
Unread2 MsgType = 2
Unread3 MsgType = 3
)

const (
TimeUnread1 = 30 * time.Minute // PR/Issue 消息第一次发送消息后若未读,经过 TimeUnread1 后重发
TimeUnread2 = 30 * time.Minute // PR/Issue 消息第二次发送消息后若未读,经过 TimeUnread2 后发送给上级
TimeUnread3 = 11 * time.Hour // PR/Issue 消息第三次发送消息后若未读,经过 TimeUnread3 后抄送群聊
CommentUnread = 1 * time.Hour // Comment 消息第一次发送后若未读,经过 CommentUnread 后抄送群聊
)
Loading