Skip to content
This repository was archived by the owner on Sep 6, 2025. It is now read-only.

Commit 9ba97c1

Browse files
authored
Merge pull request #2 from hellofresh/feature/create-test-repo
Added new create test command
2 parents 7cdf318 + 78232a7 commit 9ba97c1

File tree

9 files changed

+305
-136
lines changed

9 files changed

+305
-136
lines changed

.github.sample.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Defines the application log level
22
LogLevel="debug"
33

4+
# Where your public ssh key that is registered on Github is. By default it
5+
# looks in your ssh folder for a file called `id_rsa`
6+
# PublicKeyPath = ~/.ssh/id_rsa
7+
48
[pullapprove]
59
# Defines the pull approve organization
610
Token=""
@@ -16,8 +20,11 @@ LogLevel="debug"
1620
# Defines the github token
1721
Token=""
1822

19-
# Defines permissions on the repo per team. The possible permission values are `pull`, `push` and `admin`
20-
# and they are defined on github's API
23+
# Defines permission specifies the permission to grant the user on this repository.
24+
# Possible values are:
25+
# pull - team members can pull, but not push to or administer this repository
26+
# push - team members can pull and push, but not administer this repository
27+
# admin - team members can pull, push and administer this repository
2128
Teams=[
2229
#Example
2330
{ID=1234, Permission='pull'},

Gopkg.lock

Lines changed: 57 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@
3131
[[constraint]]
3232
name = "github.com/spf13/viper"
3333
version = "1.0.0"
34+
35+
[[constraint]]
36+
name = "gopkg.in/src-d/go-git.v4"
37+
revision = "f9879dd043f84936a1f8acb8a53b74332a7ae135"

README.md

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,12 @@ After you have *github-cli* up and running we can create our first repository.
2121
First of all we have to create a configuration file that will customize how our repositories will be created. You can have a look on our [example](.github.sample.toml).
2222
This file can be placed on the same folder as your binary is, or in your home directory and it should be named `.github.toml` (You can also use it as `yaml` or `json`).
2323

24-
Let's see how we can create a new repo:
25-
26-
```sh
27-
github-cli create
28-
```
29-
30-
This command will create a new github repository following the rules defined on the configuration file.
31-
32-
```sh
33-
Please enter the repository name: github-cli
34-
Please enter the org name:
35-
36-
INFO[0000] Creating repository...
37-
INFO[0001] Adding pull approve...
38-
INFO[0003] Adding teams to repository...
39-
INFO[0004] Adding labels to repository...
40-
INFO[0007] Adding branch protections to repository...
41-
INFO[0007] Repository created!
42-
```
43-
44-
## Flags
45-
46-
You can always customize the repo creation with flags:
47-
48-
```
49-
--add-branch-protections Enables branch protections (default true)
50-
--add-default-labels Removes the default github labels (default true)
51-
--add-lables Enable labels (default true)
52-
--add-pullapprove Enables pull approve (default true)
53-
--add-teams Enable teams (default true)
54-
--add-webhooks Enables webhooks configurations (default true)
55-
```
24+
### Commands
25+
26+
| Command | Description |
27+
|--------------------------|--------------------------------------|
28+
| `github-cli create-repo` | Creates a new github repository |
29+
| `github-cli create-test` | Creates a new hellofresh hiring test |
5630

5731
## Contributing
5832

cmd/create.go renamed to cmd/create_repo.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import (
66

77
"github.com/deiwin/interact"
88
"github.com/hellofresh/github-cli/pkg/pullapprove"
9-
10-
"github.com/hellofresh/github-cli/pkg/github"
9+
"github.com/hellofresh/github-cli/pkg/repo"
1110
log "github.com/sirupsen/logrus"
1211
"github.com/spf13/cobra"
1312
)
@@ -36,7 +35,8 @@ var (
3635
}
3736
)
3837

39-
func RunCreate(cmd *cobra.Command, args []string) {
38+
// RunCreateRepo runs the command to create a new repository
39+
func RunCreateRepo(cmd *cobra.Command, args []string) {
4040
var err error
4141

4242
actor := interact.NewActor(os.Stdin, os.Stdout)
@@ -50,43 +50,38 @@ func RunCreate(cmd *cobra.Command, args []string) {
5050
log.Fatal(err)
5151
}
5252

53-
opts := &github.HelloFreshRepoOpt{
54-
Token: globalConfig.Github.Token,
53+
opts := &repo.HelloFreshRepoOpt{
54+
Name: repoName,
55+
Org: org,
5556
Private: createRepoFlags.Private,
56-
PullApprove: &github.PullApproveRule{
57+
PullApprove: &repo.PullApproveRule{
5758
Enabled: createRepoFlags.HasPullApprove,
5859
Filename: globalConfig.PullApprove.Filename,
5960
ProtectedBranchName: globalConfig.PullApprove.ProtectedBranchName,
6061
Client: pullapprove.New(globalConfig.PullApprove.Token),
6162
},
62-
Labels: &github.LabelsRule{
63+
Labels: &repo.LabelsRule{
6364
Enabled: createRepoFlags.HasLabels,
6465
RemoveDefaultLabels: globalConfig.Github.RemoveDefaultLabels,
6566
Labels: globalConfig.Github.Labels,
6667
},
67-
Teams: &github.TeamsRule{
68+
Teams: &repo.TeamsRule{
6869
Enabled: createRepoFlags.HasTeams,
6970
Teams: globalConfig.Github.Teams,
7071
},
71-
Webhooks: &github.WebhooksRule{
72+
Webhooks: &repo.WebhooksRule{
7273
Enabled: createRepoFlags.HasWebhooks,
7374
Webhooks: globalConfig.Github.Webhooks,
7475
},
75-
BranchProtections: &github.BranchProtectionsRule{
76+
BranchProtections: &repo.BranchProtectionsRule{
7677
Enabled: createRepoFlags.HasBranchProtections,
7778
Protections: globalConfig.Github.Protections,
7879
},
7980
}
8081

81-
creator, err := github.NewHelloFreshRepoCreator(repoName, org, opts)
82-
if err != nil {
83-
log.WithError(err).Error("Could not create github client")
84-
os.Exit(1)
85-
}
86-
87-
err = creator.Create()
82+
creator := repo.NewGithub(githubClient)
83+
err = creator.Create(opts)
8884
if err != nil {
89-
log.WithError(err).Error("Could not create github repo")
90-
os.Exit(1)
85+
log.WithError(err).Fatal("Could not create github repo")
9186
}
9287
}

0 commit comments

Comments
 (0)