Skip to content

Commit

Permalink
Create create-pr-on-push-to-develop.yml
Browse files Browse the repository at this point in the history
 - Add workflow file to create PR for main branch on push to develop branch
  • Loading branch information
akarsh authored Jun 22, 2024
1 parent f56a2d8 commit e309df9
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/create-pr-on-push-to-develop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 }}"

0 comments on commit e309df9

Please sign in to comment.