Skip to content

Commit

Permalink
workflow updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Brijeshthummar02 committed Oct 20, 2024
1 parent 3c0a640 commit 1b718fe
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 0 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/autocomment-on-events.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Auto Comment on Events

on:
issues:
types: [opened, closed]
pull_request_target:
types: [opened, closed]

permissions:
issues: write
pull-requests: write

jobs:
# Job for commenting on opened issues
comment-on-issue-open:
if: github.event_name == 'issues' && github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Add Comment to Opened Issue
run: |
COMMENT=$(cat <<EOF
{
"body": "Thank you for creating this issue! 🎉 We'll look into it as soon as possible. In the meantime, please make sure to provide all the necessary details and context. If you have any questions or additional information, feel free to add them here. Your contributions are highly appreciated! 😊\n\nYou can also check our [CONTRIBUTING.md](https://github.com/dmotts/yt-to-gdrive-uploader/blob/main/CONTRIBUTING.md) for guidelines on contributing to this project."
}
EOF
)
RESPONSE=$(curl -s -o response.json -w "%{http_code}" \
-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 "$COMMENT")
cat response.json
if [ "$RESPONSE" -ne 201 ]; then
echo "Failed to add comment"
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Job for commenting on closed issues
comment-on-issue-close:
if: github.event_name == 'issues' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Greet User on Issue Close
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = context.payload.issue;
const issueCreator = issue.user.login;
const issueNumber = issue.number;
const greetingMessage = `Hello @${issueCreator}! Your issue #${issueNumber} has been closed. Thank you for your contribution!`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
});
# Job for commenting on merged pull requests
comment-on-pr-merge:
if: github.event_name == 'pull_request_target' && github.event.action == 'closed' && github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Add Comment to Merged PR
run: |
COMMENT=$(cat <<EOF
{
"body": "🎉 Your pull request has been successfully merged! 🎉 Thank you for your valuable contribution to our project. Your efforts are greatly appreciated. Feel free to reach out if you have any more contributions or if there's anything else we can assist you with. Keep up the fantastic work! 🚀"
}
EOF
)
RESPONSE=$(curl -s -o response.json -w "%{http_code}" \
-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 "$COMMENT")
cat response.json
if [ "$RESPONSE" -ne 201 ]; then
echo "Failed to add comment"
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Job for commenting on opened pull requests
comment-on-pr-open:
if: github.event_name == 'pull_request_target' && github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Add Comment to Opened PR
run: |
COMMENT=$(cat <<EOF
{
"body": "Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. In the meantime, please ensure that your changes align with our [CONTRIBUTING.md](https://github.com/dmotts/yt-to-gdrive-uploader/blob/main/CONTRIBUTING.md). If there are any specific instructions or feedback regarding your PR, we'll provide them here. Thanks again for your contribution! 😊"
}
EOF
)
RESPONSE=$(curl -s -o response.json -w "%{http_code}" \
-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 "$COMMENT")
cat response.json
if [ "$RESPONSE" -ne 201 ]; then
echo "Failed to add comment"
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Common Tests:Linting, Unit test, Build test

# 1. Linting Test (ESLint + Prettier)
# 2. TypeScript Type-Checking (if using TypeScript)
# 3. Unit Tests (with a framework like Jest or Vitest)
# 4. Integration Tests (if applicable)
# 5. Build Test (ensure the project builds without errors)
# 6. Deployment Test (automated deployment upon successful tests)


name: CI Workflow

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- run: npm install
- run: npm run lint

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- run: npm install
- run: npm run test

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
- run: npm install
- run: npm run build
30 changes: 30 additions & 0 deletions .github/workflows/close-issue-on-pr-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Close Issue on PR Merge

on:
pull_request:
types: [closed]

jobs:
close-issue:
runs-on: ubuntu-latest

if: github.event.pull_request.merged == true

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Check for issue reference
run: |
ISSUE_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -oP '(?<=#)\d+')
echo "Issue number: $ISSUE_NUMBER"
if [ -n "$ISSUE_NUMBER" ]; then
echo "Closing issue #$ISSUE_NUMBER"
curl -X PATCH \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE_NUMBER \
-d '{"state":"closed"}'
else
echo "No issue referenced in the PR description"
fi

0 comments on commit 1b718fe

Please sign in to comment.