Skip to content

Commit

Permalink
Merge pull request #14 from Megh2005/revert-13-workflows/update
Browse files Browse the repository at this point in the history
Revert "feat: improved and corrected existing github workflows"
  • Loading branch information
Megh2005 authored Jan 10, 2025
2 parents 6adc32c + 0ab5115 commit 4688cf3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 129 deletions.
30 changes: 20 additions & 10 deletions .github/workflows/auto_comment_pr_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@ permissions:
jobs:
comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.event.pull_request.merged == true

steps:
- name: Add Comment to PR
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.name,
issue_number: context.issue.number,
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! 🚀'
});
- name: Checkout Repository
uses: actions/checkout@v2

- name: Add Comment to Issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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
)
curl -X POST \
-H "Authorization: Bearer $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"
30 changes: 9 additions & 21 deletions .github/workflows/close_issue_comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,26 @@ on:
issues:
types: [closed]

permissions:
issues: write

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

permissions:
issues: write
steps:
- name: Greet User
uses: actions/github-script@v7
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 closer = context.payload.sender.login;
const wasClosedByCreator = issueCreator === closer;
let greetingMessage = `👋 Hello @${issueCreator}!\n\n`;
greetingMessage += `Thank you for reporting this issue. Issue #${issueNumber} has been closed`;
if (!wasClosedByCreator) {
greetingMessage += ` by @${closer}`;
}
greetingMessage += `. If you have any questions or need further assistance, please don't hesitate to reach out!\n\n`;
greetingMessage += `We appreciate your contribution to making our project better! 🙌`;
await github.rest.issues.createComment({
const greetingMessage = `Hello @${issueCreator}! Your issue #${issueNumber} has been closed. Thank you!`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.name,
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
});
});
60 changes: 19 additions & 41 deletions .github/workflows/close_issue_on_pr_merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,27 @@ on:
pull_request:
types: [closed]

permissions:
issues: write
pull-requests: read

jobs:
close-issues:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true

steps:
- name: Close linked issues
uses: actions/github-script@v7
with:
script: |
const prBody = context.payload.pull_request.body || '';
const prNumber = context.payload.pull_request.number;
// Find issue references using regex
const issueRefs = prBody.match(/#(\d+)/g) || [];
for (const ref of issueRefs) {
const issueNumber = ref.substring(1);
console.log(`Processing issue #${issueNumber}`);
try {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.name,
issue_number: parseInt(issueNumber),
body: `🔗 This issue has been closed automatically because it was linked to pull request #${prNumber} which has been merged.\n\nIf you believe this issue still needs attention, please reopen it or create a new issue with additional details.`
});
// Close the issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.name,
issue_number: parseInt(issueNumber),
state: 'closed',
state_reason: 'completed'
});
console.log(`Successfully closed issue #${issueNumber}`);
} catch (error) {
console.error(`Error processing issue #${issueNumber}:`, error);
}
}
- name: Checkout repository
uses: actions/checkout@v2

- name: Close linked issues
if: github.event.pull_request.merged == true
run: |
ISSUES=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | grep -Eo '#[0-9]+' | tr -d '#')
for ISSUE in $ISSUES
do
echo "Closing issue #$ISSUE"
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE/comments \
-d '{"body":"Closed by PR #${{ github.event.pull_request.number }}"}'
curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE \
-d '{"state":"closed"}'
done
62 changes: 5 additions & 57 deletions .github/workflows/validate-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,65 +6,13 @@ on:
- opened
- edited

permissions:
issues: write

jobs:
validate-template:
runs-on: ubuntu-latest

steps:
- name: Validate Issue Template
uses: actions/github-script@v7
with:
script: |
const issue = context.payload.issue
// Check if the issue uses our template form
if (!issue.body.includes('### ISSUE NAME')) {
const errorMessage = `
👋 Hello @${issue.user.login},

Thank you for creating this issue! However, it seems you haven't used our issue template form.
Please create a new issue using the issue template form provided.

You can do this by:
1. Going to the Issues tab
2. Clicking "New Issue"
3. Selecting "Contributor Issue Form"

This helps us better organize and address your concerns.
`;
// Add comment to the issue
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.name,
issue_number: issue.number,
body: errorMessage.trim()
});
// Close the issue as it doesn't use the template
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.name,
issue_number: issue.number,
state: 'closed',
state_reason: 'not_planned'
});
core.setFailed('Issue was not created using the template form');
} else {
// Issue uses the template form
// We can add additional labels if needed
if (!issue.labels.some(label => label.name === 'needs triage')) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.name,
issue_number: issue.number,
labels: ['needs triage']
});
}
}
- name: Check Issue Template
if: github.event.issue.body == null || !github.event.issue.body.contains('Your Name')
run: |
echo "::error::The issue does not follow the required template. Please fill out all fields."
exit 1

0 comments on commit 4688cf3

Please sign in to comment.