Skip to content

Commit

Permalink
feat: PAC - try to read git info from local .git config
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
  • Loading branch information
zroubalik committed Mar 20, 2023
1 parent 99de349 commit 4070572
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 6 deletions.
13 changes: 11 additions & 2 deletions cmd/config_git_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/ory/viper"
"github.com/spf13/cobra"

"github.com/openshift-pipelines/pipelines-as-code/pkg/git"

"knative.dev/func/pkg/config"
fn "knative.dev/func/pkg/functions"
"knative.dev/func/pkg/pipelines"
Expand Down Expand Up @@ -142,10 +144,15 @@ func (c configGitSetConfig) Prompt(f fn.Function) (configGitSetConfig, error) {
return c, err
}

// try to read git url from the local .git settings
gitInfo := git.GetGitInfo(c.Path)

// prompt if git URL hasn't been set previously
if c.GitURL == "" {
// TODO we can try to read git url from the local .git settings
url := f.Build.Git.URL
if gitInfo.URL != "" {
url = gitInfo.URL
}
if err := survey.AskOne(&survey.Input{
Message: "The URL to Git repository with the function source code:",
Default: url,
Expand All @@ -157,8 +164,10 @@ func (c configGitSetConfig) Prompt(f fn.Function) (configGitSetConfig, error) {

// prompt if git revision hasn't been set previously
if c.GitRevision == "" {
// TODO we can try to read git url from the local .git settings
revision := f.Build.Git.Revision
if gitInfo.Branch != "" {
revision = gitInfo.Branch
}
if err := survey.AskOne(&survey.Input{
Message: "The Git branch or tag we are targeting:",
Help: "ie: main, refs/tags/*",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/heroku/color v0.0.6
github.com/hinshun/vt10x v0.0.0-20220228203356-1ab2cad5fd82
github.com/opencontainers/image-spec v1.1.0-rc2
github.com/openshift-pipelines/pipelines-as-code v0.17.0
github.com/openshift-pipelines/pipelines-as-code v0.17.1
github.com/openshift/source-to-image v1.3.1
github.com/ory/viper v1.7.5
github.com/pkg/errors v0.9.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,8 @@ github.com/opencontainers/selinux v1.10.2 h1:NFy2xCsjn7+WspbfZkUd5zyVeisV7VFbPSP
github.com/opencontainers/selinux v1.10.2/go.mod h1:cARutUbaUrlRClyvxOICCgKixCs6L05aUsohzA3EkHQ=
github.com/openshift-pipelines/pipelines-as-code v0.17.0 h1:RtUZp7sX46lP72UntAoDfhU1iZBiKDueTgLjGzmmUrA=
github.com/openshift-pipelines/pipelines-as-code v0.17.0/go.mod h1:5gCkO4y2PEFZ842tbF8376rD386DkoSyyQI3vjdqwq4=
github.com/openshift-pipelines/pipelines-as-code v0.17.1 h1:9+vnu3FMrfMy6R+jhaV6jvmVhDrXRYuGvgHHrCfTdrU=
github.com/openshift-pipelines/pipelines-as-code v0.17.1/go.mod h1:5gCkO4y2PEFZ842tbF8376rD386DkoSyyQI3vjdqwq4=
github.com/opentracing-contrib/go-stdlib v1.0.0/go.mod h1:qtI1ogk+2JhVPIXVc6q+NHziSmy2W5GbdQZFUHADCBU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
Expand Down
13 changes: 13 additions & 0 deletions pkg/pipelines/tekton/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (
// S2I related properties
defaultS2iImageScriptsUrl = "image:///usr/libexec/s2i"
quarkusS2iImageScriptsUrl = "image:///usr/local/s2i"

// The branch or tag we are targeting with Pipelines (ie: main, refs/tags/*)
defaultPipelinesTargetBranch = "main"
)

type templateData struct {
Expand All @@ -44,6 +47,9 @@ type templateData struct {
PvcName string
SecretName string

// The branch or tag we are targeting with Pipelines (ie: main, refs/tags/*)
PipelinesTargetBranch string

// Static entries
RepoUrl string
Revision string
Expand Down Expand Up @@ -85,6 +91,11 @@ func createPipelineRunTemplate(f fn.Function) error {
contextDir = "."
}

pipelinesTargetBranch := f.Build.Git.Revision
if pipelinesTargetBranch == "" {
pipelinesTargetBranch = defaultPipelinesTargetBranch
}

buildEnvs := []string{}
if len(f.Build.BuildEnvs) == 0 {
buildEnvs = []string{"="}
Expand Down Expand Up @@ -114,6 +125,8 @@ func createPipelineRunTemplate(f fn.Function) error {
PvcName: getPipelinePvcName(f),
SecretName: getPipelineSecretName(f),

PipelinesTargetBranch: pipelinesTargetBranch,

GitCloneTaskRef: taskGitCloneRef,
FuncBuildpacksTaskRef: taskFuncBuildpacksRef,
FuncS2iTaskRef: taskFuncS2iRef,
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipelines/tekton/templates_pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ metadata:
pipelinesascode.tekton.dev/on-event: "[push]"
# The branch or tag we are targeting (ie: main, refs/tags/*)
pipelinesascode.tekton.dev/on-target-branch: "[main]"
pipelinesascode.tekton.dev/on-target-branch: "[{{.PipelinesTargetBranch}}]"
# Fetch the git-clone task from hub
pipelinesascode.tekton.dev/task: {{.GitCloneTaskRef}}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipelines/tekton/templates_s2i.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ metadata:
pipelinesascode.tekton.dev/on-event: "[push]"
# The branch or tag we are targeting (ie: main, refs/tags/*)
pipelinesascode.tekton.dev/on-target-branch: "[main]"
pipelinesascode.tekton.dev/on-target-branch: "[{{.PipelinesTargetBranch}}]"
# Fetch the git-clone task from hub
pipelinesascode.tekton.dev/task: {{.GitCloneTaskRef}}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,15 @@ github.com/opencontainers/selinux/go-selinux
github.com/opencontainers/selinux/go-selinux/label
github.com/opencontainers/selinux/pkg/pwalk
github.com/opencontainers/selinux/pkg/pwalkdir
# github.com/openshift-pipelines/pipelines-as-code v0.17.0
# github.com/openshift-pipelines/pipelines-as-code v0.17.1
## explicit; go 1.18
github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode
github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1
github.com/openshift-pipelines/pipelines-as-code/pkg/cli
github.com/openshift-pipelines/pipelines-as-code/pkg/formatting
github.com/openshift-pipelines/pipelines-as-code/pkg/generated/clientset/versioned/scheme
github.com/openshift-pipelines/pipelines-as-code/pkg/generated/clientset/versioned/typed/pipelinesascode/v1alpha1
github.com/openshift-pipelines/pipelines-as-code/pkg/git
# github.com/openshift/source-to-image v1.3.1 => github.com/boson-project/source-to-image v1.3.2
## explicit; go 1.13
github.com/openshift/source-to-image/pkg/api
Expand Down

0 comments on commit 4070572

Please sign in to comment.