chore: test the push #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# File: .github/workflows/check-merge-conflicts.yml | |
name: Check Merge Conflicts and Update Jira | |
on: | |
workflow_call: | |
push: | |
jobs: | |
check_merge_conflicts: | |
environment: | |
name: development | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get branches to process | |
id: get_branches | |
run: | | |
echo "No branches provided as input, fetching branches starting with NDT" | |
git fetch --all | |
branches=$(git branch -r | grep 'origin/NDT' | sed 's|origin/||') | |
if [ -z "$branches" ]; then | |
echo "No branches starting with 'NDT' found." | |
echo "branches=[]" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
branches_json=$(printf '%s\n' $branches | jq -R . | jq -s .) | |
echo "Branches to process: $branches_json" | |
echo "branches=$branches_json" >> $GITHUB_OUTPUT | |
- name: Process branches | |
env: | |
BRANCHES: ${{ steps.get_branches.outputs.branches }} | |
JIRA_AUTH: ${{ secrets.JIRA_AUTH }} | |
run: | | |
set -e | |
branches=$(echo $BRANCHES | jq -r '.[]') | |
if [ -z "$branches" ]; then | |
echo "No branches to process." | |
exit 0 | |
fi | |
git config user.name "CCBC Service Account" | |
git config user.email "[email protected]" | |
for BRANCH in $branches; do | |
echo "Processing branch: $BRANCH" | |
git fetch origin $BRANCH | |
git checkout $BRANCH | |
git merge origin/main --no-commit --no-ff || MERGE_CONFLICT=1 | |
if [ "$MERGE_CONFLICT" -eq 1 ]; then | |
echo "Merge conflict detected in branch $BRANCH" | |
# Extract Jira issue key from branch name | |
JIRA_KEY=$(echo $BRANCH | grep -o 'NDT-[0-9]\+') | |
if [ -z "$JIRA_KEY" ]; then | |
echo "No Jira key found in branch name $BRANCH" | |
continue | |
fi | |
echo "Jira Key: $JIRA_KEY" | |
# Check issue status in Jira | |
response=$(curl -s -X GET \ | |
-H "Authorization: Basic $JIRA_AUTH" \ | |
-H "Content-Type: application/json" \ | |
"https://connectivitydivision.atlassian.net/rest/api/3/issue/$JIRA_KEY") | |
status=$(echo "$response" | jq -r '.fields.status.name') | |
echo "Issue status: $status" | |
if [ "$status" == "PO REVIEW" ]; then | |
echo "Moving issue $JIRA_KEY to Merge Conflict column" | |
curl -X POST \ | |
-H "Authorization: Basic $JIRA_AUTH" \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"transition": { | |
"id": "9" | |
} | |
}' \ | |
"https://connectivitydivision.atlassian.net/rest/api/3/issue/$JIRA_KEY/transitions" | |
else | |
echo "Issue $JIRA_KEY is not in PO REVIEW status" | |
fi | |
else | |
echo "No merge conflict in branch $BRANCH" | |
fi | |
# Clean up for next iteration | |
git reset --hard | |
git checkout main | |
MERGE_CONFLICT=0 | |
done |