Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move detect conflict to main branch #3576

Merged
Merged
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
44 changes: 0 additions & 44 deletions .github/workflows/detect-conflict.yaml

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
branches: [main]

jobs:
has-merge-conflict:
uses: ./.github/workflows/move-on-merge-conflict.yaml
secrets: inherit

build:
uses: ./.github/workflows/build.yaml
secrets:
Expand Down
102 changes: 102 additions & 0 deletions .github/workflows/move-on-merge-conflict.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# File: .github/workflows/check-merge-conflicts.yml
name: Check Merge Conflicts and Update Jira

on:
workflow_call:
secrets:
JIRA_AUTH: { required: true }

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
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const {owner, repo } = context.repo;
const { data: pullRequests } = await github.rest.pulls.list({
owner,
repo,
state: 'open',
});
const branches = []
const filteredPrs = pullRequests.filter(pr => !pr.head.repo.fork && pr.head.ref.startsWith('NDT-') && !pr.draft);
for (const pr of filteredPrs) {
const prReviews = await github.rest.pulls.listReviews({
owner,
repo,
pull_number: pr.number,
});
const approved = prReviews.data.some(review => review.state === 'APPROVED');
if(approved) {
branches.push(pr.head.ref);
}
}

return branches;
- name: Process branches
env:
BRANCHES: ${{ steps.get_branches.outputs.result }}
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 "116113628+ccbc-service-account@users.noreply.github.com"
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
82 changes: 0 additions & 82 deletions .github/workflows/move-on-merge-conlifct.yaml

This file was deleted.

Loading