Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Github workflows For Task automation #403

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/auto_comment_on_issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Auto Comment on Issue

on:
issues:
types: [opened]

permissions:
issues: write

Comment on lines +7 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove duplicate permissions declaration.

The permissions are defined both at the workflow level and job level. The workflow-level permissions are sufficient, and the job-level permissions can be removed to avoid redundancy.

permissions:
  issues: write

jobs:
  comment:
    runs-on: ubuntu-latest
-   permissions:
-     issues: write
    steps:

Also applies to: 13-14

jobs:
comment:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Add Comment to Issue
run: |
COMMENT=$(cat <<EOF
{
"body": "Thank you for creating this issue! 🎉 We'll look into it as soon as possible."
}
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
Comment on lines +16 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance error handling and comment formatting.

While the basic functionality is implemented correctly, there are several areas for improvement:

  1. The JSON body needs proper escaping for special characters
  2. Error handling could be more robust
  3. The welcome message could be more informative by including links to contribution guidelines

Here's an improved implementation:

      - name: Add Comment to Issue
        run: |
          COMMENT=$(cat <<EOF
          {
-            "body": "Thank you for creating this issue! 🎉 We'll look into it as soon as possible."
+            "body": "Thank you for creating this issue! 🎉\n\nWe'll look into it as soon as possible. In the meantime, please make sure you have:\n\n- [ ] Provided a clear description\n- [ ] Added relevant labels\n- [ ] Checked for similar existing issues\n\nFor more information, check out our [contribution guidelines](../../CONTRIBUTING.md)."
          }
          EOF
          )
+         # Ensure curl succeeds
+         set -e
+         
          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")
+           -d "$(echo "$COMMENT" | jq -c '.')")
+
+         # Check for curl errors
+         if [ $? -ne 0 ]; then
+           echo "Failed to make API request"
+           exit 1
+         fi
+
          cat response.json
          if [ "$RESPONSE" -ne 201 ]; then
-           echo "Failed to add comment"
+           echo "Failed to add comment. Server responded with code $RESPONSE"
+           echo "Error details:"
+           jq '.message' response.json
            exit 1
          fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Add Comment to Issue
run: |
COMMENT=$(cat <<EOF
{
"body": "Thank you for creating this issue! 🎉 We'll look into it as soon as possible."
}
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
- name: Add Comment to Issue
run: |
COMMENT=$(cat <<EOF
{
"body": "Thank you for creating this issue! 🎉\n\nWe'll look into it as soon as possible. In the meantime, please make sure you have:\n\n- [ ] Provided a clear description\n- [ ] Added relevant labels\n- [ ] Checked for similar existing issues\n\nFor more information, check out our [contribution guidelines](../../CONTRIBUTING.md)."
}
EOF
)
# Ensure curl succeeds
set -e
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 "$(echo "$COMMENT" | jq -c '.')")
# Check for curl errors
if [ $? -ne 0 ]; then
echo "Failed to make API request"
exit 1
fi
cat response.json
if [ "$RESPONSE" -ne 201 ]; then
echo "Failed to add comment. Server responded with code $RESPONSE"
echo "Error details:"
jq '.message' response.json
exit 1
fi

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add newline at end of file.

Add a newline character at the end of the file to comply with YAML best practices and fix the yamllint error.

        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+

Committable suggestion was skipped due to low confidence.

🧰 Tools
🪛 yamllint

[error] 36-36: no new line character at the end of file

(new-line-at-end-of-file)

36 changes: 36 additions & 0 deletions .github/workflows/auto_comment_pr_merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Auto Comment on PR Merge

on:
pull_request:
types: [closed]

permissions:
issues: write
pull-requests: write

jobs:
comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.event.pull_request.merged == true

steps:
- name: Checkout Repository
uses: actions/checkout@v2

Comment on lines +19 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update actions/checkout to latest version.

The current version (v2) is outdated. Update to the latest stable version for better security and features.

- uses: actions/checkout@v2
+ uses: actions/checkout@v4
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Checkout Repository
uses: actions/checkout@v2
- name: Checkout Repository
uses: actions/checkout@v4
🧰 Tools
🪛 actionlint

20-20: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

- 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"
Comment on lines +22 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Simplify comment posting using official GitHub Actions.

While the current curl implementation works, using official GitHub Actions would be more maintainable and less error-prone.

- 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"
+ name: Add Comment to PR
+ uses: actions/github-script@v7
+ with:
+   script: |
+     await github.rest.issues.createComment({
+       owner: context.repo.owner,
+       repo: context.repo.repo,
+       issue_number: context.payload.pull_request.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! 🚀'
+     });

Also, add a newline at the end of the file.

      -d "$COMMENT"
+     -d "$COMMENT"
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 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"
- name: Add Comment to PR
uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.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! 🚀'
});
🧰 Tools
🪛 yamllint

[error] 36-36: no new line character at the end of file

(new-line-at-end-of-file)

37 changes: 37 additions & 0 deletions .github/workflows/auto_comment_pr_raise.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Auto Comment on PR

on:
pull_request_target:
types: [opened]

permissions:
issues: write
pull-requests: write
Comment on lines +3 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consolidate permissions configuration.

The permissions are currently declared both at the workflow and job level. This is redundant and could lead to confusion.

Remove the workflow-level permissions and keep only the job-level declaration:

-permissions:
-  issues: write
-  pull-requests: write

jobs:
  comment:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write

Also applies to: 14-15


jobs:
comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Add Comment to Pull Request
run: |
COMMENT=$(cat <<EOF
{
"body": "Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. 😊"
}
EOF
)
Comment on lines +19 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance the auto-comment message with helpful resources.

Consider making the automated comment more informative by including links to contribution guidelines, code of conduct, or other helpful resources.

Here's a suggested enhancement:

        COMMENT=$(cat <<EOF
        {
-          "body": "Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. 😊"
+          "body": "Thank you for submitting your pull request! 🙌\n\nOur team will review it as soon as possible. In the meantime:\n- 📖 Please review our [contribution guidelines](../../CONTRIBUTING.md)\n- ✅ Ensure all checks are passing\n- 📝 Update the description with any specific details or context\n\nWe appreciate your contribution! 😊"
        }
        EOF
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
COMMENT=$(cat <<EOF
{
"body": "Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. 😊"
}
EOF
)
COMMENT=$(cat <<EOF
{
"body": "Thank you for submitting your pull request! 🙌\n\nOur team will review it as soon as possible. In the meantime:\n- 📖 Please review our [contribution guidelines](../../CONTRIBUTING.md)\n- ✅ Ensure all checks are passing\n- 📝 Update the description with any specific details or context\n\nWe appreciate 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 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add newline at end of file.

Following YAML best practices, ensure there's a newline character at the end of the file.

Add a newline after line 37.

🧰 Tools
🪛 yamllint

[error] 37-37: no new line character at the end of file

(new-line-at-end-of-file)

37 changes: 37 additions & 0 deletions .github/workflows/auto_label_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Auto Comment on PR
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Rename workflow file to match its functionality

The filename auto_label_pr.yml suggests PR labeling, but this workflow actually handles PR commenting. Consider renaming the file to auto_comment_pr.yml for clarity.

Also applies to: 3-5


on:
pull_request_target:
types: [opened]

permissions:
issues: write
pull-requests: write
Comment on lines +7 to +9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consolidate permission declarations

Permissions are redundantly declared at both workflow and job levels. Consider removing the workflow-level permissions and keeping them only at the job level since that's more specific.

-permissions:
-  issues: write
-  pull-requests: write

jobs:
  comment:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write

Also applies to: 14-15


jobs:
comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Add Comment to Pull Request
run: |
COMMENT=$(cat <<EOF
{
"body": "Thank you for submitting your pull request! 🙌 We'll review it as soon as possible. 😊"
}
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
Comment on lines +25 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance error handling in the API call

While the basic error handling is present, it could be more informative for debugging purposes.

        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"
+          echo "Failed to add comment. Status code: $RESPONSE"
+          echo "Response body:"
+          cat response.json
          exit 1
        fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
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. Status code: $RESPONSE"
echo "Response body:"
cat response.json
exit 1
fi

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add newline at end of file

Add a newline character at the end of the file to comply with YAML best practices.

      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
🧰 Tools
🪛 yamllint

[error] 37-37: no new line character at the end of file

(new-line-at-end-of-file)

36 changes: 36 additions & 0 deletions .github/workflows/auto_lable_issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Auto Label Issue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix typo in workflow filename.

The workflow filename contains a typo: auto_lable_issue.yml should be auto_label_issue.yml.

Rename the file to fix the typo:

git mv .github/workflows/auto_lable_issue.yml .github/workflows/auto_label_issue.yml


on:
issues:
types: [opened, reopened, edited]

jobs:
label_issue:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Label Issue
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issue = context.payload.issue;
const issueBody = issue.body ? issue.body.toLowerCase() : '';
const issueTitle = issue.title.toLowerCase();

// Add gssoc label to all issues
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['gssoc-ext','hacktoberfest-accepted','hacktoberfest']
});
Comment on lines +23 to +28
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Revise hardcoded Hacktoberfest labels.

The workflow automatically adds Hacktoberfest-related labels to all issues regardless of timing. This could be misleading as Hacktoberfest is a time-bound event (October).

Consider adding a condition to check if it's October before adding Hacktoberfest labels:

-            await github.rest.issues.addLabels({
-              owner: context.repo.owner,
-              repo: context.repo.repo,
-              issue_number: issue.number,
-              labels: ['gssoc-ext','hacktoberfest-accepted','hacktoberfest']
-            });
+            const today = new Date();
+            const labels = ['gssoc-ext'];
+            
+            // Only add Hacktoberfest labels during October
+            if (today.getMonth() === 9) { // JavaScript months are 0-based
+              labels.push('hacktoberfest-accepted', 'hacktoberfest');
+            }
+            
+            await github.rest.issues.addLabels({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              issue_number: issue.number,
+              labels: labels
+            });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['gssoc-ext','hacktoberfest-accepted','hacktoberfest']
});
const today = new Date();
const labels = ['gssoc-ext'];
// Only add Hacktoberfest labels during October
if (today.getMonth() === 9) { // JavaScript months are 0-based
labels.push('hacktoberfest-accepted', 'hacktoberfest');
}
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: labels
});

const addLabel = async (label) => {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [label]
});
};
Comment on lines +1 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix YAML formatting issues.

There are two formatting issues in the file:

  1. Trailing spaces on line 21
  2. Missing newline at end of file

Apply these fixes:

  1. Remove trailing spaces
  2. Add a newline at the end of the file
🧰 Tools
🪛 yamllint

[error] 21-21: trailing spaces

(trailing-spaces)


[error] 36-36: no new line character at the end of file

(new-line-at-end-of-file)

Comment on lines +29 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove unused helper function.

The addLabel helper function is defined but never used in the workflow.

Either remove the unused function or implement its intended usage:

-            const addLabel = async (label) => {
-              await github.rest.issues.addLabels({
-                owner: context.repo.owner,
-                repo: context.repo.repo,
-                issue_number: issue.number,
-                labels: [label]
-              });
-            };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const addLabel = async (label) => {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [label]
});
};
🧰 Tools
🪛 yamllint

[error] 36-36: no new line character at the end of file

(new-line-at-end-of-file)

Comment on lines +17 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add error handling for GitHub API operations.

The script lacks error handling for the label operations, which could fail silently if there are API issues.

Add try-catch blocks to handle potential errors:

           script: |
+            try {
               const issue = context.payload.issue;
               const issueBody = issue.body ? issue.body.toLowerCase() : '';
               const issueTitle = issue.title.toLowerCase();
               
               // Add gssoc label to all issues
               await github.rest.issues.addLabels({
                 owner: context.repo.owner,
                 repo: context.repo.repo,
                 issue_number: issue.number,
                 labels: ['gssoc-ext','hacktoberfest-accepted','hacktoberfest']
               });
+            } catch (error) {
+              console.error('Failed to add labels:', error);
+              core.setFailed(error.message);
+            }

Committable suggestion was skipped due to low confidence.

🧰 Tools
🪛 yamllint

[error] 21-21: trailing spaces

(trailing-spaces)


[error] 36-36: no new line character at the end of file

(new-line-at-end-of-file)

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 Issues on PR Merge

on:
pull_request:
types: [closed]

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

steps:
- name: Checkout repository
uses: actions/checkout@v2
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update checkout action to latest version

The current version of actions/checkout is outdated and may have security vulnerabilities.

-      uses: actions/checkout@v2
+      uses: actions/checkout@v4
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v4
🧰 Tools
🪛 actionlint

13-13: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


- 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add newline at end of file

POSIX requires files to end with a newline character.

Add a newline at the end of the file.

🧰 Tools
🪛 yamllint

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)

Comment on lines +1 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Overlapping workflows detected - consolidation needed

The repository has three workflows triggered on similar events with overlapping functionality:

  • close_issue_on_pr_merge.yml: Closes linked issues when PR is merged
  • comment_iss-close.yml: Comments on issues when they are closed
  • auto_comment_pr_merge.yml: Comments on PRs when they are merged

This creates potential race conditions and redundant operations. Recommendations:

  • Consolidate PR merge handling into a single workflow
  • Ensure clear separation between issue-close and PR-merge triggers
  • Consider using GitHub Actions' built-in github-script action instead of raw curl commands for better maintainability
🔗 Analysis chain

Verify workflow uniqueness

Let's ensure there are no duplicate or conflicting workflows for closing issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other workflows that might handle issue closing
echo "Searching for similar workflows..."
rg -l --type yaml 'types.*closed|state.*closed' .github/workflows/

Length of output: 277


Script:

#!/bin/bash
# Let's examine the content of these files to understand their functionality
echo "=== comment_iss-close.yml ==="
cat .github/workflows/comment_iss-close.yml
echo -e "\n=== auto_comment_pr_merge.yml ==="
cat .github/workflows/auto_comment_pr_merge.yml

Length of output: 2173

🧰 Tools
🪛 actionlint

13-13: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


17-17: shellcheck reported issue in this script: SC2086:info:7:69: Double quote to prevent globbing and word splitting

(shellcheck)


17-17: shellcheck reported issue in this script: SC2086:info:11:69: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)

Comment on lines +15 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve script robustness and error handling

The current implementation has several potential issues:

  1. Missing error handling for API calls
  2. Unquoted variables could cause issues with word splitting
  3. No validation of extracted issue numbers
  4. Repeated API URL construction

Here's an improved version:

     - name: Close linked issues
       if: github.event.pull_request.merged == true
       run: |
+        API_URL="https://api.github.com/repos/${{ github.repository }}"
+        AUTH_HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
+        ACCEPT_HEADER="Accept: application/vnd.github.v3+json"
+
         ISSUES=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | grep -Eo '#[0-9]+' | tr -d '#')
-        for ISSUE in $ISSUES
+        if [ -z "$ISSUES" ]; then
+          echo "No issues found in PR body"
+          exit 0
+        fi
+
+        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"}'
+          if ! [[ "$ISSUE" =~ ^[0-9]+$ ]]; then
+            echo "Invalid issue number: $ISSUE"
+            continue
+          fi
+          
+          echo "Processing issue #$ISSUE"
+          
+          # Add comment
+          if ! curl -s -f -X POST \
+               -H "$AUTH_HEADER" \
+               -H "$ACCEPT_HEADER" \
+               "$API_URL/issues/$ISSUE/comments" \
+               -d "{\"body\":\"Closed by PR #${{ github.event.pull_request.number }}\"}"
+          then
+            echo "Failed to add comment to issue #$ISSUE"
+            continue
+          fi
+          
+          # Close issue
+          if ! curl -s -f -X PATCH \
+               -H "$AUTH_HEADER" \
+               -H "$ACCEPT_HEADER" \
+               "$API_URL/issues/$ISSUE" \
+               -d '{"state":"closed"}'
+          then
+            echo "Failed to close issue #$ISSUE"
+            continue
+          fi
+          
+          echo "Successfully closed issue #$ISSUE"
         done

The improvements include:

  • Error handling for API calls using -f flag and checking return status
  • Input validation for issue numbers
  • DRY: Common values stored in variables
  • Better progress logging
  • Silent curl output with -s flag
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 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
- name: Close linked issues
if: github.event.pull_request.merged == true
run: |
API_URL="https://api.github.com/repos/${{ github.repository }}"
AUTH_HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
ACCEPT_HEADER="Accept: application/vnd.github.v3+json"
ISSUES=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | grep -Eo '#[0-9]+' | tr -d '#')
if [ -z "$ISSUES" ]; then
echo "No issues found in PR body"
exit 0
fi
for ISSUE in $ISSUES
do
if ! [[ "$ISSUE" =~ ^[0-9]+$ ]]; then
echo "Invalid issue number: $ISSUE"
continue
fi
echo "Processing issue #$ISSUE"
# Add comment
if ! curl -s -f -X POST \
-H "$AUTH_HEADER" \
-H "$ACCEPT_HEADER" \
"$API_URL/issues/$ISSUE/comments" \
-d "{\"body\":\"Closed by PR #${{ github.event.pull_request.number }}\"}"
then
echo "Failed to add comment to issue #$ISSUE"
continue
fi
# Close issue
if ! curl -s -f -X PATCH \
-H "$AUTH_HEADER" \
-H "$ACCEPT_HEADER" \
"$API_URL/issues/$ISSUE" \
-d '{"state":"closed"}'
then
echo "Failed to close issue #$ISSUE"
continue
fi
echo "Successfully closed issue #$ISSUE"
done
🧰 Tools
🪛 actionlint

17-17: shellcheck reported issue in this script: SC2086:info:7:69: Double quote to prevent globbing and word splitting

(shellcheck)


17-17: shellcheck reported issue in this script: SC2086:info:11:69: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint

[error] 30-30: no new line character at the end of file

(new-line-at-end-of-file)

29 changes: 29 additions & 0 deletions .github/workflows/comment_iss-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Comment on Issue Close

on:
issues:
types: [closed]

jobs:
greet-on-close:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Greet User
uses: actions/github-script@v5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update github-script action version for security.

The current version (v5) is outdated. Update to the latest version for security improvements and bug fixes.

Apply this diff:

-        uses: actions/github-script@v5
+        uses: actions/github-script@v7
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
uses: actions/github-script@v5
uses: actions/github-script@v7
🧰 Tools
🪛 actionlint

14-14: the runner of "actions/github-script@v5" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

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
});
Comment on lines +24 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and enhance the comment message.

The current implementation could be more robust with:

  1. Error handling for the API call
  2. A more informative closing message

Consider this improved implementation:

             github.rest.issues.createComment({
               owner: context.repo.owner,
               repo: context.repo.repo,
               issue_number: issueNumber,
-              body: greetingMessage
-            });
+              body: `Hello @${issueCreator}! 👋
+
+Issue #${issueNumber} has been closed. Thank you for your contribution! 🙏
+
+If you believe this was closed by mistake, please feel free to comment or reopen.`
+            }).catch(error => {
+              core.setFailed(`Failed to create comment: ${error.message}`);
+            });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
});
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: `Hello @${issueCreator}! 👋
Issue #${issueNumber} has been closed. Thank you for your contribution! 🙏
If you believe this was closed by mistake, please feel free to comment or reopen.`
}).catch(error => {
core.setFailed(`Failed to create comment: ${error.message}`);
});
🧰 Tools
🪛 yamllint

[error] 29-29: no new line character at the end of file

(new-line-at-end-of-file)

Loading