Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename link to url #2812

Merged
merged 11 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cli/exec/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ var flags = []cli.Flag{
},
&cli.StringFlag{
EnvVars: []string{"CI_SYSTEM_URL"},
Name: "system-link",
Name: "system-url",
Value: "https://github.com/woodpecker-ci/woodpecker",
},
&cli.StringFlag{
Expand All @@ -144,7 +144,7 @@ var flags = []cli.Flag{
},
&cli.StringFlag{
EnvVars: []string{"CI_REPO_URL"},
Name: "repo-link",
Name: "repo-url",
},
&cli.StringFlag{
EnvVars: []string{"CI_REPO_CLONE_URL"},
Expand Down Expand Up @@ -193,7 +193,7 @@ var flags = []cli.Flag{
},
&cli.StringFlag{
EnvVars: []string{"CI_PIPELINE_URL"},
Name: "pipeline-link",
Name: "pipeline-url",
},
&cli.StringFlag{
EnvVars: []string{"CI_PIPELINE_TARGET"},
Expand Down Expand Up @@ -257,7 +257,7 @@ var flags = []cli.Flag{
},
&cli.StringFlag{
EnvVars: []string{"CI_PREV_PIPELINE_URL"},
Name: "prev-pipeline-link",
Name: "prev-pipeline-url",
},
&cli.StringFlag{
EnvVars: []string{"CI_PREV_COMMIT_SHA"},
Expand Down
8 changes: 4 additions & 4 deletions cli/exec/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func metadataFromContext(c *cli.Context, axis matrix.Axis) metadata.Metadata {
Name: repoName,
Owner: repoOwner,
RemoteID: c.String("repo-remote-id"),
Link: c.String("repo-link"),
ForgeURL: c.String("repo-url"),
CloneURL: c.String("repo-clone-url"),
CloneSSHURL: c.String("repo-clone-ssh-url"),
Private: c.Bool("repo-private"),
Expand All @@ -59,7 +59,7 @@ func metadataFromContext(c *cli.Context, axis matrix.Axis) metadata.Metadata {
Finished: c.Int64("pipeline-finished"),
Status: c.String("pipeline-status"),
Event: c.String("pipeline-event"),
Link: c.String("pipeline-link"),
ForgeURL: c.String("pipeline-url"),
Target: c.String("pipeline-target"),
Commit: metadata.Commit{
Sha: c.String("commit-sha"),
Expand All @@ -81,7 +81,7 @@ func metadataFromContext(c *cli.Context, axis matrix.Axis) metadata.Metadata {
Finished: c.Int64("prev-pipeline-finished"),
Status: c.String("prev-pipeline-status"),
Event: c.String("prev-pipeline-event"),
Link: c.String("prev-pipeline-link"),
ForgeURL: c.String("prev-pipeline-url"),
Commit: metadata.Commit{
Sha: c.String("prev-commit-sha"),
Ref: c.String("prev-commit-ref"),
Expand All @@ -106,7 +106,7 @@ func metadataFromContext(c *cli.Context, axis matrix.Axis) metadata.Metadata {
},
Sys: metadata.System{
Name: c.String("system-name"),
Link: c.String("system-link"),
URL: c.String("system-url"),
Platform: platform,
Version: version.Version,
},
Expand Down
2 changes: 1 addition & 1 deletion cli/repo/repo_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func repoInfo(c *cli.Context) error {
// template for repo information
var tmplRepoInfo = `Owner: {{ .Owner }}
Repo: {{ .Name }}
Link: {{ .Link }}
URL: {{ .ForgeURL }}
Config path: {{ .Config }}
Visibility: {{ .Visibility }}
Private: {{ .IsSCMPrivate }}
Expand Down
12 changes: 6 additions & 6 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3963,12 +3963,12 @@ const docTemplate = `{
"finished_at": {
"type": "integer"
},
"forge_url": {
"type": "string"
},
"id": {
"type": "integer"
},
"link_url": {
"type": "string"
},
"message": {
"type": "string"
},
Expand Down Expand Up @@ -4111,6 +4111,9 @@ const docTemplate = `{
"description": "ForgeRemoteID is the unique identifier for the repository on the forge.",
"type": "string"
},
"forge_url": {
"type": "string"
},
"full_name": {
"type": "string"
},
Expand All @@ -4120,9 +4123,6 @@ const docTemplate = `{
"id": {
"type": "integer"
},
"link_url": {
"type": "string"
},
"name": {
"type": "string"
},
Expand Down
1 change: 1 addition & 0 deletions docs/docs/91-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Some versions need some changes to the server configuration or the pipeline conf
- Removed `ssh` backend. Use an agent directly on the SSH machine using the `local` backend.
- Removed `/hook` and `/stream` API paths in favor of `/api/(hook|stream)`. You may need to use the "Repair repository" button in the repo settings or "Repair all" in the admin settings to recreate the forge hook.
- Removed `WOODPECKER_DOCS` config variable
- Renamed `link` to `url` (including all API fields)
- Deprecated `CI_COMMIT_URL` env var, use `CI_PIPELINE_FORGE_URL`

## 1.0.0
Expand Down
12 changes: 6 additions & 6 deletions pipeline/frontend/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func EnvVarSubst(yaml string, environ map[string]string) (string, error) {
}

// MetadataFromStruct return the metadata from a pipeline will run with.
func MetadataFromStruct(forge metadata.ServerForge, repo *model.Repo, pipeline, last *model.Pipeline, workflow *model.Workflow, link string) metadata.Metadata {
host := link
uri, err := url.Parse(link)
func MetadataFromStruct(forge metadata.ServerForge, repo *model.Repo, pipeline, last *model.Pipeline, workflow *model.Workflow, sysURL string) metadata.Metadata {
host := sysURL
uri, err := url.Parse(sysURL)
if err == nil {
host = uri.Host
}
Expand All @@ -59,7 +59,7 @@ func MetadataFromStruct(forge metadata.ServerForge, repo *model.Repo, pipeline,
Name: repo.Name,
Owner: repo.Owner,
RemoteID: fmt.Sprint(repo.ForgeRemoteID),
Link: repo.Link,
ForgeURL: repo.ForgeURL,
CloneURL: repo.Clone,
CloneSSHURL: repo.CloneSSH,
Private: repo.IsSCMPrivate,
Expand Down Expand Up @@ -94,7 +94,7 @@ func MetadataFromStruct(forge metadata.ServerForge, repo *model.Repo, pipeline,
Step: metadata.Step{},
Sys: metadata.System{
Name: "woodpecker",
Link: link,
URL: sysURL,
Host: host,
Platform: "", // will be set by pipeline platform option or by agent
Version: version.Version,
Expand Down Expand Up @@ -126,7 +126,7 @@ func metadataPipelineFromModelPipeline(pipeline *model.Pipeline, includeParent b
Finished: pipeline.Finished,
Status: string(pipeline.Status),
Event: string(pipeline.Event),
Link: pipeline.Link,
ForgeURL: pipeline.ForgeURL,
Target: pipeline.Deploy,
Commit: metadata.Commit{
Sha: pipeline.Commit,
Expand Down
16 changes: 8 additions & 8 deletions pipeline/frontend/metadata/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (m *Metadata) Environ() map[string]string {
"CI_REPO_OWNER": m.Repo.Owner,
"CI_REPO_REMOTE_ID": m.Repo.RemoteID,
"CI_REPO_SCM": "git",
"CI_REPO_URL": m.Repo.Link,
"CI_REPO_URL": m.Repo.ForgeURL,
"CI_REPO_CLONE_URL": m.Repo.CloneURL,
"CI_REPO_CLONE_SSH_URL": m.Repo.CloneSSHURL,
"CI_REPO_DEFAULT_BRANCH": m.Repo.Branch,
Expand All @@ -69,7 +69,7 @@ func (m *Metadata) Environ() map[string]string {
"CI_PIPELINE_PARENT": strconv.FormatInt(m.Curr.Parent, 10),
"CI_PIPELINE_EVENT": m.Curr.Event,
"CI_PIPELINE_URL": m.getPipelineWebURL(m.Curr, 0),
"CI_PIPELINE_FORGE_URL": m.Curr.Link,
"CI_PIPELINE_FORGE_URL": m.Curr.ForgeURL,
"CI_PIPELINE_DEPLOY_TARGET": m.Curr.Target,
"CI_PIPELINE_STATUS": m.Curr.Status,
"CI_PIPELINE_CREATED": strconv.FormatInt(m.Curr.Created, 10),
Expand All @@ -90,7 +90,7 @@ func (m *Metadata) Environ() map[string]string {
"CI_PREV_COMMIT_REF": m.Prev.Commit.Ref,
"CI_PREV_COMMIT_REFSPEC": m.Prev.Commit.Refspec,
"CI_PREV_COMMIT_BRANCH": m.Prev.Commit.Branch,
"CI_PREV_COMMIT_URL": m.Prev.Link,
"CI_PREV_COMMIT_URL": m.Prev.ForgeURL,
"CI_PREV_COMMIT_MESSAGE": m.Prev.Commit.Message,
"CI_PREV_COMMIT_AUTHOR": m.Prev.Commit.Author.Name,
"CI_PREV_COMMIT_AUTHOR_EMAIL": m.Prev.Commit.Author.Email,
Expand All @@ -100,15 +100,15 @@ func (m *Metadata) Environ() map[string]string {
"CI_PREV_PIPELINE_PARENT": strconv.FormatInt(m.Prev.Parent, 10),
"CI_PREV_PIPELINE_EVENT": m.Prev.Event,
"CI_PREV_PIPELINE_URL": m.getPipelineWebURL(m.Prev, 0),
"CI_PREV_PIPELINE_FORGE_URL": m.Prev.Link,
"CI_PREV_PIPELINE_FORGE_URL": m.Prev.ForgeURL,
"CI_PREV_PIPELINE_DEPLOY_TARGET": m.Prev.Target,
"CI_PREV_PIPELINE_STATUS": m.Prev.Status,
"CI_PREV_PIPELINE_CREATED": strconv.FormatInt(m.Prev.Created, 10),
"CI_PREV_PIPELINE_STARTED": strconv.FormatInt(m.Prev.Started, 10),
"CI_PREV_PIPELINE_FINISHED": strconv.FormatInt(m.Prev.Finished, 10),

"CI_SYSTEM_NAME": m.Sys.Name,
"CI_SYSTEM_URL": m.Sys.Link,
"CI_SYSTEM_URL": m.Sys.URL,
"CI_SYSTEM_HOST": m.Sys.Host,
"CI_SYSTEM_PLATFORM": m.Sys.Platform, // will be set by pipeline platform option or by agent
"CI_SYSTEM_VERSION": m.Sys.Version,
Expand All @@ -117,7 +117,7 @@ func (m *Metadata) Environ() map[string]string {
"CI_FORGE_URL": m.Forge.URL,

// TODO Deprecated, remove in 3.x
"CI_COMMIT_URL": m.Curr.Link,
"CI_COMMIT_URL": m.Curr.ForgeURL,
}
if m.Curr.Event == EventTag {
params["CI_COMMIT_TAG"] = strings.TrimPrefix(m.Curr.Commit.Ref, "refs/tags/")
Expand All @@ -132,8 +132,8 @@ func (m *Metadata) Environ() map[string]string {

func (m *Metadata) getPipelineWebURL(pipeline Pipeline, stepNumber int) string {
if stepNumber == 0 {
return fmt.Sprintf("%s/repos/%d/pipeline/%d", m.Sys.Link, m.Repo.ID, pipeline.Number)
return fmt.Sprintf("%s/repos/%d/pipeline/%d", m.Sys.URL, m.Repo.ID, pipeline.Number)
}

return fmt.Sprintf("%s/repos/%d/pipeline/%d/%d", m.Sys.Link, m.Repo.ID, pipeline.Number, stepNumber)
return fmt.Sprintf("%s/repos/%d/pipeline/%d/%d", m.Sys.URL, m.Repo.ID, pipeline.Number, stepNumber)
}
6 changes: 3 additions & 3 deletions pipeline/frontend/metadata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type (
Name string `json:"name,omitempty"`
Owner string `json:"owner,omitempty"`
RemoteID string `json:"remote_id,omitempty"`
Link string `json:"link,omitempty"`
ForgeURL string `json:"forge_url,omitempty"`
CloneURL string `json:"clone_url,omitempty"`
CloneSSHURL string `json:"clone_url_ssh,omitempty"`
Private bool `json:"private,omitempty"`
Expand All @@ -51,7 +51,7 @@ type (
Timeout int64 `json:"timeout,omitempty"`
Status string `json:"status,omitempty"`
Event string `json:"event,omitempty"`
Link string `json:"link,omitempty"`
ForgeURL string `json:"forge_url,omitempty"`
Target string `json:"target,omitempty"`
Trusted bool `json:"trusted,omitempty"`
Commit Commit `json:"commit,omitempty"`
Expand Down Expand Up @@ -103,7 +103,7 @@ type (
System struct {
Name string `json:"name,omitempty"`
Host string `json:"host,omitempty"`
Link string `json:"link,omitempty"`
URL string `json:"url,omitempty"`
Platform string `json:"arch,omitempty"`
Version string `json:"version,omitempty"`
}
Expand Down
12 changes: 6 additions & 6 deletions pipeline/frontend/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestMetadataFromStruct(t *testing.T) {
repo *model.Repo
pipeline, last *model.Pipeline
workflow *model.Workflow
link string
sysURL string
expectedMetadata metadata.Metadata
expectedEnviron map[string]string
}{
Expand All @@ -88,15 +88,15 @@ func TestMetadataFromStruct(t *testing.T) {
{
name: "Test with forge",
forge: forge,
repo: &model.Repo{FullName: "testUser/testRepo", Link: "https://gitea.com/testUser/testRepo", Clone: "https://gitea.com/testUser/testRepo.git", CloneSSH: "git@gitea.com:testUser/testRepo.git", Branch: "main", IsSCMPrivate: true},
repo: &model.Repo{FullName: "testUser/testRepo", ForgeURL: "https://gitea.com/testUser/testRepo", Clone: "https://gitea.com/testUser/testRepo.git", CloneSSH: "git@gitea.com:testUser/testRepo.git", Branch: "main", IsSCMPrivate: true},
pipeline: &model.Pipeline{Number: 3},
last: &model.Pipeline{Number: 2},
workflow: &model.Workflow{Name: "hello"},
link: "https://example.com",
sysURL: "https://example.com",
expectedMetadata: metadata.Metadata{
Forge: metadata.Forge{Type: "gitea", URL: "https://gitea.com"},
Sys: metadata.System{Name: "woodpecker", Host: "example.com", Link: "https://example.com"},
Repo: metadata.Repo{Owner: "testUser", Name: "testRepo", Link: "https://gitea.com/testUser/testRepo", CloneURL: "https://gitea.com/testUser/testRepo.git", CloneSSHURL: "git@gitea.com:testUser/testRepo.git", Branch: "main", Private: true},
Sys: metadata.System{Name: "woodpecker", Host: "example.com", URL: "https://example.com"},
Repo: metadata.Repo{Owner: "testUser", Name: "testRepo", ForgeURL: "https://gitea.com/testUser/testRepo", CloneURL: "https://gitea.com/testUser/testRepo.git", CloneSSHURL: "git@gitea.com:testUser/testRepo.git", Branch: "main", Private: true},
Curr: metadata.Pipeline{Number: 3},
Prev: metadata.Pipeline{Number: 2},
Workflow: metadata.Workflow{Name: "hello"},
Expand All @@ -122,7 +122,7 @@ func TestMetadataFromStruct(t *testing.T) {

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
result := frontend.MetadataFromStruct(testCase.forge, testCase.repo, testCase.pipeline, testCase.last, testCase.workflow, testCase.link)
result := frontend.MetadataFromStruct(testCase.forge, testCase.repo, testCase.pipeline, testCase.last, testCase.workflow, testCase.sysURL)
assert.EqualValues(t, testCase.expectedMetadata, result)
assert.EqualValues(t, testCase.expectedEnviron, result.Environ())
})
Expand Down
2 changes: 1 addition & 1 deletion pipeline/frontend/yaml/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestCompilerCompile(t *testing.T) {
Owner: "octacat",
Name: "hello-world",
Private: true,
Link: "https://github.com/octocat/hello-world",
ForgeURL: "https://github.com/octocat/hello-world",
CloneURL: "https://github.com/octocat/hello-world.git",
},
}),
Expand Down
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/compiler/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func WithWorkspace(base, path string) Option {

// WithWorkspaceFromURL configures the compiler with the workspace
// base and path based on the repository url.
func WithWorkspaceFromURL(base, link string) Option {
func WithWorkspaceFromURL(base, u string) Option {
srcPath := "src"
parsed, err := url.Parse(link)
parsed, err := url.Parse(u)
if err == nil {
srcPath = path.Join(srcPath, parsed.Hostname(), parsed.Path)
}
Expand Down
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/compiler/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestWithMetadata(t *testing.T) {
Owner: "octacat",
Name: "hello-world",
Private: true,
Link: "https://github.com/octocat/hello-world",
ForgeURL: "https://github.com/octocat/hello-world",
CloneURL: "https://github.com/octocat/hello-world.git",
},
}
Expand All @@ -129,7 +129,7 @@ func TestWithMetadata(t *testing.T) {
if compiler.env["CI_REPO_NAME"] != metadata.Repo.Name {
t.Errorf("WithMetadata must set CI_REPO_NAME")
}
if compiler.env["CI_REPO_URL"] != metadata.Repo.Link {
if compiler.env["CI_REPO_URL"] != metadata.Repo.ForgeURL {
t.Errorf("WithMetadata must set CI_REPO_URL")
}
if compiler.env["CI_REPO_CLONE_URL"] != metadata.Repo.CloneURL {
Expand Down
6 changes: 3 additions & 3 deletions pipeline/stepBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type StepBuilder struct {
Netrc *model.Netrc
Secs []*model.Secret
Regs []*model.Registry
Link string
Host string
Yamls []*forge_types.FileMeta
Envs map[string]string
Forge metadata.ServerForge
Expand Down Expand Up @@ -117,7 +117,7 @@ func (b *StepBuilder) Build() (items []*Item, errorsAndWarnings error) {
}

func (b *StepBuilder) genItemForWorkflow(workflow *model.Workflow, axis matrix.Axis, data string) (item *Item, errorsAndWarnings error) {
workflowMetadata := frontend.MetadataFromStruct(b.Forge, b.Repo, b.Curr, b.Last, workflow, b.Link)
workflowMetadata := frontend.MetadataFromStruct(b.Forge, b.Repo, b.Curr, b.Last, workflow, b.Host)
environ := b.environmentVariables(workflowMetadata, axis)

// add global environment variables for substituting
Expand Down Expand Up @@ -291,7 +291,7 @@ func (b *StepBuilder) toInternalRepresentation(parsed *yaml_types.Workflow, envi
),
),
compiler.WithProxy(b.ProxyOpts),
compiler.WithWorkspaceFromURL("/woodpecker", b.Repo.Link),
compiler.WithWorkspaceFromURL("/woodpecker", b.Repo.ForgeURL),
compiler.WithMetadata(metadata),
compiler.WithTrusted(b.Repo.IsTrusted),
compiler.WithNetrcOnlyTrusted(b.Repo.NetrcOnlyTrusted),
Expand Down
Loading