Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 7, 2025

The add command hardcoded workflows to .github/workflows/. This prevents organizing workflows into subdirectories for better structure.

Changes

CLI Interface:

  • Added --dir (-d) flag to specify target subdirectory
  • Subdirectory names automatically prefixed with .github/workflows/
  • Full paths starting with .github/workflows used as-is
  • Absolute paths rejected with validation error

Implementation:

  • Threaded workflowDir parameter through: AddWorkflows()addWorkflowsNormal()addWorkflowsWithPR()addWorkflowWithTracking()
  • Path construction logic handles three cases:
    • Empty: .github/workflows/ (default)
    • Name: .github/workflows/{name}/
    • Full: .github/workflows/{path}/

Example:

# Default behavior unchanged
gh aw add githubnext/agentics/ci-doctor

# Add to subfolder
gh aw add githubnext/agentics/ci-doctor --dir shared
# → .github/workflows/shared/ci-doctor.md

# Nested subfolder
gh aw add githubnext/agentics/ci-doctor --dir team/backend
# → .github/workflows/team/backend/ci-doctor.md

All existing tests updated to pass new parameter. Backward compatible.

Original prompt

Add support for specifying a subfolder in the "add" command where the workflows will be added.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits November 7, 2025 20:03
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for specifying a subfolder in add command Add --dir flag to specify subfolder for workflow installation Nov 7, 2025
Copilot AI requested a review from pelikhan November 7, 2025 20:19
Copilot finished work on behalf of pelikhan November 7, 2025 20:19
@pelikhan pelikhan marked this pull request as ready for review November 7, 2025 21:01
Copilot AI review requested due to automatic review settings November 7, 2025 21:01
@pelikhan pelikhan merged commit 0e6c1f3 into main Nov 7, 2025
87 of 91 checks passed
@pelikhan pelikhan deleted the copilot/add-subfolder-support-to-add-command branch November 7, 2025 21:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for specifying a custom subdirectory under .github/workflows/ when adding workflows via the --dir flag. Users can now organize workflows into subdirectories like .github/workflows/shared/ or .github/workflows/custom/.

Key changes:

  • Added --dir flag to the add command to specify a custom workflow subdirectory
  • Updated all function signatures in the workflow addition flow to accept and propagate the workflowDir parameter
  • Added path validation to prevent absolute paths and path traversal attacks
  • Updated tests to pass the new empty string parameter for backward compatibility

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/cli/add_command.go Core implementation: adds --dir flag, validates path input, and routes workflows to custom subdirectories
pkg/cli/trial_command.go Updates AddWorkflows call to include empty workflowDir parameter
pkg/cli/add_wildcard_test.go Updates addWorkflowWithTracking test calls with empty workflowDir parameter
pkg/cli/add_gitattributes_test.go Updates addWorkflowsNormal test calls with empty workflowDir parameter
pkg/cli/add_current_repo_test.go Updates AddWorkflows test calls with empty workflowDir parameter
.github/workflows/super-linter-report.lock.yml Removes fetch-depth: 0 from checkout action (unrelated change)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +572 to +579
workflowDir = filepath.Clean(workflowDir)
// Ensure the path is under .github/workflows
if !strings.HasPrefix(workflowDir, ".github/workflows") {
// If user provided a subdirectory name, prepend .github/workflows/
githubWorkflowsDir = filepath.Join(gitRoot, ".github/workflows", workflowDir)
} else {
githubWorkflowsDir = filepath.Join(gitRoot, workflowDir)
}
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

Path traversal vulnerability: filepath.Clean does not prevent path traversal attacks. An attacker could provide --dir ../../../etc which after cleaning becomes ../../../etc, bypassing the .github/workflows prefix check and writing workflows outside the repository. After filepath.Clean, you must validate that the cleaned path does not start with .. or contain .. segments to prevent directory traversal. Add validation like: if strings.Contains(workflowDir, \"..\") { return fmt.Errorf(\"workflow directory cannot contain '..' path elements\") }

Copilot uses AI. Check for mistakes.
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
with:
persist-credentials: false
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

Unrelated change: The removal of fetch-depth: 0 from the checkout action appears unrelated to the PR's purpose of adding the --dir flag. This change should either be explained in the PR description or moved to a separate commit/PR.

Suggested change
persist-credentials: false
persist-credentials: false
fetch-depth: 0

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants