-
Notifications
You must be signed in to change notification settings - Fork 163
Support a relative path for the options to "link to source" for the --checkout-path CLI option #490 #929
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
Anthony-Eid
wants to merge
4
commits into
swiftlang:main
Choose a base branch
from
Anthony-Eid:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Support a relative path for the options to "link to source" for the --checkout-path CLI option #490 #929
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
be84a97
Add support to relative paths SourceRepository checkoutPath argument
Anthony-Eid f08135e
Update docc convert unit test to work with relative --checkout-path
Anthony-Eid 923e328
Update and add test cases to ConvertSubCommandSourceRepositoryTests
Anthony-Eid 153cd70
Update docs to reflect that --checkout-path can be a relative path now
Anthony-Eid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Add support to relative paths SourceRepository checkoutPath argument
- Loading branch information
commit be84a9798dc0c0f32687dcbc255f54f413495999
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,33 +9,42 @@ | |
| */ | ||
|
|
||
| import Foundation | ||
| import ArgumentParser | ||
Anthony-Eid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// A remote repository that hosts source code. | ||
| public struct SourceRepository { | ||
| /// The path at which the repository is cloned locally. | ||
| public var checkoutPath: String | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this was defined as a |
||
|
|
||
| /// The base URL where the service hosts the repository's contents. | ||
| public var sourceServiceBaseURL: URL | ||
|
|
||
| /// A function that formats a line number to be included in a URL. | ||
| public var formatLineNumber: (Int) -> String | ||
|
|
||
| /// Creates a source code repository. | ||
| /// - Parameters: | ||
| /// - checkoutPath: The path at which the repository is checked out locally and from which its symbol graphs were generated. | ||
| /// - sourceServiceBaseURL: The base URL where the service hosts the repository's contents. | ||
| /// - formatLineNumber: A function that formats a line number to be included in a URL. | ||
| public init( | ||
| public init ( | ||
| checkoutPath: String, | ||
| sourceServiceBaseURL: URL, | ||
| formatLineNumber: @escaping (Int) -> String | ||
| ) { | ||
| self.checkoutPath = checkoutPath | ||
|
|
||
|
|
||
| // guard FileManager.default.directoryExists(atPath: checkoutPath) else { | ||
| // throw ValidationError("User provided checkout-path argument {checkoutPath} is invalid.") | ||
| // } | ||
| let absoluteCheckoutPath = URL(fileURLWithPath: checkoutPath).absoluteString | ||
| let startIndex = absoluteCheckoutPath.index(absoluteCheckoutPath.startIndex, offsetBy: 7) | ||
|
|
||
| self.checkoutPath = String(absoluteCheckoutPath[startIndex...]) | ||
| self.sourceServiceBaseURL = sourceServiceBaseURL | ||
| self.formatLineNumber = formatLineNumber | ||
| } | ||
|
|
||
| /// Formats a local source file URL to a URL hosted by the remote source code service. | ||
| /// - Parameters: | ||
| /// - sourceFileURL: The location of the source file on disk. | ||
|
|
@@ -45,7 +54,7 @@ public struct SourceRepository { | |
| guard sourceFileURL.path.hasPrefix(checkoutPath) else { | ||
| return nil | ||
| } | ||
|
|
||
| let path = sourceFileURL.path.dropFirst(checkoutPath.count).removingLeadingSlash | ||
| return sourceServiceBaseURL | ||
| .appendingPathComponent(path) | ||
|
|
@@ -65,7 +74,7 @@ public extension SourceRepository { | |
| formatLineNumber: { line in "L\(line)" } | ||
| ) | ||
| } | ||
|
|
||
| /// Creates a source repository hosted by the GitLab service. | ||
| /// - Parameters: | ||
| /// - checkoutPath: The path of the local checkout. | ||
|
|
@@ -77,7 +86,7 @@ public extension SourceRepository { | |
| formatLineNumber: { line in "L\(line)" } | ||
| ) | ||
| } | ||
|
|
||
| /// Creates a source repository hosted by the BitBucket service. | ||
| /// - Parameters: | ||
| /// - checkoutPath: The path of the local checkout. | ||
|
|
@@ -89,7 +98,7 @@ public extension SourceRepository { | |
| formatLineNumber: { line in "lines-\(line)" } | ||
| ) | ||
| } | ||
|
|
||
| /// Creates a source repository hosted by the device's filesystem. | ||
| /// | ||
| /// Use this source repository to format `doc-source-file://` links to files on the | ||
|
|
@@ -98,7 +107,7 @@ public extension SourceRepository { | |
| /// This source repository uses a custom scheme to offer more control local source file navigation. | ||
| static func localFilesystem() -> SourceRepository { | ||
| SourceRepository( | ||
| checkoutPath: "", | ||
| checkoutPath: "/", | ||
Anthony-Eid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // 2 slashes to specify an empty authority/host component and 1 slash to specify a base path at the root. | ||
| sourceServiceBaseURL: URL(string: "doc-source-file:///")!, | ||
| formatLineNumber: { line in "L\(line)" } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a significant amount of whitespace-only changes in all these files which adds noise to the PR. Please remove all those.