Skip to content

Commit

Permalink
Merge pull request #474 from poorvikaa08/pr-bot
Browse files Browse the repository at this point in the history
Enforce Push to Newly Created Branches, Not Main Branch
  • Loading branch information
vimistify authored Oct 9, 2024
2 parents 3591509 + 7d3ad9f commit e76fcd8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/PR_message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: PR Validation and Comment Bot

# Trigger the workflow on pull request creation
on:
pull_request:
types: [opened]

jobs:
check_branch:
runs-on: ubuntu-latest

steps:
- name: Check if PR is from main or master
run: |
if [[ "${{ github.event.pull_request.head.ref }}" == "main" || "${{ github.event.pull_request.head.ref }}" == "master" ]]; then
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
-d '{"body": "### :warning: Warning: Create a new branch!\n\nIt looks like this pull request is from the `main` or `master` branch, which is not allowed.. To keep the repository organized and avoid conflicts, you have to create a new branch. So please follow these steps:\n\n1. Close this PR.\n2. Create a new branch using `git checkout -b your-branch-name`.\n3. Make your changes in that branch and open a new PR.\n\nThank you!"}'
exit 1
fi
- name: Comment on valid PR
if: ${{ success() }}
run: |
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
-d '{"body": "### Thank you for opening a Pull Request!\n\nYour contribution is highly appreciated. Please make sure your PR meets the following guidelines:\n\n1. Follow our [contribution guidelines](https://link-to-guidelines).\n2. Ensure all code is properly documented.\n3. Add tests for your new code if applicable.\n4. Make sure you mention the issue # for which you were assigned.\n\nThank you for your contribution!"}'
18 changes: 18 additions & 0 deletions .github/workflows/bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Instructions Bot

# Trigger the workflow on issue assignment
on:
issues:
types: [assigned]

jobs:
add_pr_instructions:
runs-on: ubuntu-latest

steps:
- name: Add a comment with PR instructions
run: |
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
-d '{"body": "### Instructions for Creating a Pull Request:\n\n1. Fork the repository if you haven\'t already.\n2. Create a new branch for your work: `git checkout -b feature-branch-name`.\n3. Make your changes in this branch.\n4. Commit your changes with a clear message: `git commit -m \"Describe your changes\"`.\n5. Push your branch to your forked repository: `git push origin feature-branch-name`.\n6. Go to the original repository and click on **New Pull Request**.\n7. Select your branch and submit the PR for review.\n8. Link the PR to this issue by adding the keyword **Closes #issue_number** in the PR description.\n\nThank you!"}'

0 comments on commit e76fcd8

Please sign in to comment.