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

Conversation

shubhagarwal1
Copy link
Contributor

@shubhagarwal1 shubhagarwal1 commented Oct 25, 2024

fix: #396
Auto Comment on Issue
Auto Comment on PR
Auto Comment on PR Merge
Auto Label Issues
Auto Label PRs
Close Issues on PR Merge
Comment on Issue Close

Summary by CodeRabbit

Release Notes

  • New Features
    • Introduced automated commenting workflows for new issues and pull requests to enhance user engagement.
    • Automated labeling of issues upon creation, improving categorization and management.
    • Implemented a workflow to close linked issues when a pull request is merged, streamlining issue management.
    • Added automated comments on closed issues to acknowledge contributors.

These enhancements aim to improve user interaction and streamline repository management processes.

Copy link
Contributor

coderabbitai bot commented Oct 25, 2024

Walkthrough

This pull request introduces multiple GitHub Actions workflows to automate commenting and labeling on issues and pull requests. The new workflows include automatic comments for newly opened issues, pull requests, and merged pull requests, as well as automated labeling for issues and pull requests. Additionally, there are workflows for closing linked issues upon pull request merges and commenting on closed issues. Each workflow is designed to enhance user engagement and streamline issue management within the repository.

Changes

File Path Change Summary
.github/workflows/auto_comment_on_issue.yml New workflow to automatically comment on newly opened issues.
.github/workflows/auto_comment_pr_merge.yml New workflow to comment on issues linked to merged pull requests.
.github/workflows/auto_comment_pr_raise.yml New workflow to comment on newly opened pull requests.
.github/workflows/auto_label_pr.yml New workflow to comment on newly opened pull requests (duplicate name, same functionality).
.github/workflows/auto_label_issue.yml New workflow to automatically label issues upon creation, reopening, or editing.
.github/workflows/close_issue_on_pr_merge.yml New workflow to close issues linked in merged pull requests.
.github/workflows/comment_iss-close.yml New workflow to comment on issues when they are closed.

Assessment against linked issues

Objective Addressed Explanation
Auto Comment on Issue
Auto Comment on PR
Auto Comment on PR Merge
Auto Label Issue
Close Issues on PR Merge
Comment on Issue Close

Poem

🐰 In the garden of code, changes bloom bright,
With comments and labels, all feels just right.
Issues and PRs, they dance with delight,
Closing and greeting, all done in a flight!
So hop on, dear coder, let’s celebrate cheer,
For workflows are here, bringing joy near! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Oct 25, 2024

Deploy Preview for manageyourwaste failed. Why did it fail? →

Name Link
🔨 Latest commit 6fffff5
🔍 Latest deploy log https://app.netlify.com/sites/manageyourwaste/deploys/671c0d1cb02ccb000868eac6

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 23

🧹 Outside diff range and nitpick comments (3)
.github/workflows/comment_iss-close.yml (1)

29-29: Add newline at end of file.

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

Add a blank line after line 29.

🧰 Tools
🪛 yamllint

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

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

.github/workflows/auto_label_pr.yml (1)

1-37: Add missing PR labeling functionality

While this workflow handles PR commenting, it doesn't implement the PR labeling functionality mentioned in the PR objectives. Consider either:

  1. Adding labeling logic to this workflow, or
  2. Creating a separate workflow for PR labeling

Would you like me to help implement the PR labeling functionality? I can provide a sample implementation that:

  • Adds labels based on PR title/description keywords
  • Labels PRs based on changed files
  • Applies size labels based on the number of changes
🧰 Tools
🪛 yamllint

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

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

.github/workflows/auto_comment_pr_merge.yml (1)

11-17: Remove redundant permissions configuration.

The job-level permissions for pull-requests are redundant since they're already defined at the workflow level.

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

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 74559d3 and 6fffff5.

📒 Files selected for processing (7)
  • .github/workflows/auto_comment_on_issue.yml (1 hunks)
  • .github/workflows/auto_comment_pr_merge.yml (1 hunks)
  • .github/workflows/auto_comment_pr_raise.yml (1 hunks)
  • .github/workflows/auto_label_pr.yml (1 hunks)
  • .github/workflows/auto_lable_issue.yml (1 hunks)
  • .github/workflows/close_issue_on_pr_merge.yml (1 hunks)
  • .github/workflows/comment_iss-close.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
.github/workflows/auto_comment_on_issue.yml

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

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

.github/workflows/auto_comment_pr_merge.yml

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

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

.github/workflows/auto_comment_pr_raise.yml

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

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

.github/workflows/auto_label_pr.yml

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

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

.github/workflows/auto_lable_issue.yml

[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)

.github/workflows/close_issue_on_pr_merge.yml

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

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

.github/workflows/comment_iss-close.yml

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

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

🪛 actionlint
.github/workflows/auto_comment_pr_merge.yml

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)

.github/workflows/close_issue_on_pr_merge.yml

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)

.github/workflows/comment_iss-close.yml

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)

🔇 Additional comments (8)
.github/workflows/comment_iss-close.yml (1)

1-11: LGTM! Well-configured workflow trigger and permissions.

The workflow follows security best practices by:

  • Using specific event triggers
  • Explicitly declaring minimal required permissions
.github/workflows/auto_comment_on_issue.yml (1)

10-15: LGTM!

The job configuration is well-structured and uses appropriate settings.

.github/workflows/auto_comment_pr_raise.yml (1)

25-35: 🛠️ Refactor suggestion

Consider using GitHub CLI for simpler implementation.

The current implementation using curl is functional but could be simplified using the GitHub CLI (gh). Additionally, the error handling could be improved to handle rate limiting and provide more detailed error messages.

Here's a suggested improvement using GitHub CLI:

-        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
+        if ! gh pr comment ${{ github.event.pull_request.number }} --body "$(echo "$COMMENT" | jq -r .body)"; then
+          echo "::error::Failed to add comment to PR"
+          exit 1
+        fi

This change:

  • Uses gh pr comment for simpler API interaction
  • Removes the need for manual JSON handling
  • Uses GitHub Actions error logging

Let's verify if GitHub CLI is available in the workflow environment:

.github/workflows/auto_label_pr.yml (1)

4-5: Review security implications of pull_request_target

The pull_request_target trigger runs workflows with repository token permissions in the context of the base repository. While this is necessary for commenting on PRs from forks, ensure that no untrusted code from the PR is checked out or executed in this workflow.

✅ Verification successful

No security concerns with current pull_request_target usage

The workflows using pull_request_target are secure because:

  • None of them use actions/checkout to access PR code
  • They only perform safe operations:
    • auto_label_pr.yml and auto_comment_pr_raise.yml just post welcome comments using GitHub API
    • greetings.yaml uses the official actions/first-interaction action to post welcome messages
  • All workflows have properly restricted permissions using the permissions block
  • They only trigger on opened event type (except greetings which is safe by design)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if any other workflows in the repository use pull_request_target and potentially checkout code
rg -l "pull_request_target" .github/workflows/ | while read -r file; do
  echo "Checking $file for potential security issues..."
  rg "actions/checkout" "$file" -C 5
done

Length of output: 805


Script:

#!/bin/bash
# Let's examine the content of these workflows to understand their usage of pull_request_target
echo "=== Content of auto_label_pr.yml ==="
cat .github/workflows/auto_label_pr.yml

echo -e "\n=== Content of auto_comment_pr_raise.yml ==="
cat .github/workflows/auto_comment_pr_raise.yml

echo -e "\n=== Content of greetings.yaml ==="
cat .github/workflows/greetings.yaml

Length of output: 3166

.github/workflows/close_issue_on_pr_merge.yml (1)

3-6: 🛠️ Refactor suggestion

Optimize workflow trigger configuration

The workflow currently runs on all PR closures but only executes when PRs are merged. Consider optimizing the trigger to only run on merged PRs:

 on:
   pull_request:
-    types: [closed]
+    types: [closed, merged]

Likely invalid or redundant comment.

.github/workflows/auto_comment_pr_merge.yml (1)

1-10: LGTM! Well-configured workflow trigger and permissions.

The workflow is properly configured to trigger on PR closures with appropriate scoped permissions for issues and pull requests.

.github/workflows/auto_lable_issue.yml (2)

3-6: LGTM: Workflow triggers are appropriate.

The workflow triggers on issue events (opened, reopened, edited) are well-defined and appropriate for the labeling use case.


10-11: LGTM: Minimal permissions following principle of least privilege.

The workflow correctly specifies minimal issues: write permissions needed for labeling operations.

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)

Comment on lines +24 to +29
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
});
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)

Comment on lines +7 to +9
permissions:
issues: write

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

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)

Comment on lines +16 to +34
- 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
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

@@ -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

Comment on lines +1 to +36
name: Auto Label Issue

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']
});
const addLabel = async (label) => {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [label]
});
};
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
const addLabel = async (label) => {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [label]
});
};
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 +23 to +28
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['gssoc-ext','hacktoberfest-accepted','hacktoberfest']
});
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
});

Comment on lines +17 to +36
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']
});
const addLabel = async (label) => {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [label]
});
};
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)

@GarimaSingh0109 GarimaSingh0109 merged commit 1c9d683 into GarimaSingh0109:main Oct 26, 2024
2 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CICD Github Workflow
2 participants