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

More work on actions #622

Merged
merged 6 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 9 additions & 4 deletions .github/actions/help-command/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ inputs:
github-token:
description: 'GitHub token for posting comments'
required: true
issue-number:
description: 'PR/Issue number to post the comment to (optional, defaults to event context)'
required: false

runs:
using: "composite"
steps:
- name: Show Available Commands
uses: actions/github-script
uses: actions/github-script@v7
with:
github-token: ${{ inputs.github-token }}
script: |
Expand Down Expand Up @@ -80,12 +83,14 @@ runs:
'3. Open an issue in this repository',
].join('\n');
const context = github.context;
if (context.eventName === 'issue_comment') {
const issueNumber = inputs['issue-number'] ||
(context.eventName === 'issue_comment' ? context.payload.issue.number : null);
if (issueNumber) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
issue_number: issueNumber,
Comment on lines +86 to +93
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling and fix trailing space.

  1. Fix the trailing space on line 86.
  2. Consider adding explicit error handling when issueNumber is null in non-comment contexts.
-          const issueNumber = inputs['issue-number'] || 
+          const issueNumber = inputs['issue-number'] ||
           (context.eventName === 'issue_comment' ? context.payload.issue.number : null);

-          if (issueNumber) {
+          if (!issueNumber) {
+            core.warning('No issue number provided or found in context. Falling back to console output.');
+            console.log(helpText);
+          } else {
             await github.rest.issues.createComment({
               owner: context.repo.owner,
               repo: context.repo.repo,
               issue_number: issueNumber,
               body: helpText
             });
-          } else {
-            console.log(helpText);
           }
📝 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 issueNumber = inputs['issue-number'] ||
(context.eventName === 'issue_comment' ? context.payload.issue.number : null);
if (issueNumber) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number,
issue_number: issueNumber,
const issueNumber = inputs['issue-number'] ||
(context.eventName === 'issue_comment' ? context.payload.issue.number : null);
if (!issueNumber) {
core.warning('No issue number provided or found in context. Falling back to console output.');
console.log(helpText);
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: helpText
});
}
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 86-86: trailing spaces

(trailing-spaces)

body: helpText
});
} else {
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/help-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
issue-number:
description: 'PR/Issue number to post the help comment to'
required: true
type: number

permissions:
issues: write
Expand All @@ -26,6 +31,7 @@ jobs:
uses: actions/checkout

- name: Show Help Information
uses: ./.github/actions/help-command
uses: shakacode/shared-actions/help-command@justin808-more-work-on-review-apps-2
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using feature branch references in production workflows.

The action reference @justin808-more-work-on-review-apps-2 points to a feature branch, which could lead to instability. Consider using a stable version tag or commit SHA.

-        uses: shakacode/shared-actions/help-command@justin808-more-work-on-review-apps-2
+        uses: shakacode/shared-actions/help-command@v1

Also applies to: 37-37

with:
github-token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.inputs.issue-number }}
Loading