@@ -100,73 +100,8 @@ extends:
100100 displayName: 'Generate change files'
101101 condition: and(succeeded(), eq(variables.HasChanges, 'true'))
102102
103- - bash : |
104- set -e
105- git push origin $(BranchName) --force
106- displayName: 'Push branch'
107- condition: and(succeeded(), eq(variables.HasChanges, 'true'))
108-
109- - bash : |
110- set -e
111-
112- # Derive owner/repo from the git remote
113- REPO_SLUG=$(git remote get-url origin | sed -E 's#.*github\.com[:/](.+/[^.]+)(\.git)?$#\1#')
114- echo "Repository: ${REPO_SLUG}"
115-
116- # Extract the authorization header that AzDO configured via persistCredentials
117- AUTH_HEADER=$(git config --get-regexp 'http\..*\.extraheader' | head -1 | sed 's/^[^ ]* //')
118- if [ -z "$AUTH_HEADER" ]; then
119- echo "##[error]Could not extract authorization header from git config"
120- exit 1
121- fi
122-
123- PR_TITLE="$(CommitMessage)"
124- PR_BODY="Automated PR to bump decoupled local dependencies to the latest published versions."
125- API_BASE="https://api.github.com/repos/${REPO_SLUG}"
126-
127- # Helper to call the GitHub API and fail with a visible error
128- github_api() {
129- local RESPONSE HTTP_CODE
130- RESPONSE=$(curl -s -w "\n%{http_code}" "$@")
131- HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
132- BODY=$(echo "$RESPONSE" | sed '$d')
133-
134- if [[ "$HTTP_CODE" -ge 200 && "$HTTP_CODE" -lt 300 ]]; then
135- echo "$BODY"
136- else
137- echo "::error::GitHub API returned HTTP ${HTTP_CODE}:" >&2
138- echo "$BODY" >&2
139- return 1
140- fi
141- }
142-
143- # Check if a PR already exists for this branch
144- OWNER=$(echo "${REPO_SLUG}" | cut -d/ -f1)
145- EXISTING_PR=$(github_api \
146- -H "$AUTH_HEADER" \
147- -H "Accept: application/vnd.github+json" \
148- "${API_BASE}/pulls?head=${OWNER}:$(BranchName)&state=open" \
149- | jq '.[0].number // empty')
150-
151- if [ -n "$EXISTING_PR" ]; then
152- echo "Updating existing PR #${EXISTING_PR}"
153- github_api -X PATCH \
154- -H "$AUTH_HEADER" \
155- -H "Accept: application/vnd.github+json" \
156- "${API_BASE}/pulls/${EXISTING_PR}" \
157- -d "$(jq -n --arg body "$PR_BODY" '{body: $body}')"
158- else
159- echo "Creating new PR"
160- github_api -X POST \
161- -H "$AUTH_HEADER" \
162- -H "Accept: application/vnd.github+json" \
163- "${API_BASE}/pulls" \
164- -d "$(jq -n \
165- --arg title "$PR_TITLE" \
166- --arg body "$PR_BODY" \
167- --arg head "$(BranchName)" \
168- --arg base "main" \
169- '{title: $title, body: $body, head: $head, base: $base}')"
170- fi
171- displayName: 'Create or update GitHub PR'
172- condition: and(succeeded(), eq(variables.HasChanges, 'true'))
103+ - template : /common/config/azure-pipelines/templates/push-and-create-github-pr.yaml@self
104+ parameters :
105+ BranchName : $(BranchName)
106+ PrTitle : $(CommitMessage)
107+ PrDescription : ' Automated PR to bump decoupled local dependencies to the latest published versions.'
0 commit comments