-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor to support gitlab version < 13
- Loading branch information
Showing
22 changed files
with
804 additions
and
776 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,6 @@ | |
|
||
gitlab review-bot | ||
|
||
## Preconditions | ||
- Gitlab version 13+ | ||
|
||
## Quick start | ||
|
||
### Config | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
/* | ||
Copyright © 2021 zc2638 <[email protected]>. | ||
// Copyright © 2021 zc2638 <[email protected]>. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package app | ||
|
||
import ( | ||
|
@@ -35,27 +34,25 @@ func NewServerCommand() *cobra.Command { | |
Short: "review bot", | ||
Long: `Review Bot.`, | ||
SilenceUsage: true, | ||
RunE: run, | ||
RunE: func(_ *cobra.Command, _ []string) error { | ||
cfg := global.Environ() | ||
if err := server.ParseConfigWithEnv(cfgFile, cfg, global.EnvPrefix); err != nil { | ||
return err | ||
} | ||
if err := global.InitCfg(cfg); err != nil { | ||
return err | ||
} | ||
s := server.New(&cfg.Server) | ||
s.Handler = handler.New() | ||
fmt.Println("Listen on", s.Addr) | ||
return s.Run(context.Background()) | ||
}, | ||
} | ||
|
||
cfgFilePath := os.Getenv(global.EnvPrefix + "_CONFIG") | ||
if cfgFilePath == "" { | ||
cfgFilePath = "config/config.yaml" | ||
} | ||
cmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", cfgFilePath, "config file (default is $HOME/config.yaml)") | ||
return cmd | ||
} | ||
|
||
func run(cmd *cobra.Command, args []string) error { | ||
ctx := context.Background() | ||
cfg, err := global.ParseConfig(cfgFile) | ||
if err != nil { | ||
return err | ||
} | ||
if err := global.InitCfg(cfg); err != nil { | ||
return err | ||
} | ||
s := server.New(&cfg.Server) | ||
s.Handler = handler.New() | ||
fmt.Println("Listen on", s.Addr) | ||
return s.Run(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
/* | ||
Copyright © 2021 zc2638 <[email protected]>. | ||
// Copyright © 2021 zc2638 <[email protected]>. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package main | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
/* | ||
Copyright © 2021 zc2638 <[email protected]>. | ||
// Copyright © 2021 zc2638 <[email protected]>. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package global | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/mitchellh/go-homedir" | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/pkgms/go/server" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/zc2638/review-bot/pkg/scm" | ||
) | ||
|
@@ -48,32 +40,3 @@ func Environ() *Config { | |
cfg.SCM.Type = "gitlab" | ||
return cfg | ||
} | ||
|
||
func ParseConfig(cfgPath string) (*Config, error) { | ||
if cfgPath != "" { | ||
viper.SetConfigFile(cfgPath) | ||
} else { | ||
home, err := homedir.Dir() | ||
if err != nil { | ||
return nil, err | ||
} | ||
viper.AddConfigPath(home) | ||
viper.SetConfigName("config.yaml") | ||
} | ||
viper.SetEnvPrefix(EnvPrefix) | ||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) | ||
viper.AutomaticEnv() | ||
cfg := Environ() | ||
if err := viper.ReadInConfig(); err != nil { | ||
if _, ok := err.(*os.PathError); ok { | ||
fmt.Println("Warning: not find config file, use default.") | ||
return cfg, nil | ||
} | ||
return nil, err | ||
} | ||
fmt.Println("Using config file:", viper.ConfigFileUsed()) | ||
err := viper.Unmarshal(cfg, func(dc *mapstructure.DecoderConfig) { | ||
dc.TagName = "json" | ||
}) | ||
return cfg, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
/* | ||
Copyright © 2021 zc2638 <[email protected]>. | ||
// Copyright © 2021 zc2638 <[email protected]>. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package global | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
/* | ||
Copyright © 2021 zc2638 <[email protected]>. | ||
// Copyright © 2021 zc2638 <[email protected]>. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package home | ||
|
||
import ( | ||
|
@@ -22,8 +21,6 @@ import ( | |
"github.com/zc2638/swag/swagger" | ||
) | ||
|
||
const tag = "home" | ||
|
||
func Register(doc *swagger.API) { | ||
doc.AddEndpoint( | ||
endpoint.New( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
/** | ||
* Created by zc on 2021/1/15. | ||
*/ | ||
// Copyright © 2021 zc2638 <[email protected]>. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package home | ||
|
||
import ( | ||
|
Oops, something went wrong.