@@ -7,7 +7,6 @@ metadata:
7
7
app.kubernetes.io/version : " 0.1"
8
8
annotations :
9
9
tekton.dev/pipelines.minVersion : " 0.12.1"
10
- tekton.dev/tags : " appstudio, hacbs"
11
10
name : update-repository
12
11
spec :
13
12
description : |
30
29
- name : SCRIPT_ARGS
31
30
description : Arguments to the bash script
32
31
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"
42
32
- name : GIT_IMAGE
43
33
description : Image reference containing the git command
44
34
default : registry.redhat.io/openshift-pipelines/pipelines-git-init-rhel8:v1.8.2-8@sha256:a538c423e7a11aae6ae582a411fdb090936458075f99af4ce5add038bb6983e8
48
38
- name : GIT_EMAIL
49
39
description : Email to appear in the commit
50
40
51
- volumes :
52
- - name : infra-deployments-pr-creator
53
- secret :
54
- # 'private-key' - private key for Github app
55
- secretName : $(params.shared-secret)
56
41
steps :
57
42
- name : git-clone-repository
58
43
image : $(params.GIT_IMAGE)
67
52
- name : TARGET_GH_URL
68
53
value : $(params.TARGET_GH_URL)
69
54
script : |
55
+ #!/bin/bash
56
+ set -o errexit
57
+ set -o nounset
58
+ set -o pipefail
59
+
70
60
WORK_DIR="${PWD}/${TARGET_GH_OWNER}/${TARGET_GH_NAME}"
71
61
if [ -e "${WORK_DIR}" ]; then
72
62
echo "Clean checkout of '${TARGET_GH_URL}/${TARGET_BRANCH}' in '${WORK_DIR}'"
@@ -126,14 +116,61 @@ spec:
126
116
127
117
# Run script
128
118
"${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}"
129
143
130
144
# Push changes
131
145
if ! git ls-remote --heads origin | grep -q "/$COMMIT_BRANCH$" \
132
146
|| ! git diff --quiet "origin/$COMMIT_BRANCH" ; then
133
147
git push --force --set-upstream origin "$COMMIT_BRANCH"
148
+ echo "Branch pushed successfully"
134
149
else
135
150
echo "No changes"
151
+ exit 0
136
152
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"
137
174
workspaces :
138
175
- name : workdir
139
176
description : Shared storage to keep a single copy of the repositories
0 commit comments