Skip to content

Commit b62bc25

Browse files
Roming22gabemontero
authored andcommitted
Refactor update-dependencies 2/2
* Create or update Pull Request Signed-off-by: Romain Arnaud <[email protected]>
1 parent 7d6a86c commit b62bc25

File tree

1 file changed

+52
-15
lines changed

1 file changed

+52
-15
lines changed

.tekton/tasks/update-repository.yaml

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ metadata:
77
app.kubernetes.io/version: "0.1"
88
annotations:
99
tekton.dev/pipelines.minVersion: "0.12.1"
10-
tekton.dev/tags: "appstudio, hacbs"
1110
name: update-repository
1211
spec:
1312
description: |
@@ -30,15 +29,6 @@ spec:
3029
- name: SCRIPT_ARGS
3130
description: Arguments to the bash script
3231
type: array
33-
- name: shared-secret
34-
default: infra-deployments-pr-creator
35-
description: secret in the namespace which contains private key for the GitHub App
36-
- name: GITHUB_APP_ID
37-
description: ID of Github app used for updating PR
38-
default: "305606"
39-
- name: GITHUB_APP_INSTALLATION_ID
40-
description: Installation ID of Github app in the organization
41-
default: "35269675"
4232
- name: GIT_IMAGE
4333
description: Image reference containing the git command
4434
default: registry.redhat.io/openshift-pipelines/pipelines-git-init-rhel8:v1.8.2-8@sha256:a538c423e7a11aae6ae582a411fdb090936458075f99af4ce5add038bb6983e8
@@ -48,11 +38,6 @@ spec:
4838
- name: GIT_EMAIL
4939
description: Email to appear in the commit
5040
default: "[email protected]"
51-
volumes:
52-
- name: infra-deployments-pr-creator
53-
secret:
54-
# 'private-key' - private key for Github app
55-
secretName: $(params.shared-secret)
5641
steps:
5742
- name: git-clone-repository
5843
image: $(params.GIT_IMAGE)
@@ -67,6 +52,11 @@ spec:
6752
- name: TARGET_GH_URL
6853
value: $(params.TARGET_GH_URL)
6954
script: |
55+
#!/bin/bash
56+
set -o errexit
57+
set -o nounset
58+
set -o pipefail
59+
7060
WORK_DIR="${PWD}/${TARGET_GH_OWNER}/${TARGET_GH_NAME}"
7161
if [ -e "${WORK_DIR}" ]; then
7262
echo "Clean checkout of '${TARGET_GH_URL}/${TARGET_BRANCH}' in '${WORK_DIR}'"
@@ -126,14 +116,61 @@ spec:
126116
127117
# Run script
128118
"${SCRIPT_PATH}" "${SCRIPT_ARGS[@]}"
119+
# Based on https://github.com/tektoncd/catalog/tree/main/task/github-app-token/0.2/
120+
- name: create-pull-request
121+
image: quay.io/redhat-appstudio/github-app-token@sha256:b4f2af12e9beea68055995ccdbdb86cfe1be97688c618117e5da2243dc1da18e
122+
workingDir: $(workspaces.workdir.path)
123+
env:
124+
- name: COMMIT_BRANCH
125+
value: $(params.COMMIT_BRANCH)
126+
- name: GITHUB_API_URL
127+
value: https://api.github.com
128+
- name: TARGET_BRANCH
129+
value: $(params.TARGET_BRANCH)
130+
- name: TARGET_GH_NAME
131+
value: $(params.TARGET_GH_NAME)
132+
- name: TARGET_GH_OWNER
133+
value: $(params.TARGET_GH_OWNER)
134+
script: |
135+
#!/bin/bash
136+
set -o errexit
137+
set -o nounset
138+
set -o pipefail
139+
140+
# Go to repository directory
141+
WORK_DIR="${PWD}/${TARGET_GH_OWNER}/${TARGET_GH_NAME}"
142+
cd "${WORK_DIR}"
129143
130144
# Push changes
131145
if ! git ls-remote --heads origin | grep -q "/$COMMIT_BRANCH$" \
132146
|| ! git diff --quiet "origin/$COMMIT_BRANCH" ; then
133147
git push --force --set-upstream origin "$COMMIT_BRANCH"
148+
echo "Branch pushed successfully"
134149
else
135150
echo "No changes"
151+
exit 0
136152
fi
153+
154+
GITHUB_TOKEN=$(git remote get-url origin | sed "s|https\?://[^:]*:\([^@]*\)@.*|\1|")
155+
echo "GITHUB_TOKEN=$GITHUB_TOKEN"
156+
157+
DATA=$(cat << EOF
158+
{
159+
"title":"$(git log -1 --format="%s" | sed 's:":\\":g')",
160+
"body":"$(git log -1 --format="%b" | sed 's:":\\":g' | sed 's:$:\\n:g' | tr -d '\n')",
161+
"head":"$COMMIT_BRANCH",
162+
"base":"$TARGET_BRANCH"
163+
}
164+
EOF
165+
)
166+
167+
curl --location \
168+
--request POST \
169+
--header "Accept: application/vnd.github+json" \
170+
--header "Authorization: Bearer $GITHUB_TOKEN" \
171+
--header "X-GitHub-Api-Version: 2022-11-28" \
172+
"${GITHUB_API_URL}/repos/${TARGET_GH_OWNER}/${TARGET_GH_NAME}/pulls" \
173+
--data "$DATA"
137174
workspaces:
138175
- name: workdir
139176
description: Shared storage to keep a single copy of the repositories

0 commit comments

Comments
 (0)