Skip to content

Commit

Permalink
Fix image path in generate-releaseyaml.sh
Browse files Browse the repository at this point in the history
and generate some changes in go by rephrasing some of the sentences in
cli webhook gitlab.

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Feb 6, 2025
1 parent 9cac663 commit 1ce8970
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 48 deletions.
71 changes: 35 additions & 36 deletions hack/generate-releaseyaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set -euf

export TARGET_REPO_CONTROLLER=${TARGET_REPO_CONTROLLER:-ghcr.io/openshift-pipelines/pipelines-as-code/pipelines-as-code/pipelines-as-code/pipelines-as-code/pipelines-as-code-controller}
export TARGET_REPO_WATCHER=${TARGET_REPO_WATCHER:-ghcr.io/openshift-pipelines/pipelines-as-code/pipelines-as-code/pipelines-as-code/pipelines-as-code/pipelines-as-code-watcher}
export TARGET_REPO_WEBHOOK=${TARGET_REPO_WEBHOOK:-ghcr.io/openshift-pipelines/pipelines-as-code/pipelines-as-code/pipelines-as-code/pipelines-as-code/pipelines-as-code-webhook}
export TARGET_REPO_WATCHER=${TARGET_REPO_WATCHER:-ghcr.io/openshift-pipelines/pipelines-as-code/pipelines-as-code-watcher}
export TARGET_REPO_WEBHOOK=${TARGET_REPO_WEBHOOK:-ghcr.io/openshift-pipelines/pipelines-as-code/pipelines-as-code-webhook}
export TARGET_BRANCH=${TARGET_BRANCH:-main}
export TARGET_NAMESPACE=${TARGET_NAMESPACE:-pipelines-as-code}
export TARGET_OPENSHIFT=${TARGET_OPENSHIFT:-""}
Expand All @@ -15,44 +15,43 @@ trap clean EXIT

MODE=${1:-""}

if [[ -n ${MODE} && ${MODE} == ko ]];then
tmpfile=$(mktemp /tmp/.mm.XXXXXX)
clean() { rm -f ${tmpfile}; }
trap clean EXIT
ko resolve -f config/ > ${tmpfile}
if [[ -n ${MODE} && ${MODE} == ko ]]; then
tmpfile=$(mktemp /tmp/.mm.XXXXXX)
clean() { rm -f ${tmpfile}; }
trap clean EXIT
ko resolve -f config/ >${tmpfile}

if [[ ${TARGET_OPENSHIFT} != "" ]];then
ko resolve -f config/openshift >> ${tmpfile}
fi
if [[ ${TARGET_OPENSHIFT} != "" ]]; then
ko resolve -f config/openshift >>${tmpfile}
fi

files="${tmpfile}"
files="${tmpfile}"
else
files=$(find config -maxdepth 1 -name '*.yaml'|sort -n)
files=$(find config -maxdepth 1 -name '*.yaml' | sort -n)

if [[ ${TARGET_OPENSHIFT} != "" ]];then
files="${files} $(find config/openshift -maxdepth 1 -name '*.yaml'|sort -n)"
fi
if [[ ${TARGET_OPENSHIFT} != "" ]]; then
files="${files} $(find config/openshift -maxdepth 1 -name '*.yaml' | sort -n)"
fi
fi


for file in ${files};do
sed -e '/^$/d' -e '/^#/d' ${file} | head -1 | grep -q -- "---" || echo -e "---\n"
sed -r -e "s,(.*image:.*)ko://github.com/openshift-pipelines/pipelines-as-code/cmd/pipelines-as-code-controller.*,\1${TARGET_REPO_CONTROLLER}:${TARGET_BRANCH}\"," \
-r -e "s,(.*image:.*)ko://github.com/openshift-pipelines/pipelines-as-code/cmd/pipelines-as-code-watcher.*,\1${TARGET_REPO_WATCHER}:${TARGET_BRANCH}\"," \
-r -e "s,(.*image:.*)ko://github.com/openshift-pipelines/pipelines-as-code/cmd/pipelines-as-code-webhook.*,\1${TARGET_REPO_WEBHOOK}:${TARGET_BRANCH}\"," \
-e "s/(namespace: )\w+.*/\1${TARGET_NAMESPACE}/g" \
-e "s,app.kubernetes.io/version:.*,app.kubernetes.io/version: \"${TARGET_PAC_VERSION}\"," \
-e "s/Copyright[ ]*[0-9]{4}/Copyright $(date "+%Y")/" \
-e "/kind: Namespace$/ { n;n;s/name: .*/name: ${TARGET_NAMESPACE}/;}" \
-e "s/\"devel\"/\"${TARGET_PAC_VERSION}\"/" \
${file} > ${TMP}

# Remove openshift stuff apiGroups if we are not targetting openshift...
[[ -z ${TARGET_OPENSHIFT} ]] && {
sed -ir '/^[ ]*- apiGroups:.*route.openshift.io/,/verbs.*/d' ${TMP}
}

echo "" >> ${TMP}
tail -1 ${TMP} |grep -q "^$" && sed -i '$d' ${TMP} >> /tmp/aaaa
cat ${TMP}
for file in ${files}; do
sed -e '/^$/d' -e '/^#/d' ${file} | head -1 | grep -q -- "---" || echo -e "---\n"
sed -r -e "s,(.*image:.*)ko://github.com/openshift-pipelines/pipelines-as-code/cmd/pipelines-as-code-controller.*,\1${TARGET_REPO_CONTROLLER}:${TARGET_BRANCH}\"," \
-r -e "s,(.*image:.*)ko://github.com/openshift-pipelines/pipelines-as-code/cmd/pipelines-as-code-watcher.*,\1${TARGET_REPO_WATCHER}:${TARGET_BRANCH}\"," \
-r -e "s,(.*image:.*)ko://github.com/openshift-pipelines/pipelines-as-code/cmd/pipelines-as-code-webhook.*,\1${TARGET_REPO_WEBHOOK}:${TARGET_BRANCH}\"," \
-e "s/(namespace: )\w+.*/\1${TARGET_NAMESPACE}/g" \
-e "s,app.kubernetes.io/version:.*,app.kubernetes.io/version: \"${TARGET_PAC_VERSION}\"," \
-e "s/Copyright[ ]*[0-9]{4}/Copyright $(date "+%Y")/" \
-e "/kind: Namespace$/ { n;n;s/name: .*/name: ${TARGET_NAMESPACE}/;}" \
-e "s/\"devel\"/\"${TARGET_PAC_VERSION}\"/" \
${file} >${TMP}

# Remove openshift stuff apiGroups if we are not targetting openshift...
[[ -z ${TARGET_OPENSHIFT} ]] && {
sed -ir '/^[ ]*- apiGroups:.*route.openshift.io/,/verbs.*/d' ${TMP}
}

echo "" >>${TMP}
tail -1 ${TMP} | grep -q "^$" && sed -i '$d' ${TMP} >>/tmp/aaaa
cat ${TMP}
done
24 changes: 12 additions & 12 deletions pkg/cli/webhook/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ func (gl *gitLabConfig) Run(_ context.Context, opts *Options) (*response, error)
}, gl.create()
}

// Changes in askGLWebhookConfig function.
func (gl *gitLabConfig) askGLWebhookConfig(repoURL, controllerURL, apiURL, personalAccessToken string) error {
if repoURL == "" {
msg := "Please enter the git repository url you want to be configured: "
msg := "Enter the GitLab repository URL to configure: "
if err := prompt.SurveyAskOne(&survey.Input{Message: msg}, &repoURL,
survey.WithValidator(survey.Required)); err != nil {
return err
Expand All @@ -48,19 +49,17 @@ func (gl *gitLabConfig) askGLWebhookConfig(repoURL, controllerURL, apiURL, perso
fmt.Fprintf(gl.IOStream.Out, "✓ Setting up GitLab Webhook for Repository %s\n", repoURL)
}

msg := "Please enter the project ID for the repository you want to be configured, \n project ID refers to an unique ID (e.g. 34405323) shown at the top of your GitLab project :"
msg := "Enter the project ID of your GitLab repository.\nThe project ID is a unique number (e.g. 34405323) shown at the top of your GitLab project page: "
if err := prompt.SurveyAskOne(&survey.Input{Message: msg}, &gl.projectID,
survey.WithValidator(survey.Required)); err != nil {
return err
}

// set controller url
gl.controllerURL = controllerURL

// confirm whether to use the detected url
if gl.controllerURL != "" {
var answer bool
fmt.Fprintf(gl.IOStream.Out, "👀 I have detected a controller url: %s\n", gl.controllerURL)
fmt.Fprintf(gl.IOStream.Out, "👀 Controller URL detected: %s\n", gl.controllerURL)
err := prompt.SurveyAskOne(&survey.Confirm{
Message: "Do you want me to use it?",
Default: true,
Expand All @@ -75,14 +74,14 @@ func (gl *gitLabConfig) askGLWebhookConfig(repoURL, controllerURL, apiURL, perso

if gl.controllerURL == "" {
if err := prompt.SurveyAskOne(&survey.Input{
Message: "Please enter your controller public route URL: ",
Message: "Enter your controller's public route URL: ",
}, &gl.controllerURL, survey.WithValidator(survey.Required)); err != nil {
return err
}
}

data := random.AlphaString(12)
msg = fmt.Sprintf("Please enter the secret to configure the webhook for payload validation (default: %s): ", data)
msg = fmt.Sprintf("Enter a secret for webhook payload validation (default: %s): ", data)
var webhookSecret string
if err := prompt.SurveyAskOne(&survey.Input{Message: msg, Default: data}, &webhookSecret); err != nil {
return err
Expand All @@ -91,10 +90,10 @@ func (gl *gitLabConfig) askGLWebhookConfig(repoURL, controllerURL, apiURL, perso
gl.webhookSecret = webhookSecret

if personalAccessToken == "" {
fmt.Fprintln(gl.IOStream.Out, "ℹ ️You now need to create a GitLab personal access token with `api` scope")
fmt.Fprintln(gl.IOStream.Out, "ℹ ️Go to this URL to generate one https://gitlab.com/-/profile/personal_access_tokens, see https://is.gd/rOEo9B for documentation ")
fmt.Fprintln(gl.IOStream.Out, "ℹ ️You need to create a GitLab personal access token with 'api' scope")
fmt.Fprintln(gl.IOStream.Out, "ℹ ️Generate one at https://gitlab.com/-/profile/personal_access_tokens (see documentation: https://is.gd/rOEo9B)")
if err := prompt.SurveyAskOne(&survey.Password{
Message: "Please enter the GitLab access token: ",
Message: "Enter your GitLab access token: ",
}, &gl.personalAccessToken, survey.WithValidator(survey.Required)); err != nil {
return err
}
Expand All @@ -104,7 +103,7 @@ func (gl *gitLabConfig) askGLWebhookConfig(repoURL, controllerURL, apiURL, perso

if apiURL == "" {
if err := prompt.SurveyAskOne(&survey.Input{
Message: "Please enter your GitLab API URL: ",
Message: "Enter your GitLab API URL: ",
}, &gl.APIURL, survey.WithValidator(survey.Required)); err != nil {
return err
}
Expand All @@ -115,6 +114,7 @@ func (gl *gitLabConfig) askGLWebhookConfig(repoURL, controllerURL, apiURL, perso
return nil
}

// create function.
func (gl *gitLabConfig) create() error {
glClient, err := gl.newClient()
if err != nil {
Expand Down Expand Up @@ -145,7 +145,7 @@ func (gl *gitLabConfig) create() error {
resp.StatusCode, payload)
}

fmt.Fprintln(gl.IOStream.Out, "✓ Webhook has been created on your repository")
fmt.Fprintln(gl.IOStream.Out, "✓ Webhook successfully created on your repository")
return nil
}

Expand Down

0 comments on commit 1ce8970

Please sign in to comment.