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

feat: revert removal of lighthouse common pipelines & fix Tekton validation errors #1556

Merged
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
3 changes: 3 additions & 0 deletions pkg/config/job/utilityconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ type UtilityConfig struct {
// CloneDepth is the depth of the clone that will be used.
// A depth of zero will do a full clone.
CloneDepth int `json:"clone_depth,omitempty"`
// IsResolvedWithUsesSyntax indicates how the pipeline was resolved. Used internally in lighthouse for determining
// if the pipeline syntax is deprecated.
IsResolvedWithUsesSyntax bool `json:"-"`
}
68 changes: 60 additions & 8 deletions pkg/plugins/trigger/pull-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ package trigger

import (
"fmt"
"net/url"

"github.com/jenkins-x/go-scm/scm"
"github.com/jenkins-x/lighthouse/pkg/config"
"github.com/jenkins-x/lighthouse/pkg/config/job"
"github.com/jenkins-x/lighthouse/pkg/errorutil"
"github.com/jenkins-x/lighthouse/pkg/jobutil"
"github.com/jenkins-x/lighthouse/pkg/labels"
"github.com/jenkins-x/lighthouse/pkg/plugins"
"github.com/jenkins-x/lighthouse/pkg/scmprovider"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"net/url"
)

func handlePR(c Client, trigger *plugins.Trigger, pr scm.PullRequestHook) error {
Expand All @@ -46,14 +48,19 @@ func handlePR(c Client, trigger *plugins.Trigger, pr scm.PullRequestHook) error
if err != nil {
return fmt.Errorf("could not check membership: %s", err)
}
if member {
c.Logger.Infof("Author %q is a member, Starting all jobs for new PR.", author)
return buildAll(c, &pr.PullRequest, pr.GUID, trigger.ElideSkippedContexts)
if !member {
c.Logger.Infof("Author is not a member, Welcome message to PR author %q.", author)
if err = welcomeMsg(c.SCMProviderClient, trigger, pr.PullRequest); err != nil {
return fmt.Errorf("could not welcome non-org member %q: %v", author, err)
}
return nil
}
c.Logger.Infof("Author is not a member, Welcome message to PR author %q.", author)
if err := welcomeMsg(c.SCMProviderClient, trigger, pr.PullRequest); err != nil {
return fmt.Errorf("could not welcome non-org member %q: %v", author, err)

if err = infoMsg(c, pr.PullRequest); err != nil {
return err
}
c.Logger.Infof("Author %q is a member, Starting all jobs for new PR.", author)
return buildAll(c, &pr.PullRequest, pr.GUID, trigger.ElideSkippedContexts)
case scm.ActionReopen:
// When a PR is reopened, check that the user is in the org or that an org
// member had said "/ok-to-test" before building, resulting in label ok-to-test.
Expand Down Expand Up @@ -132,6 +139,51 @@ func buildAllIfTrusted(c Client, trigger *plugins.Trigger, pr scm.PullRequestHoo
return nil
}

func infoMsg(c Client, pr scm.PullRequest) error {
if isSyntaxDeprecated := isPipelinesSyntaxDeprecated(c.Config, pr.Repository()); !isSyntaxDeprecated {
return nil
}

org, repo, a := orgRepoAuthor(pr)
author := string(a)

comment := fmt.Sprintf(`[jx-info] Hi @%s. We've detected that the pipelines in this repository are using a syntax that will soon be deprecated.
We'll continue to update you through PRs as we progress. Please check [#8589](https://github.com/jenkins-x/jx/issues/8589) for further information.
`, author)

if err := c.SCMProviderClient.CreateComment(org, repo, pr.Number, true, comment); err != nil {
return errors.Wrap(err, "failed to comment info message")
}
return nil
}

func isPipelinesSyntaxDeprecated(cfg *config.Config, repo scm.Repository) bool {
logger := logrus.WithField("repo", repo.FullName)
for _, pre := range cfg.GetPresubmits(repo) {
if pre.PipelineRunSpec == nil {
err := pre.LoadPipeline(logger)
if err != nil {
return false
}
}
if pre.IsResolvedWithUsesSyntax {
return true
}
}
for _, post := range cfg.GetPostsubmits(repo) {
if post.PipelineRunSpec == nil {
err := post.LoadPipeline(logger)
if err != nil {
return false
}
}
if post.IsResolvedWithUsesSyntax {
return true
}
}
return false
}

func welcomeMsg(spc scmProviderClient, trigger *plugins.Trigger, pr scm.PullRequest) error {
var errors []error
org, repo, a := orgRepoAuthor(pr)
Expand Down
27 changes: 17 additions & 10 deletions pkg/triggerconfig/inrepo/default_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"strings"

"github.com/tektoncd/pipeline/pkg/apis/config"

"github.com/pkg/errors"

"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
Expand Down Expand Up @@ -102,7 +104,6 @@ func DefaultPipelineParameters(prs *v1beta1.PipelineRun) (*v1beta1.PipelineRun,
if prs.Annotations != nil && prs.Annotations[DefaultParameters] == "false" {
return prs, nil
}

ps := prs.Spec.PipelineSpec
if ps == nil {
return prs, nil
Expand All @@ -125,15 +126,6 @@ func DefaultPipelineParameters(prs *v1beta1.PipelineRun) (*v1beta1.PipelineRun,
}
}

for i := range ps.Params {
param := &ps.Params[i]
if param.Type == "" {
param.Type = "string"
}

ps.Params[i] = *param
}

for i := range ps.Finally {
task := &ps.Finally[i]
task.Params = addDefaultParameters(task.Params, defaultParameters)
Expand All @@ -151,6 +143,8 @@ func DefaultPipelineParameters(prs *v1beta1.PipelineRun) (*v1beta1.PipelineRun,

// lets validate to make sure its valid
ctx := context.TODO()
// lets enable alpha fields
ctx = enableAlphaAPIFields(ctx)

// lets avoid missing workspaces causing issues
if len(prs.Spec.Workspaces) > 0 {
Expand All @@ -175,6 +169,19 @@ func DefaultPipelineParameters(prs *v1beta1.PipelineRun) (*v1beta1.PipelineRun,
return prs, nil
}

func enableAlphaAPIFields(ctx context.Context) context.Context {
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{
"enable-api-fields": "alpha",
})
cfg := &config.Config{
Defaults: &config.Defaults{
DefaultTimeoutMinutes: 60,
},
FeatureFlags: featureFlags,
}
return config.ToContext(ctx, cfg)
}

func addDefaultParameterSpecs(params []v1beta1.ParamSpec, defaults []v1beta1.ParamSpec) []v1beta1.ParamSpec {
for _, dp := range defaults {
found := false
Expand Down
Loading