forked from abhargav-mw/sampleRepo
-
Notifications
You must be signed in to change notification settings - Fork 11
86 lines (71 loc) · 2.42 KB
/
Copy pathpr_creation.yml
File metadata and controls
86 lines (71 loc) · 2.42 KB
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
name: Auto-create Feature Branches and PRs
on:
push:
branches:
- master
jobs:
create_branches_and_prs:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
env:
FEATURE_NAME: testRes
DEV_ASSIGNEE: dev-user
DOC_ASSIGNEE: doc-user
QA_ASSIGNEE: qa-user
RELEASE_ASSIGNEE: release-owner
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up GH CLI
run: |
sudo apt update
sudo apt install -y gh
- name: Configure GitHub CLI
run: gh auth setup-git
- name: Create branches if not exist
run: |
fname=${FEATURE_NAME}
base=main
echo "Creating branches for feature: $fname"
# Function to create branch if not exists
create_branch() {
branch=$1
from=$2
if ! git ls-remote --exit-code origin "refs/heads/$branch" >/dev/null 2>&1; then
echo "Creating branch $branch from $from"
git fetch origin $from
git branch $branch origin/$from
git push origin $branch
else
echo "Branch $branch already exists, skipping."
fi
}
create_branch src/$fname main
create_branch doc/$fname main
create_branch test/$fname src/$fname
create_branch feature/$fname main
- name: Create draft PRs
run: |
fname=${FEATURE_NAME}
echo "Creating draft PRs for $fname"
# Helper function to check and create PR
create_pr() {
head=$1
base=$2
title=$3
assignee=$4
if ! gh pr list --head $head --base $base --json headRefName,baseRefName --jq '.[] | select(.headRefName=="'$head'" and .baseRefName=="'$base'")' >/dev/null; then
echo "Creating PR: $head → $base"
gh pr create --base $base --head $head --title "$title" --draft --assignee $assignee
else
echo "PR from $head to $base already exists."
fi
}
create_pr src/$fname feature/$fname "Source changes for $fname"
create_pr doc/$fname feature/$fname "Docs for $fname"
create_pr test/$fname src/$fname "Tests for $fname"
create_pr feature/$fname main "Integrate $fname"