Skip to content

Commit 59892a5

Browse files
committed
Create Repo / Org make --forge-type optional
* This makes gitea garm usage unnessary complex
1 parent 18ef27b commit 59892a5

4 files changed

Lines changed: 38 additions & 4 deletions

File tree

cmd/garm-cli/cmd/common.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cmd
2+
3+
import (
4+
"github.com/cloudbase/garm/client/credentials"
5+
"github.com/cloudbase/garm/params"
6+
)
7+
8+
func queryForgeType(credentialName string) error {
9+
if forgeType == "" {
10+
// TODO do this on server?, where we can query by Name
11+
list, err := apiCli.Credentials.ListGiteaCredentials(&credentials.ListGiteaCredentialsParams{}, authToken)
12+
if err != nil {
13+
return err
14+
}
15+
for _, cred := range list.Payload {
16+
if cred.Name == credentialName {
17+
forgeType = string(params.GiteaEndpointType)
18+
break
19+
}
20+
}
21+
// TODO should we validate that an GitHub endpoint exists?
22+
if forgeType == "" {
23+
forgeType = string(params.GithubEndpointType)
24+
}
25+
}
26+
return nil
27+
}

cmd/garm-cli/cmd/organization.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ var orgAddCmd = &cobra.Command{
163163
orgWebhookSecret = secret
164164
}
165165

166+
if err := queryForgeType(orgCreds); err != nil {
167+
return fmt.Errorf("failed to query forge type: %w", err)
168+
}
169+
166170
newOrgReq := apiClientOrgs.NewCreateOrgParams()
167171
newOrgReq.Body = params.CreateOrgParams{
168172
Name: orgName,
@@ -308,7 +312,7 @@ func init() {
308312
orgAddCmd.Flags().StringVar(&orgName, "name", "", "The name of the organization")
309313
orgAddCmd.Flags().StringVar(&poolBalancerType, "pool-balancer-type", string(params.PoolBalancerTypeRoundRobin), "The balancing strategy to use when creating runners in pools matching requested labels.")
310314
orgAddCmd.Flags().StringVar(&orgWebhookSecret, "webhook-secret", "", "The webhook secret for this organization")
311-
orgAddCmd.Flags().StringVar(&forgeType, "forge-type", string(params.GithubEndpointType), "The forge type of the organization. Supported values: github, gitea.")
315+
orgAddCmd.Flags().StringVar(&forgeType, "forge-type", "", "The forge type of the organization. Supported values: github, gitea.")
312316
orgAddCmd.Flags().StringVar(&orgCreds, "credentials", "", "Credentials name. See credentials list.")
313317
orgAddCmd.Flags().BoolVar(&orgRandomWebhookSecret, "random-webhook-secret", false, "Generate a random webhook secret for this organization.")
314318
orgAddCmd.Flags().BoolVar(&installOrgWebhook, "install-webhook", false, "Install the webhook as part of the add operation.")

cmd/garm-cli/cmd/repository.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ var repoAddCmd = &cobra.Command{
165165
repoWebhookSecret = secret
166166
}
167167

168+
if err := queryForgeType(repoCreds); err != nil {
169+
return fmt.Errorf("failed to query forge type: %w", err)
170+
}
171+
168172
newRepoReq := apiClientRepos.NewCreateRepoParams()
169173
newRepoReq.Body = params.CreateRepoParams{
170174
Owner: repoOwner,
@@ -312,7 +316,7 @@ func init() {
312316
repoAddCmd.Flags().StringVar(&repoOwner, "owner", "", "The owner of this repository")
313317
repoAddCmd.Flags().StringVar(&poolBalancerType, "pool-balancer-type", string(params.PoolBalancerTypeRoundRobin), "The balancing strategy to use when creating runners in pools matching requested labels.")
314318
repoAddCmd.Flags().StringVar(&repoName, "name", "", "The name of the repository")
315-
repoAddCmd.Flags().StringVar(&forgeType, "forge-type", string(params.GithubEndpointType), "The forge type of the repository. Supported values: github, gitea.")
319+
repoAddCmd.Flags().StringVar(&forgeType, "forge-type", "", "The forge type of the repository. Supported values: github, gitea.")
316320
repoAddCmd.Flags().StringVar(&repoWebhookSecret, "webhook-secret", "", "The webhook secret for this repository")
317321
repoAddCmd.Flags().StringVar(&repoCreds, "credentials", "", "Credentials name. See credentials list.")
318322
repoAddCmd.Flags().BoolVar(&randomWebhookSecret, "random-webhook-secret", false, "Generate a random webhook secret for this repository.")

doc/gitea.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ garm-cli repo add \
295295
--name testrepo \
296296
--owner testorg \
297297
--random-webhook-secret \
298-
--install-webhook \
299-
--forge-type gitea
298+
--install-webhook
300299
```
301300
302301
Make a note of the repo UUID. You will need it when adding a pool.

0 commit comments

Comments
 (0)