Skip to content

Commit 7c84e4b

Browse files
authored
Merge pull request #7 from lyleshaw/main
[fix] fix circle import
2 parents 5b617cd + f036d41 commit 7c84e4b

File tree

9 files changed

+109
-23
lines changed

9 files changed

+109
-23
lines changed

.github/workflows/.build-docker.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
build:
10+
name: Build
11+
runs-on: ubuntu-latest
12+
environment: cr-bot-build-docker
13+
env:
14+
GO111MODULE: on
15+
steps:
16+
- name: Check out code into the Go module directory
17+
uses: actions/checkout@v2
18+
- name: Set up Go 1.17
19+
uses: actions/setup-go@v2
20+
with:
21+
go-version: 1.17
22+
- name: Login Resigtry
23+
if: github.event_name == 'push'
24+
run: |
25+
echo ${{ secrets.REGISTRY_PASSWORD }} | docker login ccr.ccs.tencentyun.com -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
26+
- name: Build
27+
run: |
28+
echo "LarkAppId= ${{ secrets.LARKAPPID }} " > .env
29+
echo "LarkAppSecret= ${{ secrets.LARKAPPSECRET }} " >> .env
30+
echo "VerificationToken= ${{ secrets.VERIFICATIONTOKEN }} " >> .env
31+
echo "EncryptKey= ${{ secrets.ENCRYPTKEY }} " >> .env
32+
33+
docker build -t ccr.ccs.tencentyun.com/lyle/cr-bot -f ./Dockerfile .
34+
docker push ccr.ccs.tencentyun.com/lyle/cr-bot:latest

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
.env
88
.idea
99
.DS_Store
10-
common.yaml
1110

1211
# Test binary, built with `go test -c`
1312
*.test

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ARG GO_VERSION=1.17
2+
3+
FROM golang:${GO_VERSION}-alpine AS builder
4+
5+
RUN apk update && apk add alpine-sdk git && rm -rf /var/cache/apk/*
6+
7+
RUN mkdir -p /builder
8+
WORKDIR /builder
9+
10+
COPY go.mod .
11+
COPY go.sum .
12+
RUN go mod download
13+
14+
COPY . .
15+
RUN go build -o ./server ./cmd/main.go
16+
17+
FROM alpine:latest
18+
19+
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
20+
21+
WORKDIR /
22+
COPY --from=builder /builder/server .
23+
COPY --from=builder /builder/common.yaml .
24+
COPY --from=builder /builder/.env .
25+
26+
EXPOSE 9000

cmd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func main() {
3535
router.POST("/api/lark/callback", lark.Callback)
3636
router.POST("/api/lark/cardCallback", lark.CardCallback)
3737

38-
err := router.Run(":3000")
38+
err := router.Run(":9000")
3939
if err != nil {
4040
return
4141
}

common.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
tasks:
2+
- name: "Task 1"
3+
repo: lyleshaw/repoTest
4+
repoType: github
5+
receiver: oc_3f96455148ce46f993da675c96548812
6+
pushChannel: lark
7+
- name: "Task 2"
8+
repo: lyleshaw/gobestpractice
9+
repoType: github
10+
receiver: oc_3f96455148ce46f993da675c96548812
11+
pushChannel: lark
12+
maps:
13+
- name: "1"
14+
github: lyleshaw
15+
lark: ou_c1cf4cfa9f0b25110808eeb649422fca
16+
role: member
17+
boss: 0
18+
- name: "2"
19+
github: wyqw0522
20+
lark: ou_0f89e919a57dcf16d8c5fdcee68b4161
21+
role: contributor
22+
boss: lyleshaw
23+
scheduler:
24+
- timeUnread1: 30
25+
- timeUnread2: 30
26+
- timeUnread3: 660
27+
- commentUnread: 60

internal/pkg/config/config.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ import (
55
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/constants"
66
"gopkg.in/yaml.v2"
77
"io/ioutil"
8+
"time"
89
)
910

1011
var (
11-
Cfg *Config
12-
LarkMaps map[string]Maps
13-
MsgQueue map[string]constants.MsgType
12+
Cfg *Config
13+
LarkMaps map[string]Maps
14+
MsgQueue map[string]constants.MsgType
15+
TimeUnread1 time.Duration // PR/Issue 消息第一次发送消息后若未读,经过 TimeUnread1 后重发
16+
TimeUnread2 time.Duration // PR/Issue 消息第二次发送消息后若未读,经过 TimeUnread2 后发送给上级
17+
TimeUnread3 time.Duration // PR/Issue 消息第三次发送消息后若未读,经过 TimeUnread3 后抄送群聊
18+
CommentUnread time.Duration // Comment 消息第一次发送后若未读,经过 CommentUnread 后抄送群聊
19+
1420
)
1521

1622
type Config struct {
@@ -59,6 +65,12 @@ func InitConfig() {
5965
for _, i := range Cfg.Maps {
6066
LarkMaps[i.Github] = i
6167
}
68+
69+
TimeUnread1 = time.Duration(Cfg.Scheduler.TimeUnread1) * time.Minute // PR/Issue 消息第一次发送消息后若未读,经过 TimeUnread1 后重发
70+
TimeUnread2 = time.Duration(Cfg.Scheduler.TimeUnread2) * time.Minute // PR/Issue 消息第二次发送消息后若未读,经过 TimeUnread2 后发送给上级
71+
TimeUnread3 = time.Duration(Cfg.Scheduler.TimeUnread3) * time.Minute // PR/Issue 消息第三次发送消息后若未读,经过 TimeUnread3 后抄送群聊
72+
CommentUnread = time.Duration(Cfg.Scheduler.CommentUnread) * time.Minute // Comment 消息第一次发送后若未读,经过 CommentUnread 后抄送群聊
73+
6274
}
6375

6476
func QueryReceiveIDByRepo(repo string) (string, error) {

internal/pkg/constants/constants.go

-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package constants
22

3-
import (
4-
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/config"
5-
"time"
6-
)
7-
83
type MsgType int
94

105
const (
@@ -13,10 +8,3 @@ const (
138
Unread2 MsgType = 2
149
Unread3 MsgType = 3
1510
)
16-
17-
var (
18-
TimeUnread1 = time.Duration(config.Cfg.Scheduler.TimeUnread1) * time.Minute // PR/Issue 消息第一次发送消息后若未读,经过 TimeUnread1 后重发
19-
TimeUnread2 = time.Duration(config.Cfg.Scheduler.TimeUnread2) * time.Minute // PR/Issue 消息第二次发送消息后若未读,经过 TimeUnread2 后发送给上级
20-
TimeUnread3 = time.Duration(config.Cfg.Scheduler.TimeUnread3) * time.Minute // PR/Issue 消息第三次发送消息后若未读,经过 TimeUnread3 后抄送群聊
21-
CommentUnread = time.Duration(config.Cfg.Scheduler.CommentUnread) * time.Minute // Comment 消息第一次发送后若未读,经过 CommentUnread 后抄送群聊
22-
)

internal/pkg/eventListener/eventListener.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func GitHubWebHook(c *gin.Context) {
129129
}
130130

131131
// 定时未读则转发群聊
132-
time.AfterFunc(constants.CommentUnread, func() {
132+
time.AfterFunc(config.CommentUnread, func() {
133133
issueCommentMsg = lark.MsgTemplateUpgrade(issueCommentMsg)
134134
for _, receiver := range atPeople {
135135
if _, ok := config.MsgQueue[receiver+number+string(gitHubEvent)]; ok {
@@ -325,7 +325,7 @@ func GitHubWebHook(c *gin.Context) {
325325
}
326326

327327
// 定时未读则转发群聊
328-
time.AfterFunc(constants.CommentUnread, func() {
328+
time.AfterFunc(config.CommentUnread, func() {
329329
prReviewMsg = lark.MsgTemplateUpgrade(prReviewMsg)
330330
for _, receiver := range atPeople {
331331
if _, ok := config.MsgQueue[receiver+number+string(gitHubEvent)]; ok {
@@ -412,7 +412,7 @@ func GitHubWebHook(c *gin.Context) {
412412
}
413413

414414
// 定时未读则转发群聊
415-
time.AfterFunc(constants.CommentUnread, func() {
415+
time.AfterFunc(config.CommentUnread, func() {
416416
prCommentMsg = lark.MsgTemplateUpgrade(prCommentMsg)
417417
for _, receiver := range atPeople {
418418
if _, ok := config.MsgQueue[receiver+number+string(gitHubEvent)]; ok {

internal/pkg/pushChannel/lark/message.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func SendMessages(receiveID string, receivers []string, msgTemplate string, numb
164164
}
165165
}
166166
// 设置定时任务
167-
time.AfterFunc(constants.TimeUnread1, func() {
167+
time.AfterFunc(config.TimeUnread1, func() {
168168
TimeCheck1(receiveID, receivers, msgTemplate, number, gitHubEvent)
169169
})
170170
}
@@ -189,7 +189,7 @@ func TimeCheck1(receiveID string, receivers []string, msgTemplate string, number
189189
}
190190
}
191191
// 设置定时任务
192-
time.AfterFunc(constants.TimeUnread2, func() {
192+
time.AfterFunc(config.TimeUnread2, func() {
193193
TimeCheck2(receiveID, receivers, msgTemplate, number, gitHubEvent)
194194
})
195195
}
@@ -223,7 +223,7 @@ func TimeCheck2(receiveID string, receivers []string, msgTemplate string, number
223223
}
224224
}
225225
// 设置定时任务
226-
time.AfterFunc(constants.TimeUnread3, func() {
226+
time.AfterFunc(config.TimeUnread3, func() {
227227
TimeCheck3(receiveID, receivers, msgTemplate, number, gitHubEvent)
228228
})
229229
}

0 commit comments

Comments
 (0)