Skip to content
This repository was archived by the owner on Aug 26, 2023. It is now read-only.

Commit ef85a32

Browse files
authored
feature(main): add pr comment code (#12)
Signed-off-by: cuisongliu <cuisongliu@qq.com>
1 parent c6bc0b9 commit ef85a32

File tree

18 files changed

+404
-174
lines changed

18 files changed

+404
-174
lines changed

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ RUN apk --no-cache add jq bash curl git git-lfs github-cli
88

99
COPY gh-rebot /usr/bin/
1010

11-
ENTRYPOINT ["/usr/bin/gh-rebot"]
12-
13-
CMD ["--help"]
11+
ENTRYPOINT ["/usr/bin/gh-rebot","action"]

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: "Gh Rebot for Sealos"
2+
description: "Add some rebot command for sealos"
3+
author: "cuisongliu"
4+
runs:
5+
using: 'docker'
6+
image: 'Dockerfile'
7+
branding:
8+
icon: 'git-pull-request'
9+
color: 'green'

cmd/action.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"github.com/cuisongliu/logger"
9+
"github.com/labring/gh-rebot/pkg/action"
10+
"github.com/labring/gh-rebot/pkg/setup"
11+
"os"
12+
13+
"github.com/spf13/cobra"
14+
)
15+
16+
// actionCmd represents the action command
17+
var actionCmd = &cobra.Command{
18+
Use: "action",
19+
Run: func(cmd *cobra.Command, args []string) {
20+
actionType, err := action.GetEnvFromAction("type")
21+
if err != nil {
22+
logger.Error(err)
23+
os.Exit(1)
24+
}
25+
switch actionType {
26+
case "/comment":
27+
err = action.CommentEngine()
28+
case "pr_comment":
29+
err = action.PRComment()
30+
default:
31+
err = fmt.Errorf("not support action type")
32+
}
33+
if err != nil {
34+
logger.Error(err)
35+
os.Exit(1)
36+
}
37+
},
38+
}
39+
40+
func init() {
41+
cobra.OnInitialize(func() {
42+
setup.Setup(cfgFile)
43+
})
44+
rootCmd.AddCommand(actionCmd)
45+
46+
// Here you will define your flags and configuration settings.
47+
48+
// Cobra supports Persistent Flags which will work for this command
49+
// and all subcommands, e.g.:
50+
// actionCmd.PersistentFlags().String("foo", "", "A help for foo")
51+
52+
// Cobra supports local flags which will only run when this command
53+
// is called directly, e.g.:
54+
// actionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
55+
}

cmd/comment.go

Lines changed: 0 additions & 74 deletions
This file was deleted.

cmd/webhook.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package cmd
55

66
import (
77
"github.com/cuisongliu/logger"
8+
"github.com/labring/gh-rebot/pkg/setup"
89
"github.com/labring/gh-rebot/pkg/webhook"
910

1011
"github.com/spf13/cobra"
@@ -23,7 +24,7 @@ var webhookCmd = &cobra.Command{
2324

2425
func init() {
2526
cobra.OnInitialize(func() {
26-
checkToken()
27+
setup.Setup(cfgFile)
2728
})
2829
rootCmd.AddCommand(webhookCmd)
2930

go.mod

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,29 @@ require (
1111
github.com/gin-gonic/gin v1.9.0
1212
github.com/gorilla/websocket v1.5.0
1313
github.com/hashicorp/go-version v1.6.0
14-
github.com/onsi/ginkgo v1.16.5
15-
github.com/onsi/gomega v1.23.0
1614
github.com/pkg/errors v0.9.1
1715
github.com/spf13/cobra v1.6.1
1816
k8s.io/apimachinery v0.26.2
19-
k8s.io/client-go v0.26.2
2017
sigs.k8s.io/yaml v1.3.0
2118
)
2219

23-
require k8s.io/api v0.26.2
20+
require (
21+
github.com/google/go-github/v39 v39.2.0
22+
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b
23+
sigs.k8s.io/kustomize/kyaml v0.14.2
24+
)
2425

2526
require (
2627
github.com/Masterminds/goutils v1.1.1 // indirect
2728
github.com/bytedance/sonic v1.8.0 // indirect
2829
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
2930
github.com/davecgh/go-spew v1.1.1 // indirect
30-
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
31-
github.com/fsnotify/fsnotify v1.4.9 // indirect
3231
github.com/gin-contrib/sse v0.1.0 // indirect
32+
github.com/go-errors/errors v1.4.2 // indirect
3333
github.com/go-logr/logr v1.2.3 // indirect
34-
github.com/go-openapi/jsonpointer v0.19.5 // indirect
35-
github.com/go-openapi/jsonreference v0.20.0 // indirect
36-
github.com/go-openapi/swag v0.19.14 // indirect
34+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
35+
github.com/go-openapi/jsonreference v0.20.1 // indirect
36+
github.com/go-openapi/swag v0.22.3 // indirect
3737
github.com/go-playground/locales v0.14.1 // indirect
3838
github.com/go-playground/universal-translator v0.18.1 // indirect
3939
github.com/go-playground/validator/v10 v10.11.2 // indirect
@@ -42,6 +42,7 @@ require (
4242
github.com/golang/protobuf v1.5.2 // indirect
4343
github.com/google/gnostic v0.5.7-v3refs // indirect
4444
github.com/google/go-cmp v0.5.9 // indirect
45+
github.com/google/go-querystring v1.1.0 // indirect
4546
github.com/google/gofuzz v1.1.0 // indirect
4647
github.com/google/uuid v1.1.2 // indirect
4748
github.com/huandu/xstrings v1.3.3 // indirect
@@ -51,14 +52,12 @@ require (
5152
github.com/json-iterator/go v1.1.12 // indirect
5253
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
5354
github.com/leodido/go-urn v1.2.1 // indirect
54-
github.com/mailru/easyjson v0.7.6 // indirect
55+
github.com/mailru/easyjson v0.7.7 // indirect
5556
github.com/mattn/go-isatty v0.0.17 // indirect
5657
github.com/mitchellh/copystructure v1.0.0 // indirect
5758
github.com/mitchellh/reflectwalk v1.0.0 // indirect
5859
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
5960
github.com/modern-go/reflect2 v1.0.2 // indirect
60-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
61-
github.com/nxadm/tail v1.4.8 // indirect
6261
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
6362
github.com/shopspring/decimal v1.2.0 // indirect
6463
github.com/spf13/cast v1.3.1 // indirect
@@ -68,19 +67,15 @@ require (
6867
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
6968
golang.org/x/crypto v0.5.0 // indirect
7069
golang.org/x/net v0.7.0 // indirect
71-
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
7270
golang.org/x/sys v0.5.0 // indirect
73-
golang.org/x/term v0.5.0 // indirect
7471
golang.org/x/text v0.7.0 // indirect
75-
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
7672
google.golang.org/appengine v1.6.7 // indirect
7773
google.golang.org/protobuf v1.28.1 // indirect
7874
gopkg.in/inf.v0 v0.9.1 // indirect
79-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
8075
gopkg.in/yaml.v2 v2.4.0 // indirect
8176
gopkg.in/yaml.v3 v3.0.1 // indirect
8277
k8s.io/klog/v2 v2.80.1 // indirect
83-
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
78+
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 // indirect
8479
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
8580
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
8681
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect

0 commit comments

Comments
 (0)