go-plugin/repo.go

111 lines
2.8 KiB
Go
Raw Permalink Normal View History

2023-01-08 03:53:03 +01: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/v3"
2023-01-08 03:53:03 +01:00
)
// Repository defines runtime metadata for a repository.
type Repository struct {
RemoteID string `json:"remote_id,omitempty"`
Name string `json:"name,omitempty"`
Owner string `json:"owner,omitempty"`
Link string `json:"link,omitempty"`
URL string `json:"url,omitempty"`
CloneURL string `json:"clone_url,omitempty"`
Private bool `json:"private,omitempty"`
DefaultBranch string `json:"default_branch,omitempty"`
// Deprecated: Please use DefaultBranch instead.
Branch string
2023-01-08 03:53:03 +01:00
}
func repositoryFlags() []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "repo.remote-id",
Usage: "repo remote id",
Sources: cli.EnvVars(
"CI_REPO_REMOTE_ID",
),
},
2023-01-08 03:53:03 +01:00
&cli.StringFlag{
Name: "repo.name",
Usage: "repo name",
Sources: cli.EnvVars(
2023-01-08 03:53:03 +01:00
"CI_REPO_NAME",
"DRONE_REPO_NAME",
),
2023-01-08 03:53:03 +01:00
},
&cli.StringFlag{
Name: "repo.owner",
Usage: "repo owner",
Sources: cli.EnvVars(
2023-01-08 03:53:03 +01:00
"CI_REPO_OWNER",
"DRONE_REPO_OWNER",
),
2023-01-08 03:53:03 +01:00
},
&cli.StringFlag{
Name: "repo.url",
Aliases: []string{"repo.link"},
Usage: "repo url",
Sources: cli.EnvVars(
"CI_REPO_URL",
2023-01-08 03:53:03 +01:00
"CI_REPO_LINK",
"DRONE_REPO_LINK",
),
2023-01-08 03:53:03 +01:00
},
&cli.StringFlag{
Name: "repo.clone-url",
Usage: "repo clone url",
Sources: cli.EnvVars(
2023-01-08 03:53:03 +01:00
"CI_REPO_CLONE_URL",
"DRONE_GIT_HTTP_URL",
),
2023-01-08 03:53:03 +01:00
},
&cli.BoolFlag{
Name: "repo.private",
Usage: "repo private",
Sources: cli.EnvVars(
2023-01-08 03:53:03 +01:00
"CI_REPO_PRIVATE",
"DRONE_REPO_PRIVATE",
),
2023-01-08 03:53:03 +01:00
},
&cli.StringFlag{
Name: "repo.default-branch",
Usage: "repo default branch",
Sources: cli.EnvVars(
2023-01-08 03:53:03 +01:00
"CI_REPO_DEFAULT_BRANCH",
"DRONE_REPO_BRANCH",
),
2023-01-08 03:53:03 +01:00
},
}
}
func repositoryFromContext(c *cli.Command) Repository {
2023-01-08 03:53:03 +01:00
return Repository{
RemoteID: c.String("repo.remote-id"),
Name: c.String("repo.name"),
Owner: c.String("repo.owner"),
URL: c.String("repo.url"),
Link: c.String("repo.url"),
CloneURL: c.String("repo.clone-url"),
Private: c.Bool("repo.private"),
Branch: c.String("repo.default-branch"),
DefaultBranch: c.String("repo.default-branch"),
2023-01-08 03:53:03 +01:00
}
}