-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-pr-on-push-to-develop.yml
More file actions
68 lines (59 loc) · 2.4 KB
/
Copy pathcreate-pr-on-push-to-develop.yml
File metadata and controls
68 lines (59 loc) · 2.4 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
name: create-pr-on-push-to-develop
run-name: Create Pull Request from Source Branch to Main
on:
push:
branches:
- develop
jobs:
create-pr:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.PAT_EXAMPLE }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get latest commit details
id: commit_details
run: |
COMMIT_SHA=$(git rev-parse HEAD)
COMMIT_TITLE=$(git log -1 --pretty=format:'%s' $COMMIT_SHA)
COMMIT_MESSAGE=$(git log -1 --pretty=format:'%B' $COMMIT_SHA)
COMMIT_AUTHOR=$(git log -1 --pretty=format:'%an' $COMMIT_SHA)
echo "commit_sha=${COMMIT_SHA}" >> $GITHUB_ENV
echo "commit_title=${COMMIT_TITLE}" >> $GITHUB_ENV
echo "commit_author=${COMMIT_AUTHOR}" >> $GITHUB_ENV
echo "${COMMIT_MESSAGE}" > commit_message.txt
- name: Map commit author to GitHub username
id: map_author
run: |
declare -A AUTHOR_MAP=( ["Akarsh Seggemu"]="akarsh" )
GITHUB_USERNAME=${AUTHOR_MAP["$commit_author"]}
echo "GITHUB_USERNAME=${GITHUB_USERNAME}" >> $GITHUB_ENV
- name: Determine labels based on commit message
id: determine_labels
run: |
declare -A LABEL_KEYWORDS
LABEL_KEYWORDS["bug"]="bug"
LABEL_KEYWORDS["doc"]="documentation"
LABEL_KEYWORDS["enhancement"]="enhancement"
LABEL_KEYWORDS["first issue"]="good first issue"
LABEL_KEYWORDS["help"]="help wanted"
LABEL_KEYWORDS["invalid"]="invalid"
LABEL_KEYWORDS["question"]="question"
LABEL_KEYWORDS["wontfix"]="wontfix"
COMMIT_TITLE="${{ env.commit_title }}"
COMMIT_MESSAGE=$(cat commit_message.txt)
LABELS=""
for KEYWORD in "${!LABEL_KEYWORDS[@]}"; do
if echo "$COMMIT_TITLE" "$COMMIT_MESSAGE" | grep -qi "$KEYWORD"; then
LABELS="${LABELS},${LABEL_KEYWORDS[$KEYWORD]}"
fi
done
# Remove leading comma
LABELS="${LABELS#,}"
echo "LABELS=${LABELS}" >> $GITHUB_ENV
- name: Create pull request
id: create_pr
run: |
COMMIT_MESSAGE=$(cat commit_message.txt) # Read commit message from the file
gh pr create --head develop --base main -t "${{ env.commit_title }}" -b "$COMMIT_MESSAGE" -a "${{ env.GITHUB_USERNAME }}" -l "${{ env.LABELS }}"