Skip to content

Commit e9dabf8

Browse files
committed
Use service connection credentials from git config for GitHub API calls
1 parent f934b71 commit e9dabf8

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

common/config/azure-pipelines/bump-decoupled-deps.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ extends:
113113
REPO_SLUG=$(git remote get-url origin | sed -E 's#.*github\.com[:/](.+/[^.]+)(\.git)?$#\1#')
114114
echo "Repository: ${REPO_SLUG}"
115115
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+
116123
PR_TITLE="$(CommitMessage)"
117124
PR_BODY="Automated PR to bump decoupled local dependencies to the latest published versions."
118125
API_BASE="https://api.github.com/repos/${REPO_SLUG}"
@@ -136,22 +143,22 @@ extends:
136143
# Check if a PR already exists for this branch
137144
OWNER=$(echo "${REPO_SLUG}" | cut -d/ -f1)
138145
EXISTING_PR=$(github_api \
139-
-H "Authorization: token ${GITHUB_TOKEN}" \
146+
-H "$AUTH_HEADER" \
140147
-H "Accept: application/vnd.github+json" \
141148
"${API_BASE}/pulls?head=${OWNER}:$(BranchName)&state=open" \
142149
| jq '.[0].number // empty')
143150
144151
if [ -n "$EXISTING_PR" ]; then
145152
echo "Updating existing PR #${EXISTING_PR}"
146153
github_api -X PATCH \
147-
-H "Authorization: token ${GITHUB_TOKEN}" \
154+
-H "$AUTH_HEADER" \
148155
-H "Accept: application/vnd.github+json" \
149156
"${API_BASE}/pulls/${EXISTING_PR}" \
150157
-d "$(jq -n --arg body "$PR_BODY" '{body: $body}')"
151158
else
152159
echo "Creating new PR"
153160
github_api -X POST \
154-
-H "Authorization: token ${GITHUB_TOKEN}" \
161+
-H "$AUTH_HEADER" \
155162
-H "Accept: application/vnd.github+json" \
156163
"${API_BASE}/pulls" \
157164
-d "$(jq -n \
@@ -163,5 +170,3 @@ extends:
163170
fi
164171
displayName: 'Create or update GitHub PR'
165172
condition: and(succeeded(), eq(variables.HasChanges, 'true'))
166-
env:
167-
GITHUB_TOKEN: $(GitHubToken)

0 commit comments

Comments
 (0)