Skip to content

Commit

Permalink
Merge pull request #7 from lyleshaw/main
Browse files Browse the repository at this point in the history
[fix] fix circle import
  • Loading branch information
daniel-hutao authored Sep 29, 2022
2 parents 5b617cd + f036d41 commit 7c84e4b
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 23 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/.build-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Go

on:
push:
branches:
- "main"

jobs:
build:
name: Build
runs-on: ubuntu-latest
environment: cr-bot-build-docker
env:
GO111MODULE: on
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set up Go 1.17
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Login Resigtry
if: github.event_name == 'push'
run: |
echo ${{ secrets.REGISTRY_PASSWORD }} | docker login ccr.ccs.tencentyun.com -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
- name: Build
run: |
echo "LarkAppId= ${{ secrets.LARKAPPID }} " > .env
echo "LarkAppSecret= ${{ secrets.LARKAPPSECRET }} " >> .env
echo "VerificationToken= ${{ secrets.VERIFICATIONTOKEN }} " >> .env
echo "EncryptKey= ${{ secrets.ENCRYPTKEY }} " >> .env
docker build -t ccr.ccs.tencentyun.com/lyle/cr-bot -f ./Dockerfile .
docker push ccr.ccs.tencentyun.com/lyle/cr-bot:latest
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
.env
.idea
.DS_Store
common.yaml

# Test binary, built with `go test -c`
*.test
Expand Down
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ARG GO_VERSION=1.17

FROM golang:${GO_VERSION}-alpine AS builder

RUN apk update && apk add alpine-sdk git && rm -rf /var/cache/apk/*

RUN mkdir -p /builder
WORKDIR /builder

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN go build -o ./server ./cmd/main.go

FROM alpine:latest

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

WORKDIR /
COPY --from=builder /builder/server .
COPY --from=builder /builder/common.yaml .
COPY --from=builder /builder/.env .

EXPOSE 9000
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func main() {
router.POST("/api/lark/callback", lark.Callback)
router.POST("/api/lark/cardCallback", lark.CardCallback)

err := router.Run(":3000")
err := router.Run(":9000")
if err != nil {
return
}
Expand Down
27 changes: 27 additions & 0 deletions common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
tasks:
- name: "Task 1"
repo: lyleshaw/repoTest
repoType: github
receiver: oc_3f96455148ce46f993da675c96548812
pushChannel: lark
- name: "Task 2"
repo: lyleshaw/gobestpractice
repoType: github
receiver: oc_3f96455148ce46f993da675c96548812
pushChannel: lark
maps:
- name: "1"
github: lyleshaw
lark: ou_c1cf4cfa9f0b25110808eeb649422fca
role: member
boss: 0
- name: "2"
github: wyqw0522
lark: ou_0f89e919a57dcf16d8c5fdcee68b4161
role: contributor
boss: lyleshaw
scheduler:
- timeUnread1: 30
- timeUnread2: 30
- timeUnread3: 660
- commentUnread: 60
18 changes: 15 additions & 3 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import (
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/constants"
"gopkg.in/yaml.v2"
"io/ioutil"
"time"
)

var (
Cfg *Config
LarkMaps map[string]Maps
MsgQueue map[string]constants.MsgType
Cfg *Config
LarkMaps map[string]Maps
MsgQueue map[string]constants.MsgType
TimeUnread1 time.Duration // PR/Issue 消息第一次发送消息后若未读,经过 TimeUnread1 后重发
TimeUnread2 time.Duration // PR/Issue 消息第二次发送消息后若未读,经过 TimeUnread2 后发送给上级
TimeUnread3 time.Duration // PR/Issue 消息第三次发送消息后若未读,经过 TimeUnread3 后抄送群聊
CommentUnread time.Duration // Comment 消息第一次发送后若未读,经过 CommentUnread 后抄送群聊

)

type Config struct {
Expand Down Expand Up @@ -59,6 +65,12 @@ func InitConfig() {
for _, i := range Cfg.Maps {
LarkMaps[i.Github] = i
}

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

}

func QueryReceiveIDByRepo(repo string) (string, error) {
Expand Down
12 changes: 0 additions & 12 deletions internal/pkg/constants/constants.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package constants

import (
"github.com/lyleshaw/ospp-cr-bot/internal/pkg/config"
"time"
)

type MsgType int

const (
Expand All @@ -13,10 +8,3 @@ const (
Unread2 MsgType = 2
Unread3 MsgType = 3
)

var (
TimeUnread1 = time.Duration(config.Cfg.Scheduler.TimeUnread1) * time.Minute // PR/Issue 消息第一次发送消息后若未读,经过 TimeUnread1 后重发
TimeUnread2 = time.Duration(config.Cfg.Scheduler.TimeUnread2) * time.Minute // PR/Issue 消息第二次发送消息后若未读,经过 TimeUnread2 后发送给上级
TimeUnread3 = time.Duration(config.Cfg.Scheduler.TimeUnread3) * time.Minute // PR/Issue 消息第三次发送消息后若未读,经过 TimeUnread3 后抄送群聊
CommentUnread = time.Duration(config.Cfg.Scheduler.CommentUnread) * time.Minute // Comment 消息第一次发送后若未读,经过 CommentUnread 后抄送群聊
)
6 changes: 3 additions & 3 deletions internal/pkg/eventListener/eventListener.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func GitHubWebHook(c *gin.Context) {
}

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

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

// 定时未读则转发群聊
time.AfterFunc(constants.CommentUnread, func() {
time.AfterFunc(config.CommentUnread, func() {
prCommentMsg = lark.MsgTemplateUpgrade(prCommentMsg)
for _, receiver := range atPeople {
if _, ok := config.MsgQueue[receiver+number+string(gitHubEvent)]; ok {
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/pushChannel/lark/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func SendMessages(receiveID string, receivers []string, msgTemplate string, numb
}
}
// 设置定时任务
time.AfterFunc(constants.TimeUnread1, func() {
time.AfterFunc(config.TimeUnread1, func() {
TimeCheck1(receiveID, receivers, msgTemplate, number, gitHubEvent)
})
}
Expand All @@ -189,7 +189,7 @@ func TimeCheck1(receiveID string, receivers []string, msgTemplate string, number
}
}
// 设置定时任务
time.AfterFunc(constants.TimeUnread2, func() {
time.AfterFunc(config.TimeUnread2, func() {
TimeCheck2(receiveID, receivers, msgTemplate, number, gitHubEvent)
})
}
Expand Down Expand Up @@ -223,7 +223,7 @@ func TimeCheck2(receiveID string, receivers []string, msgTemplate string, number
}
}
// 设置定时任务
time.AfterFunc(constants.TimeUnread3, func() {
time.AfterFunc(config.TimeUnread3, func() {
TimeCheck3(receiveID, receivers, msgTemplate, number, gitHubEvent)
})
}
Expand Down

0 comments on commit 7c84e4b

Please sign in to comment.