Skip to content

Commit a4fcb17

Browse files
Add validation for Azure DevOps org and PAT when link-commits-to-pull-request is true
Co-authored-by: joshjohanning <[email protected]>
1 parent 105026c commit a4fcb17

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

__tests__/action.test.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,65 @@ test_comment_id_logic() {
270270
fi
271271
}
272272

273+
# Test Suite: Azure DevOps Configuration Validation
274+
test_azdo_config_validation() {
275+
echo ""
276+
echo -e "${YELLOW}Testing: Azure DevOps Configuration Validation${NC}"
277+
echo "========================================"
278+
279+
# Test when both org and PAT are set (valid)
280+
ORG="my-org"
281+
PAT="my-pat-token"
282+
if [ -z "$ORG" ] || [ -z "$PAT" ]; then
283+
TESTS_RUN=$((TESTS_RUN + 1))
284+
TESTS_FAILED=$((TESTS_FAILED + 1))
285+
echo -e "${RED}${NC} Should pass when both org and PAT are set"
286+
else
287+
TESTS_RUN=$((TESTS_RUN + 1))
288+
TESTS_PASSED=$((TESTS_PASSED + 1))
289+
echo -e "${GREEN}${NC} Should pass when both org and PAT are set"
290+
fi
291+
292+
# Test when org is empty (invalid)
293+
ORG=""
294+
PAT="my-pat-token"
295+
if [ -z "$ORG" ] || [ -z "$PAT" ]; then
296+
TESTS_RUN=$((TESTS_RUN + 1))
297+
TESTS_PASSED=$((TESTS_PASSED + 1))
298+
echo -e "${GREEN}${NC} Should fail when org is empty"
299+
else
300+
TESTS_RUN=$((TESTS_RUN + 1))
301+
TESTS_FAILED=$((TESTS_FAILED + 1))
302+
echo -e "${RED}${NC} Should fail when org is empty"
303+
fi
304+
305+
# Test when PAT is empty (invalid)
306+
ORG="my-org"
307+
PAT=""
308+
if [ -z "$ORG" ] || [ -z "$PAT" ]; then
309+
TESTS_RUN=$((TESTS_RUN + 1))
310+
TESTS_PASSED=$((TESTS_PASSED + 1))
311+
echo -e "${GREEN}${NC} Should fail when PAT is empty"
312+
else
313+
TESTS_RUN=$((TESTS_RUN + 1))
314+
TESTS_FAILED=$((TESTS_FAILED + 1))
315+
echo -e "${RED}${NC} Should fail when PAT is empty"
316+
fi
317+
318+
# Test when both are empty (invalid)
319+
ORG=""
320+
PAT=""
321+
if [ -z "$ORG" ] || [ -z "$PAT" ]; then
322+
TESTS_RUN=$((TESTS_RUN + 1))
323+
TESTS_PASSED=$((TESTS_PASSED + 1))
324+
echo -e "${GREEN}${NC} Should fail when both org and PAT are empty"
325+
else
326+
TESTS_RUN=$((TESTS_RUN + 1))
327+
TESTS_FAILED=$((TESTS_FAILED + 1))
328+
echo -e "${RED}${NC} Should fail when both org and PAT are empty"
329+
fi
330+
}
331+
273332
# Run all tests
274333
main() {
275334
echo "========================================"
@@ -283,6 +342,7 @@ main() {
283342
test_short_sha
284343
test_env_checks
285344
test_comment_id_logic
345+
test_azdo_config_validation
286346

287347
# Print summary
288348
echo ""

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ runs:
8686
8787
if ${{ inputs.link-commits-to-pull-request }}; then
8888
# make the call to main.js to do the linking
89-
# TODO: check to see if org/pat are set
89+
# Check to see if org/pat are set
90+
if [ -z "${{ inputs.azure-devops-organization }}" ] || [ -z "${{ inputs.azure-devops-token }}" ]; then
91+
echo "::error title=Missing Azure DevOps Configuration::Azure DevOps organization and token are required when link-commits-to-pull-request is true"
92+
exit 1
93+
fi
9094
echo "Attempting to link work item ${WORKITEM} to pull request ${PULL_NUMBER}..."
9195
REPO_TOKEN=${{ inputs.github-token }} AZURE_DEVOPS_ORG=${{ inputs.azure-devops-organization }} AZURE_DEVOPS_PAT=${{ inputs.azure-devops-token }} WORKITEMID=$WORKITEM PULLREQUESTID=${{ github.event.number }} REPO=${{ github.repository }} node $main
9296
echo "...PR linked to work item"

0 commit comments

Comments
 (0)