Skip to content

Commit 79ff148

Browse files
Improve error messages to specify which configuration is missing
Co-authored-by: joshjohanning <19912012+joshjohanning@users.noreply.github.com>
1 parent a4fcb17 commit 79ff148

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

__tests__/action.test.sh

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,30 @@ test_azdo_config_validation() {
279279
# Test when both org and PAT are set (valid)
280280
ORG="my-org"
281281
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
282+
ORG_CHECK_FAILED=false
283+
PAT_CHECK_FAILED=false
284+
285+
if [ -z "$ORG" ]; then
286+
ORG_CHECK_FAILED=true
287+
fi
288+
if [ -z "$PAT" ]; then
289+
PAT_CHECK_FAILED=true
290+
fi
291+
292+
if [ "$ORG_CHECK_FAILED" = false ] && [ "$PAT_CHECK_FAILED" = false ]; then
287293
TESTS_RUN=$((TESTS_RUN + 1))
288294
TESTS_PASSED=$((TESTS_PASSED + 1))
289295
echo -e "${GREEN}${NC} Should pass when both org and PAT are set"
296+
else
297+
TESTS_RUN=$((TESTS_RUN + 1))
298+
TESTS_FAILED=$((TESTS_FAILED + 1))
299+
echo -e "${RED}${NC} Should pass when both org and PAT are set"
290300
fi
291301

292-
# Test when org is empty (invalid)
302+
# Test when org is empty (invalid) - should fail on org check
293303
ORG=""
294304
PAT="my-pat-token"
295-
if [ -z "$ORG" ] || [ -z "$PAT" ]; then
305+
if [ -z "$ORG" ]; then
296306
TESTS_RUN=$((TESTS_RUN + 1))
297307
TESTS_PASSED=$((TESTS_PASSED + 1))
298308
echo -e "${GREEN}${NC} Should fail when org is empty"
@@ -302,10 +312,10 @@ test_azdo_config_validation() {
302312
echo -e "${RED}${NC} Should fail when org is empty"
303313
fi
304314

305-
# Test when PAT is empty (invalid)
315+
# Test when PAT is empty (invalid) - should fail on PAT check
306316
ORG="my-org"
307317
PAT=""
308-
if [ -z "$ORG" ] || [ -z "$PAT" ]; then
318+
if [ -z "$PAT" ]; then
309319
TESTS_RUN=$((TESTS_RUN + 1))
310320
TESTS_PASSED=$((TESTS_PASSED + 1))
311321
echo -e "${GREEN}${NC} Should fail when PAT is empty"
@@ -315,13 +325,13 @@ test_azdo_config_validation() {
315325
echo -e "${RED}${NC} Should fail when PAT is empty"
316326
fi
317327

318-
# Test when both are empty (invalid)
328+
# Test when both are empty (invalid) - should fail on org check first
319329
ORG=""
320330
PAT=""
321-
if [ -z "$ORG" ] || [ -z "$PAT" ]; then
331+
if [ -z "$ORG" ]; then
322332
TESTS_RUN=$((TESTS_RUN + 1))
323333
TESTS_PASSED=$((TESTS_PASSED + 1))
324-
echo -e "${GREEN}${NC} Should fail when both org and PAT are empty"
334+
echo -e "${GREEN}${NC} Should fail when both org and PAT are empty (fails on org check)"
325335
else
326336
TESTS_RUN=$((TESTS_RUN + 1))
327337
TESTS_FAILED=$((TESTS_FAILED + 1))

action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,12 @@ runs:
8787
if ${{ inputs.link-commits-to-pull-request }}; then
8888
# make the call to main.js to do the linking
8989
# 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"
90+
if [ -z "${{ inputs.azure-devops-organization }}" ]; then
91+
echo "::error title=Missing Azure DevOps Configuration::Azure DevOps organization is required when link-commits-to-pull-request is true"
92+
exit 1
93+
fi
94+
if [ -z "${{ inputs.azure-devops-token }}" ]; then
95+
echo "::error title=Missing Azure DevOps Configuration::Azure DevOps token is required when link-commits-to-pull-request is true"
9296
exit 1
9397
fi
9498
echo "Attempting to link work item ${WORKITEM} to pull request ${PULL_NUMBER}..."

0 commit comments

Comments
 (0)