-
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.
- Loading branch information
1 parent
100bd16
commit 68167a6
Showing
5 changed files
with
175 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var RootCmd = &cobra.Command{ | ||
Use: "gotcha", | ||
Short: "Pull Request Quality Reviewer", | ||
} | ||
|
||
// Starts the root-cli. | ||
func Execute() { | ||
if err := RootCmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/diegolnasc/gotcha/pkg/handler" | ||
c "github.com/diegolnasc/gotcha/pkg/model" | ||
|
||
g "github.com/diegolnasc/gotcha/pkg/provider/github" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
type Provider string | ||
|
||
const ( | ||
GitHub Provider = "github" | ||
) | ||
|
||
// Server command configuration. | ||
type config struct { | ||
providerWorker handler.ProviderWorker | ||
providerName Provider | ||
config c.Settings | ||
} | ||
|
||
// Returns the command cli | ||
func Init() *cobra.Command { | ||
c := &config{} | ||
return &cobra.Command{ | ||
Use: "server", | ||
Short: "Show the current version", | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
c.preRun() | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
c.providerWorker = g.New(&c.config) | ||
h := &handler.ServerHandler{ | ||
Config: c.config, | ||
ProviderWorker: c.providerWorker, | ||
} | ||
h.NewServer() | ||
}, | ||
} | ||
} | ||
|
||
func (c *config) preRun() { | ||
viper.SetConfigName("config") | ||
viper.SetConfigType("yaml") | ||
viper.AddConfigPath("./build") | ||
viper.ReadInConfig() | ||
viper.Unmarshal(&c.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Version configuration. | ||
type GotchaVersion struct { | ||
Version string | ||
} | ||
|
||
// Returns the command cli | ||
func (v *GotchaVersion) Init() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: "Show the current version", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Gotcha -> " + v.Version) | ||
}, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package cmd | ||
|
||
import "testing" | ||
|
||
func TestVersion(t *testing.T) { | ||
cmd := &GotchaVersion{Version: "test-1.0.0"} | ||
|
||
if err := cmd.Init().Execute(); err != nil { | ||
t.Errorf("unexpected return %s", err.Error()) | ||
t.FailNow() | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2021 Diego Lima. All rights reserved. | ||
|
||
// Use of this source code is governed by a Apache license. | ||
// license that can be found in the LICENSE file. | ||
|
||
package model | ||
|
||
// Settings represents the configuration and authorization aspects. | ||
type Settings struct { | ||
Layout Layout `yaml:"layout"` | ||
Github Github `yaml:"github"` | ||
} | ||
|
||
// Layout represents permissions level and pull request functionalities. | ||
type Layout struct { | ||
Administration Administration `yaml:"administration"` | ||
PullRequest PullRequest `yaml:"pullRequest"` | ||
} | ||
|
||
// Administration represents general permissions. | ||
type Administration struct { | ||
Permission Permission `yaml:"permission"` | ||
} | ||
|
||
// Permission represents high level user's and repository permissions. | ||
type Permission struct { | ||
Users []string `yaml:"users"` | ||
Repositories []Repositories `yaml:"repositories"` | ||
} | ||
|
||
// Repositories represents low level permissions in repositories. | ||
type Repositories struct { | ||
Repository Repository `yaml:"repository"` | ||
} | ||
|
||
// Repository represents user permission in a single repository. | ||
type Repository struct { | ||
Name string `yaml:"name"` | ||
Users []string `yaml:"users"` | ||
} | ||
|
||
// PullRequest represents commands and functionalities. | ||
type PullRequest struct { | ||
EnableOverview bool `yaml:"enableOverview"` | ||
OverViewCommand string `yaml:"overViewCommand"` | ||
ApproveCommand string `yaml:"approveCommand"` | ||
RunTestSuiteCommand string `yaml:"runTestSuiteCommand"` | ||
MergeCommand string `yaml:"mergeCommand"` | ||
MergeAndDeleteCommand string `yaml:"mergeAndDeleteCommand"` | ||
TestSuite TestSuite `yaml:"testSuite"` | ||
} | ||
|
||
// TestSuite represents configuration for the test cases. | ||
type TestSuite struct { | ||
NamePattern string `yaml:"namePattern"` | ||
Reviewers bool `yaml:"reviewers"` | ||
Assignees bool `yaml:"assignees"` | ||
Labels bool `yaml:"labels"` | ||
} | ||
|
||
// Github represents github app owner configuration. | ||
type Github struct { | ||
AppID int `yaml:"appId"` | ||
Organization string `yaml:"organization"` | ||
User string `yaml:"user"` | ||
WebhookSecret string `yaml:"webhookSecret"` | ||
PrivateKeyLocation string `yaml:"privateKeyLocation"` | ||
PrivateKey string `yaml:"privateKey"` | ||
Events []string `yaml:"events"` | ||
} |