-
Notifications
You must be signed in to change notification settings - Fork 3
89 lines (85 loc) · 3.28 KB
/
move-on-merge-conflict.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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