Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ Required software installed on runner:
- `grep`
- `cut`

### Action Output

The action provides visibility into linked work items through:

- **GitHub Actions Notices**: Work item links are displayed as notice annotations in the workflow run, making it easy to see which work items are linked
- **Job Summary**: A summary of all linked work items is added to the workflow run's job summary page, providing a quick reference of work items associated with the PR

## Screenshots

### Failing pull request, including comment back to the pull request showing why it failed
Expand Down
18 changes: 12 additions & 6 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## Test Summary

✅ **Bash Tests: 25/25 Passing**
✅ **Bash Tests: 33/33 Passing**
✅ **JavaScript Tests: 3/3 Passing**

## Overview

This project has two types of tests:

1. **Bash Script Tests** - Tests for the core action logic in `action.yml` ✅ (25 tests passing)
1. **Bash Script Tests** - Tests for the core action logic in `action.yml` ✅ (33 tests passing)
2. **JavaScript Tests** - Tests for the work item linking logic in `main.js` ✅ (3 tests passing)

## Bash Script Tests
Expand Down Expand Up @@ -47,9 +47,15 @@ The bash script tests focus on the core validation and automation logic.
- Verifying required commands exist (bash, jq, cut, grep, gh)

- ✅ **Comment ID Logic** (2 tests)

- Finding existing PR comments by content
- Handling non-existent comments

- ✅ **GitHub Actions Annotations** (8 tests)
- Testing notice annotation format for work items
- Testing job summary format for commits and PRs
- Verifying work item information is properly displayed

### Running Bash Tests

```bash
Expand All @@ -63,8 +69,8 @@ npm run test:bash
### Bash Test Results

```text
Total Tests: 25
Passed: 25
Total Tests: 33
Passed: 33
All tests passed!
```

Expand Down Expand Up @@ -115,10 +121,10 @@ npm test

This will run:

1. Bash tests (25 passing)
1. Bash tests (33 passing)
2. JavaScript tests (3 passing)

**Total: 28 tests passing** ✅
**Total: 36 tests passing** ✅

## Test Files

Expand Down
27 changes: 27 additions & 0 deletions __tests__/action.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,32 @@ test_comment_id_logic() {
fi
}

# Test Suite: GitHub Actions Annotations
test_github_annotations() {
echo ""
echo -e "${YELLOW}Testing: GitHub Actions Annotations${NC}"
echo "========================================"

# Test notice annotation format for work items
WORKITEM_NUMBER="12345"
NOTICE_OUTPUT="::notice title=Work Item Linked::Pull request linked to work item AB#${WORKITEM_NUMBER}"
assert_contains "$NOTICE_OUTPUT" "::notice" "Notice annotation should contain ::notice"
assert_contains "$NOTICE_OUTPUT" "AB#12345" "Notice should include work item number"
assert_contains "$NOTICE_OUTPUT" "title=Work Item Linked" "Notice should have title"

# Test summary format
PULL_NUMBER="42"
SHORT_COMMIT_SHA="abc123d"
SUMMARY_COMMIT="- Work item AB#${WORKITEM_NUMBER} (from commit ${SHORT_COMMIT_SHA}) linked to pull request #${PULL_NUMBER}"
SUMMARY_PR="- Pull request #${PULL_NUMBER} linked to work item AB#${WORKITEM_NUMBER}"

assert_contains "$SUMMARY_COMMIT" "Work item AB#12345" "Summary should include work item"
assert_contains "$SUMMARY_COMMIT" "from commit abc123d" "Summary should include commit SHA"
assert_contains "$SUMMARY_COMMIT" "pull request #42" "Summary should include PR number"
assert_contains "$SUMMARY_PR" "Pull request #42" "Summary should include PR number"
assert_contains "$SUMMARY_PR" "AB#12345" "Summary should include work item"
}

# Run all tests
main() {
echo "========================================"
Expand All @@ -283,6 +309,7 @@ main() {
test_short_sha
test_env_checks
test_comment_id_logic
test_github_annotations

# Print summary
echo ""
Expand Down
6 changes: 4 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ runs:
echo "Attempting to link work item ${WORKITEM} to pull request ${PULL_NUMBER}..."
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
echo "...PR linked to work item"
echo "::notice title=Work Item Linked::Work item AB#${WORKITEM} (from commit ${SHORT_COMMIT_SHA}) linked to pull request #${PULL_NUMBER}"
echo "- Work item AB#${WORKITEM} (from commit ${SHORT_COMMIT_SHA}) linked to pull request #${PULL_NUMBER}" >> $GITHUB_STEP_SUMMARY
fi
fi
done
Expand Down Expand Up @@ -135,8 +137,8 @@ runs:
WORKITEM_NUMBER=${WORKITEM:3}

echo "Pull request linked to work item number: $WORKITEM_NUMBER"
# TODO: validate work item?
# TODO: add this as an ::info or to the job summary?
echo "::notice title=Work Item Linked::Pull request linked to work item AB#${WORKITEM_NUMBER}"
echo "- Pull request #${PULL_NUMBER} linked to work item AB#${WORKITEM_NUMBER}" >> $GITHUB_STEP_SUMMARY
done
fi
fi