Skip to content

Commit fdd6549

Browse files
infernus01chmouel
authored andcommitted
refactor(triggertype): rename LabelUpdate to pull_request_labeled
Signed-off-by: Shubham Bhardwaj <[email protected]>
1 parent 934dddc commit fdd6549

File tree

9 files changed

+12
-10
lines changed

9 files changed

+12
-10
lines changed

pkg/matcher/annotation_matcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func MatchPipelinerunByAnnotation(ctx context.Context, logger *zap.SugaredLogger
266266
// If the event is a pull_request and the event type is label_update, but the PipelineRun
267267
// does not contain an 'on-label' annotation, do not match this PipelineRun, as it is not intended for this event.
268268
_, ok := prun.GetObjectMeta().GetAnnotations()[keys.OnLabel]
269-
if event.TriggerTarget == triggertype.PullRequest && event.EventType == string(triggertype.LabelUpdate) && !ok {
269+
if event.TriggerTarget == triggertype.PullRequest && event.EventType == string(triggertype.PullRequestLabeled) && !ok {
270270
logger.Infof("label update event, PipelineRun %s does not have a on-label for any of those labels: %s", prName, strings.Join(event.PullRequestLabel, "|"))
271271
continue
272272
}

pkg/matcher/annotation_matcher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ func TestMatchPipelinerunByAnnotation(t *testing.T) {
16931693
runevent: info.Event{
16941694
URL: "https://hello/moto",
16951695
TriggerTarget: triggertype.PullRequest,
1696-
EventType: string(triggertype.LabelUpdate),
1696+
EventType: string(triggertype.PullRequestLabeled),
16971697
HeadBranch: "source",
16981698
BaseBranch: "main",
16991699
PullRequestNumber: 10,

pkg/params/triggertype/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type (
88
func IsPullRequestType(s string) Trigger {
99
eventType := s
1010
switch s {
11-
case PullRequest.String(), OkToTest.String(), Retest.String(), Cancel.String(), LabelUpdate.String():
11+
case PullRequest.String(), OkToTest.String(), Retest.String(), Cancel.String(), PullRequestLabeled.String():
1212
eventType = PullRequest.String()
1313
}
1414
return Trigger(eventType)
@@ -38,6 +38,8 @@ func StringToType(s string) Trigger {
3838
return Incoming
3939
case Comment.String():
4040
return Comment
41+
case PullRequestLabeled.String():
42+
return PullRequestLabeled
4143
}
4244
return ""
4345
}
@@ -48,7 +50,7 @@ const (
4850
CheckSuiteRerequested Trigger = "check-suite-rerequested"
4951
Comment Trigger = "comment"
5052
Incoming Trigger = "incoming"
51-
LabelUpdate Trigger = "label_update"
53+
PullRequestLabeled Trigger = "pull_request_labeled"
5254
OkToTest Trigger = "ok-to-test"
5355
PullRequestClosed Trigger = "pull_request_closed"
5456
PullRequest Trigger = "pull_request" // it's should be "pull_request_opened_updated" but let's keep it simple.

pkg/policy/policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (p *Policy) checkAllowed(ctx context.Context, tType triggertype.Trigger) (R
4545
sType = settings.Policy.OkToTest
4646
// apply the same policy for PullRequest and comment
4747
// we don't support comments on PRs yet but if we do on the future we will need our own policy
48-
case triggertype.PullRequest, triggertype.Comment, triggertype.LabelUpdate, triggertype.PullRequestClosed:
48+
case triggertype.PullRequest, triggertype.Comment, triggertype.PullRequestLabeled, triggertype.PullRequestClosed:
4949
sType = settings.Policy.PullRequest
5050
// NOTE: not supported yet, will imp if it gets requested and reasonable to implement
5151
case triggertype.Push, triggertype.Cancel, triggertype.CheckSuiteRerequested, triggertype.CheckRunRerequested, triggertype.Incoming:

pkg/provider/gitea/parse_payload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (v *Provider) ParsePayload(_ context.Context, _ *params.Run, request *http.
5252
processedEvent.TriggerTarget = triggertype.PullRequest
5353
processedEvent.EventType = triggertype.PullRequest.String()
5454
if provider.Valid(string(gitEvent.Action), []string{pullRequestLabelUpdated}) {
55-
processedEvent.EventType = string(triggertype.LabelUpdate)
55+
processedEvent.EventType = string(triggertype.PullRequestLabeled)
5656
}
5757
for _, label := range gitEvent.PullRequest.Labels {
5858
processedEvent.PullRequestLabel = append(processedEvent.PullRequestLabel, label.Name)

pkg/provider/github/parse_payload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ func (v *Provider) processEvent(ctx context.Context, event *info.Event, eventInt
393393
v.userType = gitEvent.GetPullRequest().GetUser().GetType()
394394

395395
if gitEvent.Action != nil && provider.Valid(*gitEvent.Action, pullRequestLabelEvent) {
396-
processedEvent.EventType = string(triggertype.LabelUpdate)
396+
processedEvent.EventType = string(triggertype.PullRequestLabeled)
397397
}
398398

399399
if gitEvent.GetAction() == "closed" {

pkg/provider/gitlab/parse_payload.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (v *Provider) ParsePayload(ctx context.Context, run *params.Run, request *h
7070

7171
// This is a label update, like adding or removing a label from a MR.
7272
if gitEvent.Changes.Labels.Current != nil {
73-
processedEvent.EventType = triggertype.LabelUpdate.String()
73+
processedEvent.EventType = triggertype.PullRequestLabeled.String()
7474
}
7575
for _, label := range gitEvent.Labels {
7676
processedEvent.PullRequestLabel = append(processedEvent.PullRequestLabel, label.Title)

test/github_pullrequest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestGithubPullRequestOnLabel(t *testing.T) {
9999

100100
sopt := twait.SuccessOpt{
101101
Title: g.CommitTitle,
102-
OnEvent: triggertype.LabelUpdate.String(),
102+
OnEvent: triggertype.PullRequestLabeled.String(),
103103
TargetNS: g.TargetNamespace,
104104
NumberofPRMatch: len(g.YamlFiles),
105105
SHA: g.SHA,

test/gitlab_merge_request_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func TestGitlabOnLabel(t *testing.T) {
199199
repo, err := twait.UntilRepositoryUpdated(ctx, runcnx.Clients, waitOpts)
200200
assert.NilError(t, err)
201201
assert.Assert(t, len(repo.Status) > 0)
202-
assert.Equal(t, *repo.Status[0].EventType, triggertype.LabelUpdate.String())
202+
assert.Equal(t, *repo.Status[0].EventType, triggertype.PullRequestLabeled.String())
203203
}
204204

205205
func TestGitlabOnComment(t *testing.T) {

0 commit comments

Comments
 (0)