Stamp trusted commit-branch and event pod labels (#6802)

This commit is contained in:
Marc Plano-Lesay
2026-07-01 23:56:48 +02:00
committed by GitHub
parent 6fe8d0bfb5
commit ba2f6f7115
3 changed files with 35 additions and 0 deletions
+2
View File
@@ -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"
+2
View File
@@ -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
}
+31
View File
@@ -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])
}