Skip to content

Add support for triggering workflows in git submodules#597

Open
bpmiranda3099 wants to merge 2 commits into
github:mainfrom
bpmiranda3099:fix/support-submodule-workflows
Open

Add support for triggering workflows in git submodules#597
bpmiranda3099 wants to merge 2 commits into
github:mainfrom
bpmiranda3099:fix/support-submodule-workflows

Conversation

@bpmiranda3099
Copy link
Copy Markdown

Description

This PR fixes #596 when triggering GitHub Actions workflows located in git submodules. Previously, the extension would fail with a 404 error when attempting to dispatch workflows in submodules, as it would incorrectly route the dispatch to the parent repository instead of the submodule's separate GitHub repository.

Example Structure

monorepo/                              (Parent repo: github.com/owner/monorepo)
└── submodule/                         (Submodule: github.com/owner/submodule)
    └── .github/workflows/
        └── deploy.yml                 ← Should dispatch to submodule repo

When triggering submodule/.github/workflows/deploy.yml, the extension should dispatch to the submodule repository, not the parent monorepo repository.

Changes

Submodule Detection and Repository Routing

  • Added src/git/submoduleHelper.ts with getRepositoryRootForDocumentUri() helper function
  • Detects when a workflow file is located in a git submodule by iterating through all git repositories
  • Queries git directly to identify the correct GitHub repository for each submodule
  • Routes workflow dispatch to the correct repository regardless of how many submodules exist

Updated Imports and Exports

  • Exported getGitExtension() in src/git/repository.ts to enable submodule detection
  • Updated src/commands/triggerWorkflowRun.ts to import and use submodule helper

Improved Path Calculation

  • Fixed relative workflow path calculation to be relative to the correct repository (submodule or parent)
  • Ensures workflow dispatch API call uses the correct path format

Debug Configuration

  • During development, the extension debug session encountered "task has not exited and doesn't have a problemMatcher defined" error
  • Fixed webpack watch problemMatcher in .vscode/tasks.json for proper debug task completion
  • Changed problemMatcher from invalid $ts-webpack-watch to correct $tsc-watch value
  • This ensures the debug session properly detects when webpack build completes and the extension is ready to load

Related Issues

Fixes #596

Testing

The fix ensures that:

  • Workflows in submodules with separate GitHub repositories can be triggered successfully
  • The correct repository is used for dispatch (verified via API call routing)
  • Fallback to workspace folder works for workflows not in submodules
  • Solution scales to any number of submodules

Copilot AI review requested due to automatic review settings May 25, 2026 13:28
@bpmiranda3099 bpmiranda3099 requested a review from a team as a code owner May 25, 2026 13:28
Copy link
Copy Markdown

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds submodule-aware repository detection so triggering a workflow can resolve the correct repo root (or submodule root) instead of relying solely on the workspace folder.

Changes:

  • Introduces submoduleHelper.ts to find the repository/submodule root for a document URI.
  • Exports getGitExtension for reuse and updates workflow trigger logic to use repository root resolution.
  • Updates VS Code task problem matcher configuration.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
src/git/submoduleHelper.ts New helper to resolve repo/submodule root for a document path; logs submodule remote.
src/git/repository.ts Exports getGitExtension() so other modules can query VS Code Git repositories.
src/commands/triggerWorkflowRun.ts Uses repo root resolution and computes workflow path relative to that root.
.vscode/tasks.json Switches problem matcher from webpack watch to tsc watch.

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

Comment thread src/git/submoduleHelper.ts Outdated
Comment on lines +9 to +13
const dir = path.dirname(documentPath);
const cp = await import("child_process");
const util = await import("util");
const execPromise = util.promisify(cp.exec);
const {stdout} = await execPromise("git config --get remote.origin.url", {cwd: dir});
Comment thread src/git/submoduleHelper.ts Outdated
for (const repository of git.repositories) {
const repoPath = repository.rootUri.fsPath;

if (documentPath.startsWith(repoPath)) {
Comment thread src/git/submoduleHelper.ts Outdated
Comment on lines +37 to +38
const submodulePath = path.join(repoPath, submodule.path);
if (documentPath.startsWith(submodulePath)) {
Comment thread src/commands/triggerWorkflowRun.ts Outdated
Comment on lines +94 to +96
const workflowPath = workflowUri.fsPath;
const repositoryPath = repositoryUri.fsPath;
const relativeWorkflowPath = workflowPath.substring(repositoryPath.length + 1);
const workspaceFolder = vscode.workspace.getWorkspaceFolder(workflowUri);
if (!workspaceFolder) {
return;
let repositoryUri = await getRepositoryRootForDocumentUri(workflowUri);
Comment thread src/commands/triggerWorkflowRun.ts Outdated
Comment on lines 42 to 43
const gitHubRepoContext = await getGitHubContextForWorkspaceUri(repositoryUri);
if (!gitHubRepoContext) {
Comment thread src/git/submoduleHelper.ts Outdated
const repoPath = repository.rootUri.fsPath;

if (documentPath.startsWith(repoPath)) {
await repository.status();
Comment thread src/git/submoduleHelper.ts Outdated
const cp = await import("child_process");
const util = await import("util");
const execPromise = util.promisify(cp.exec);
const {stdout} = await execPromise("git config --get remote.origin.url", {cwd: dir});
@bpmiranda3099
Copy link
Copy Markdown
Author

Quick follow-up to clean up some of the code review feedback from Copilot. Nothing changes functionally, just made some stuff more robust and cross-platform friendly.

Changes

  • Fix git remote lookup to handle folders correctly, use safer command execution
  • Fix path checking to avoid matching wrong folders on Windows
  • Fix workflow path calculation to work properly on all systems
  • Add way to find GitHub repo info from git remote for submodules

Testing

  • Built and tested, workflows still work
  • No TypeScript errors

Let me know if anything needs further adjustment.

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.

Workflow dispatch fails for workflows in git submodules

2 participants