Skip to content

feat: add support for repository-path in forge doc #10879

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nitininhouse
Copy link

@nitininhouse nitininhouse commented Jun 29, 2025

Motivation

When working with monorepos or projects where source code is located in specific directories, documentation links should point directly to the relevant code location rather than the repository root. This improves developer experience by providing direct navigation to the actual source files.

Solution

Added an optional path configuration field to the [doc] section that allows specifying the exact repository path for documentation links. This field accepts the full path including branch information, providing flexibility for repositories with different default branches.

Configuration

[doc]
repository = "https://github.com/company/monorepo"
path = "tree/main/packages/contracts"

Result

Documentation links now point to:

https://github.com/company/monorepo/tree/main/packages/contracts

Key Features

  • Supports any branch name (main, master, develop, etc.)
  • Works with any directory structure
  • Maintains full backward compatibility when not specified
  • Provides precise control over documentation navigation links

Usage Examples

# For main branch subdirectory
path = "tree/main/src/contracts"

# For master branch subdirectory
path = "tree/master/packages/core"

# For specific tag or branch
path = "tree/v1.0.0/contracts"

This change enables accurate source code navigation from documentation, particularly valuable in monorepo setups and projects with non-standard repository structures.


Fixes #10836

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

Thank you, left a comment. Also please fix fmt and undo Cargo.lock updates, don't think they are needed?

Some(dir) => {
// If directory is specified, append it to the repository URL
let repo_clean = repo.trim_end_matches('/');
format!("{}/tree/main/{}", repo_clean, dir.trim_start_matches('/'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this won't work for repos with default branch master (or other), maybe directory option should be renamed to path or repo_path) and should contain exact value (like directory = "main/packages/contracts" or directory = "tree/main/packages/contracts"

Copy link
Author

Choose a reason for hiding this comment

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

Should I add a separate configuration option for the branch, or simply rename directory to path and let users specify the full path, including the branch?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest renaming and make description clear on what's expected. Thank you

Copy link
Author

Choose a reason for hiding this comment

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

I have made the change as you said

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, thank you, please add description for the new option.

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

smol nit

@@ -20,6 +20,8 @@ pub struct DocConfig {
/// The repository url.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub repository: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
Copy link
Member

Choose a reason for hiding this comment

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

can we add a oneliner doc here

Copy link
Author

Choose a reason for hiding this comment

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

yeah!

Comment on lines +352 to +363
// Create the full repository URL
let git_repo_url = match &self.config.path {
Some(path) => {
// If path is specified, append it to the repository URL
let repo_clean = repo.trim_end_matches('/');
format!("{}/{}", repo_clean, dir.trim_start_matches('/'))
}
None => {
// No path specified, use repository URL as-is
repo.clone()
}
};
Copy link
Member

Choose a reason for hiding this comment

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

this makes sense,

I'd prefer a if let some else style here instead of the match

Copy link
Author

Choose a reason for hiding this comment

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

Thanks mattsse! going to do it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

feat(forge doc): support repository field to link to a directory in a directory structure rather than a URL
3 participants