mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-09-05 20:07:25 +00:00
Stamp trusted commit-branch and event pod labels (#6802)
This commit is contained in:
@@ -29,6 +29,8 @@ const (
|
||||
LabelRepoFullName string = InternalLabelPrefix + "/repo-full-name"
|
||||
LabelBranch string = InternalLabelPrefix + "/branch"
|
||||
LabelOrgID string = InternalLabelPrefix + "/org-id"
|
||||
LabelCommitBranch string = InternalLabelPrefix + "/commit-branch"
|
||||
LabelEvent string = InternalLabelPrefix + "/event"
|
||||
LabelFilterOrg string = "org-id"
|
||||
LabelFilterRepo string = "repo"
|
||||
LabelFilterPlatform string = "platform"
|
||||
|
||||
@@ -202,6 +202,8 @@ func (b *PipelineBuilder) genItemForWorkflow(workflow *Workflow, axis matrix.Axi
|
||||
item.Labels[pipeline.LabelRepoFullName] = workflowMetadata.Repo.Owner + "/" + workflowMetadata.Repo.Name
|
||||
item.Labels[pipeline.LabelBranch] = workflowMetadata.Repo.Branch
|
||||
item.Labels[pipeline.LabelOrgID] = strconv.FormatInt(workflowMetadata.Repo.OrgID, 10)
|
||||
item.Labels[pipeline.LabelCommitBranch] = workflowMetadata.Curr.Commit.Branch
|
||||
item.Labels[pipeline.LabelEvent] = string(workflowMetadata.Curr.Event)
|
||||
|
||||
return item, errorsAndWarnings
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"go.woodpecker-ci.org/woodpecker/v3/pipeline"
|
||||
"go.woodpecker-ci.org/woodpecker/v3/pipeline/errors"
|
||||
"go.woodpecker-ci.org/woodpecker/v3/pipeline/frontend/metadata"
|
||||
"go.woodpecker-ci.org/woodpecker/v3/pipeline/frontend/yaml/compiler"
|
||||
@@ -902,3 +903,33 @@ func (t *testMetadata) GetWorkflowMetadata(w *Workflow) metadata.Metadata {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestInternalCommitBranchAndEventLabels(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
m := &testMetadata{
|
||||
pipelineEvent: "push",
|
||||
branch: "main",
|
||||
}
|
||||
|
||||
b := PipelineBuilder{
|
||||
GetWorkflowMetadata: m.GetWorkflowMetadata,
|
||||
RepoTrusted: &metadata.TrustedConfiguration{},
|
||||
Yamls: []*YamlFile{
|
||||
{Data: []byte(`
|
||||
when:
|
||||
event: push
|
||||
steps:
|
||||
- name: build
|
||||
image: scratch
|
||||
`)},
|
||||
},
|
||||
}
|
||||
|
||||
items, err := b.Build()
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, items, 1)
|
||||
|
||||
assert.Equal(t, "main", items[0].Labels[pipeline.LabelCommitBranch])
|
||||
assert.Equal(t, "push", items[0].Labels[pipeline.LabelEvent])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user