Skip to content
Open
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
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ linters:
- whitespace
- zerologlint
settings:
misspell:
ignore-words:
- cancelled
extra-words:
- typo: "canceled"
correction: "cancelled"
errcheck:
exclude-functions:
- (*github.com/tektoncd/pipeline/vendor/go.uber.org/zap.SugaredLogger).Sync
Expand All @@ -82,6 +88,14 @@ linters:
path: _test\.go
- path: pkg/resolve/resolve.go
text: don't use `init` function
- linters:
- misspell
path: pkg/provider/gitlab/gitlab\.go
text: '`canceled` is a misspelling of `cancelled`'
- linters:
- misspell
path: test/gitlab.*\.go
text: '`canceled` is a misspelling of `cancelled`'
paths:
- vendor
- pkg/provider/gitea/structs
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/tknpac/resolve/basic_auth_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func makeGitAuthSecret(ctx context.Context, cs *params.Run, filenames []string,
provideSecret := false
msg := "We have detected a git_auth_secret in your PipelineRun. Would you like to provide a API token for the git_clone task?"
if err := prompt.SurveyAskOne(&survey.Confirm{Message: msg, Default: true}, &provideSecret); err != nil {
return "", "", fmt.Errorf("canceled")
return "", "", fmt.Errorf("cancelled")
}
if provideSecret {
msg := `Enter a token to be used for the git_auth_secret`
if err := prompt.SurveyAskOne(&survey.Password{Message: msg}, &token); err != nil {
return "", "", fmt.Errorf("canceled")
return "", "", fmt.Errorf("cancelled")
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/provider/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ func (v *Provider) CreateStatus(_ context.Context, event *info.Event, statusOpts
case "neutral":
statusOpts.Conclusion = "canceled"
statusOpts.Title = "stopped"
case "cancelled":
statusOpts.Conclusion = "canceled"
statusOpts.Title = "cancelled validating this commit"
Comment on lines 263 to +268

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for neutral and cancelled conclusions is very similar. You can combine these cases to reduce code duplication and improve maintainability.

Suggested change
case "neutral":
statusOpts.Conclusion = "canceled"
statusOpts.Title = "stopped"
case "cancelled":
statusOpts.Conclusion = "canceled"
statusOpts.Title = "cancelled validating this commit"
case "neutral", "cancelled":
if statusOpts.Conclusion == "neutral" {
statusOpts.Title = "stopped"
} else {
statusOpts.Title = "cancelled validating this commit"
}
statusOpts.Conclusion = "canceled"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd rather duplication than code spagetthi, so you can discard this

case "failure":
statusOpts.Conclusion = "failed"
statusOpts.Title = "failed"
Expand Down
14 changes: 14 additions & 0 deletions pkg/provider/gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ func TestCreateStatus(t *testing.T) {
postStr: "has completed",
},
},
{
name: "cancelled conclusion",
wantClient: true,
wantErr: false,
args: args{
statusOpts: provider.StatusOpts{
Conclusion: "cancelled",
},
event: &info.Event{
TriggerTarget: "pull_request",
},
postStr: "has cancelled",
},
},
{
name: "gitops comments completed",
wantClient: true,
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, pr *tektonv1.PipelineRun
}

// queue pipelines which are in queued state and pending status
// if status is not pending, it could be canceled so let it be reported, even if state is queued
// if status is not pending, it could be cancelled so let it be reported, even if state is queued
if state == kubeinteraction.StateQueued && pr.Spec.Status == tektonv1.PipelineRunSpecStatusPending {
return r.queuePipelineRun(ctx, logger, pr)
}
Expand Down
4 changes: 2 additions & 2 deletions test/bitbucket_cloud_pullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ func TestBitbucketCloudPullRequestCancelInProgressMerged(t *testing.T) {
_, err = bprovider.Client().Repositories.PullRequests.Decline(po)
assert.NilError(t, err)

runcnx.Clients.Log.Info("Waiting 10 seconds to check things has been canceled")
runcnx.Clients.Log.Info("Waiting 10 seconds to check things has been cancelled")
time.Sleep(10 * time.Second) // β€œEvil does not sleep. It waits.” - Galadriel

prs, err := runcnx.Clients.Tekton.TektonV1().PipelineRuns(targetNS).List(context.Background(), metav1.ListOptions{})
assert.NilError(t, err)
assert.Equal(t, len(prs.Items), 1, "should have only one pipelinerun, but we have: %d", len(prs.Items))

assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been canceled")
assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been cancelled")
}

// Local Variables:
Expand Down
8 changes: 4 additions & 4 deletions test/gitea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func TestGiteaConfigCancelInProgress(t *testing.T) {
cancelledPr++
}
}
assert.Equal(t, cancelledPr, 1, "only one pr should have been canceled")
assert.Equal(t, cancelledPr, 1, "only one pr should have been cancelled")

// Test that cancelling works with /retest - use specific PipelineRun name to bypass success check
tgitea.PostCommentOnPullRequest(t, topts, "/retest pr-cancel-in-progress")
Expand All @@ -554,7 +554,7 @@ func TestGiteaConfigCancelInProgress(t *testing.T) {
cancelledPr++
}
}
assert.Equal(t, cancelledPr, 2, "tweo pr should have been canceled")
assert.Equal(t, cancelledPr, 2, "two pr should have been cancelled")
}

func TestGiteaConfigCancelInProgressAfterPRClosed(t *testing.T) {
Expand Down Expand Up @@ -586,14 +586,14 @@ func TestGiteaConfigCancelInProgressAfterPRClosed(t *testing.T) {
})
assert.NilError(t, err)

topts.ParamsRun.Clients.Log.Info("Waiting 10 seconds to check things has been canceled")
topts.ParamsRun.Clients.Log.Info("Waiting 10 seconds to check things has been cancelled")
time.Sleep(10 * time.Second) // β€œEvil does not sleep. It waits.” - Galadriel

prs, err := topts.ParamsRun.Clients.Tekton.TektonV1().PipelineRuns(topts.TargetNS).List(context.Background(), metav1.ListOptions{})
assert.NilError(t, err)
assert.Equal(t, len(prs.Items), 1, "should have only one pipelinerun, but we have: %d", len(prs.Items))

assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been canceled")
assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been cancelled")
}

func TestGiteaPush(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions test/github_pullrequest_retest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ func TestGithubSecondPullRequestGitopsCommentCancel(t *testing.T) {
assert.NilError(t, err)
assert.Equal(t, len(pruns.Items), 3)

// go over all pruns check that at least one is canceled and the other two are succeeded
canceledCount := 0
// go over all pruns check that at least one is cancelled and the other two are succeeded
cancelledCount := 0
succeededCount := 0
unknownCount := 0
for _, prun := range pruns.Items {
for _, condition := range prun.Status.Conditions {
if condition.Type == "Succeeded" {
switch condition.Status {
case corev1.ConditionFalse:
canceledCount++
cancelledCount++
case corev1.ConditionTrue:
succeededCount++
case corev1.ConditionUnknown:
Expand All @@ -140,7 +140,7 @@ func TestGithubSecondPullRequestGitopsCommentCancel(t *testing.T) {
}
}
}
assert.Equal(t, canceledCount, 1, "should have one canceled PipelineRun")
assert.Equal(t, cancelledCount, 1, "should have one cancelled PipelineRun")
assert.Equal(t, succeededCount, 2, "should have two succeeded PipelineRuns")
assert.Equal(t, unknownCount, 0, "should have zero unknown PipelineRuns: %+v", pruns.Items)
}
10 changes: 5 additions & 5 deletions test/github_pullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func TestGithubSecondCancelInProgress(t *testing.T) {
err = twait.UntilPipelineRunCreated(ctx, g.Cnx.Clients, waitOpts)
assert.NilError(t, err)

g.Cnx.Clients.Log.Infof("Sleeping for 10 seconds to let the pipelinerun to be canceled")
g.Cnx.Clients.Log.Infof("Sleeping for 10 seconds to let the pipelinerun to be cancelled")

i := 0
foundCancelled := false
Expand All @@ -357,7 +357,7 @@ func TestGithubSecondCancelInProgress(t *testing.T) {
continue
}
if pr.Status.Conditions[0].Reason == "Cancelled" {
g.Cnx.Clients.Log.Infof("PipelineRun %s has been canceled", pr.Name)
g.Cnx.Clients.Log.Infof("PipelineRun %s has been cancelled", pr.Name)
foundCancelled = true
break
}
Expand Down Expand Up @@ -400,16 +400,16 @@ func TestGithubSecondCancelInProgressPRClosed(t *testing.T) {
})
assert.NilError(t, err)

g.Cnx.Clients.Log.Infof("Sleeping for 10 seconds to let the pipelinerun to be canceled")
g.Cnx.Clients.Log.Infof("Sleeping for 10 seconds to let the pipelinerun to be cancelled")
time.Sleep(10 * time.Second)

g.Cnx.Clients.Log.Infof("Checking that the pipelinerun has been canceled")
g.Cnx.Clients.Log.Infof("Checking that the pipelinerun has been cancelled")

prs, err := g.Cnx.Clients.Tekton.TektonV1().PipelineRuns(g.TargetNamespace).List(context.Background(), metav1.ListOptions{})
assert.NilError(t, err)
assert.Equal(t, len(prs.Items), 1, "should have only one pipelinerun, but we have: %d", len(prs.Items))

assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been canceled")
assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been cancelled")

res, resp, err := g.Provider.Client().Checks.ListCheckRunsForRef(ctx, g.Options.Organization, g.Options.Repo, g.SHA, &github.ListCheckRunsOptions{
AppID: g.Provider.ApplicationID,
Expand Down
4 changes: 2 additions & 2 deletions test/github_push_retest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ func TestGithubPushRequestGitOpsCommentCancel(t *testing.T) {
&github.RepositoryComment{Body: github.Ptr(comment)})
assert.NilError(t, err)

g.Cnx.Clients.Log.Infof("Waiting for Repository to be updated still to %d since it has been canceled", numberOfStatus)
repo, _ := twait.UntilRepositoryUpdated(ctx, g.Cnx.Clients, waitOpts) // don't check for error, because canceled is not success and this will fail
g.Cnx.Clients.Log.Infof("Waiting for Repository to be updated still to %d since it has been cancelled", numberOfStatus)
repo, _ := twait.UntilRepositoryUpdated(ctx, g.Cnx.Clients, waitOpts) // don't check for error, because cancelled is not success and this will fail
cancelled := false
for _, c := range repo.Status {
if c.Conditions[0].Reason == tektonv1.TaskRunReasonCancelled.String() {
Expand Down
4 changes: 2 additions & 2 deletions test/gitlab_merge_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestGitlabCancelInProgressOnChange(t *testing.T) {
err = twait.UntilPipelineRunCreated(ctx, runcnx.Clients, newPipelineWaitOpts)
assert.NilError(t, err)

runcnx.Clients.Log.Infof("Waiting for old pipelinerun to be canceled")
runcnx.Clients.Log.Infof("Waiting for old pipelinerun to be cancelled")
cancelledErr := twait.UntilPipelineRunHasReason(ctx, runcnx.Clients, v1.PipelineRunReasonCancelled, originalPipelineWaitOpts)
assert.NilError(t, cancelledErr)
}
Expand Down Expand Up @@ -429,7 +429,7 @@ func TestGitlabCancelInProgressOnPRClose(t *testing.T) {
prs, err := runcnx.Clients.Tekton.TektonV1().PipelineRuns(targetNS).List(context.Background(), metav1.ListOptions{})
assert.NilError(t, err)
assert.Equal(t, len(prs.Items), 1, "should have only one pipelinerun, but we have: %d", len(prs.Items))
assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been canceled")
assert.Equal(t, prs.Items[0].GetStatusCondition().GetCondition(apis.ConditionSucceeded).GetReason(), "Cancelled", "should have been cancelled")

// failing on `true` condition because for cancelled PipelineRun we want `false` condition.
waitOpts.FailOnRepoCondition = corev1.ConditionTrue
Expand Down