2023-08-11 10:27:16 +00:00
|
|
|
// Copyright 2023 Woodpecker Authors
|
|
|
|
//
|
|
|
|
// 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 plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Repository defines runtime metadata for a repository.
|
|
|
|
type Repository struct {
|
2023-08-16 13:02:13 +00:00
|
|
|
Slug string
|
|
|
|
Name string
|
|
|
|
Owner string
|
|
|
|
URL string
|
|
|
|
CloneURL string
|
|
|
|
Private bool
|
|
|
|
Branch string
|
|
|
|
RemoteID int64
|
2023-08-11 10:27:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func repositoryFlags(category string) []cli.Flag {
|
|
|
|
return []cli.Flag{
|
2023-08-16 06:36:06 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repo.slug",
|
|
|
|
Usage: "repo slug",
|
|
|
|
EnvVars: []string{"CI_REPO"},
|
|
|
|
Category: category,
|
|
|
|
},
|
2023-08-11 10:27:16 +00:00
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repo.name",
|
|
|
|
Usage: "repo name",
|
|
|
|
EnvVars: []string{"CI_REPO_NAME"},
|
|
|
|
Category: category,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repo.owner",
|
|
|
|
Usage: "repo owner",
|
|
|
|
EnvVars: []string{"CI_REPO_OWNER"},
|
|
|
|
Category: category,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
2023-08-16 13:02:13 +00:00
|
|
|
Name: "repo.url",
|
|
|
|
Usage: "repo url",
|
2023-08-16 06:36:06 +00:00
|
|
|
EnvVars: []string{"CI_REPO_URL"},
|
2023-08-11 10:27:16 +00:00
|
|
|
Category: category,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repo.clone-url",
|
|
|
|
Usage: "repo clone url",
|
|
|
|
EnvVars: []string{"CI_REPO_CLONE_URL"},
|
|
|
|
Category: category,
|
|
|
|
},
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "repo.private",
|
|
|
|
Usage: "repo private",
|
|
|
|
EnvVars: []string{"CI_REPO_PRIVATE"},
|
|
|
|
Category: category,
|
|
|
|
},
|
|
|
|
&cli.StringFlag{
|
|
|
|
Name: "repo.default-branch",
|
|
|
|
Usage: "repo default branch",
|
|
|
|
EnvVars: []string{"CI_REPO_DEFAULT_BRANCH"},
|
|
|
|
Category: category,
|
|
|
|
},
|
2023-08-16 13:02:13 +00:00
|
|
|
&cli.Int64Flag{
|
|
|
|
Name: "repo.remote-id",
|
|
|
|
Usage: "repo remote id",
|
|
|
|
EnvVars: []string{"CI_REPO_REMOTE_ID"},
|
|
|
|
Category: category,
|
|
|
|
},
|
2023-08-11 10:27:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func repositoryFromContext(c *cli.Context) Repository {
|
|
|
|
return Repository{
|
2023-08-16 06:36:06 +00:00
|
|
|
Slug: c.String("repo.slug"),
|
2023-08-11 10:27:16 +00:00
|
|
|
Name: c.String("repo.name"),
|
|
|
|
Owner: c.String("repo.owner"),
|
2023-08-16 13:02:13 +00:00
|
|
|
URL: c.String("repo.url"),
|
2023-08-11 10:27:16 +00:00
|
|
|
CloneURL: c.String("repo.clone-url"),
|
|
|
|
Private: c.Bool("repo.private"),
|
|
|
|
Branch: c.String("repo.default-branch"),
|
2023-08-16 13:02:13 +00:00
|
|
|
RemoteID: c.Int64("repo.remote-id"),
|
2023-08-11 10:27:16 +00:00
|
|
|
}
|
|
|
|
}
|