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
2 changes: 1 addition & 1 deletion .github/actions/enforce-pr-conventions/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ runs:
fi

if [[ -z "$BRANCH_REGEX" ]]; then
echo "valid-branch-regex=^(revert-)|(improvement|fix|feature|test|tmp)\/($JIRA_KEY)-[0-9]+[_-]{1}[A-Za-z0-9._-]+$" >> $GITHUB_OUTPUT
echo "valid-branch-regex=^(revert-)|(improvement|fix|feature|test|tmp)\/($JIRA_KEY)-[0-9]+[_-]{1}[A-Za-z0-9._-]+$|^copilot\/fix.*$" >> $GITHUB_OUTPUT
else
echo "valid-branch-regex=$BRANCH_REGEX" >> $GITHUB_OUTPUT
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
setup() {
# Runs everywhere
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
PATH="$DIR/..:$PATH"

# Mock GitHub Actions environment
export GITHUB_OUTPUT=/dev/null
}

@test "branch regex generation includes copilot/fix pattern" {
# Mock the generate-regex step behavior
export JIRA_KEY="JKEY"
export BRANCH_REGEX=""
export PR_REGEX=""

# Create a temp file to capture output instead of /dev/null
temp_output=$(mktemp)
export GITHUB_OUTPUT="$temp_output"

# Test the regex generation logic inline
if [[ -z "$BRANCH_REGEX" ]]; then
echo "valid-branch-regex=^(revert-)|(improvement|fix|feature|test|tmp)\/($JIRA_KEY)-[0-9]+[_-]{1}[A-Za-z0-9._-]+$|^copilot\/fix.*$" >> "$GITHUB_OUTPUT"
fi

# Verify the output contains the copilot/fix pattern
run grep "copilot" "$temp_output"
[ "$status" -eq 0 ]

# Extract the generated regex
generated_regex=$(grep "valid-branch-regex=" "$temp_output" | cut -d'=' -f2-)

# Test the regex with various branch names
test_traditional_branch="improvement/JKEY-12345-some-feature"
test_copilot_branch="copilot/fix-bug-123"
test_invalid_branch="invalid/branch"

[[ $test_traditional_branch =~ $generated_regex ]]
[[ $test_copilot_branch =~ $generated_regex ]]
[[ ! $test_invalid_branch =~ $generated_regex ]]

# Cleanup
rm "$temp_output"
}

@test "copilot/fix branch validation allows various patterns" {
# Test various copilot/fix branch patterns
export JIRA_KEY="JKEY"
regex="^(revert-)|(improvement|fix|feature|test|tmp)\/($JIRA_KEY)-[0-9]+[_-]{1}[A-Za-z0-9._-]+$|^copilot\/fix.*$"

# Should match
[[ "copilot/fix-bug-123" =~ $regex ]]
[[ "copilot/fix-aja" =~ $regex ]]
[[ "copilot/fix" =~ $regex ]]
[[ "copilot/fix_test" =~ $regex ]]
[[ "copilot/fix-with-many-dashes-and_underscores" =~ $regex ]]

# Should not match copilot branches that are not fix
[[ ! "copilot/feature-123" =~ $regex ]]
[[ ! "copilot/improvement-123" =~ $regex ]]
}

@test "traditional branch patterns still work" {
export JIRA_KEY="JKEY"
regex="^(revert-)|(improvement|fix|feature|test|tmp)\/($JIRA_KEY)-[0-9]+[_-]{1}[A-Za-z0-9._-]+$|^copilot\/fix.*$"

# Traditional patterns should still match
[[ "improvement/JKEY-12345-the-topic" =~ $regex ]]
[[ "fix/JKEY-67890_bug-fix" =~ $regex ]]
[[ "feature/JKEY-11111-new-feature" =~ $regex ]]
[[ "test/JKEY-22222-test-something" =~ $regex ]]
[[ "tmp/JKEY-33333-temporary" =~ $regex ]]
[[ "revert-123-improvement/JKEY-44444-revert" =~ $regex ]]
}
12 changes: 11 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,24 +581,34 @@ To exempt specific branch names from *both* checks, the optional input parameter

The inputs `jira-project-key`, `valid-branch-regex` and `valid-pr-title-regex` are optional: if `valid-branch-regex` or `valid-pr-title-regex` are not provided, the action will consume `jira-project-key` to generate the default regex.

**Default regex for Branch name**: `"^(revert-)|(improvement|fix|feature|test|tmp)\/($JIRA_KEY)-[0-9]+[_-]{1}[A-Za-z0-9._-]+$"`
**Default regex for Branch name**: `"^(revert-)|(improvement|fix|feature|test|tmp)\/($JIRA_KEY)-[0-9]+[_-]{1}[A-Za-z0-9._-]+$|^copilot\/fix.*$"`

If the branch name starts with `(revert-)` it will be considered valid.

Branches starting with `copilot/fix` are also supported for GitHub Copilot-generated fixes. For these branches, the Jira key should be included in the PR title instead of the branch name.

Examples:

✅ improvement/JKEY-12345-the-topic-of-the-branch

✅ revert-123-improvement/JKEY-12345-the-topic-of-the-branch

✅ copilot/fix-bug-123 (requires Jira key in PR title)

✅ copilot/fix-aja (requires Jira key in PR title)

❌ dev-uname-jkey-12345

❌ copilot/feature-123 (only copilot/fix* is supported)

**Default regex for PR title:**: `"^(Revert*)|^($JIRA_KEY)-[0-9]+ [A-Z]{1}.*$"`

If the PR title starts with "Revert", it will be considered valid.

If the PR title does not start with "Revert", it will be checked against `^($JIRA_KEY)-[0-9]+ [A-Z]{1}[A-Za-z].*$` regex.

**Note**: For `copilot/fix*` branches, the Jira key must be present in the PR title since these branches do not contain the Jira key in their name.

Examples:

✅ JKEY-12345 The title of the Merge Commit
Expand Down