forked from moul/depviz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: merge multipmuri as a depviz/pkg (moul#664)
- Loading branch information
Showing
25 changed files
with
2,383 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package multipmuri | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
func DecodeString(input string) (Entity, error) { | ||
return NewUnknownEntity().RelDecodeString(input) | ||
} | ||
|
||
type unknownEntity struct{} | ||
|
||
func NewUnknownEntity() Entity { return &unknownEntity{} } | ||
|
||
func (unknownEntity) Kind() Kind { return UnknownKind } | ||
func (unknownEntity) Provider() Provider { return UnknownProvider } | ||
func (unknownEntity) String() string { return "" } | ||
func (unknownEntity) Equals(Entity) bool { return false } | ||
func (unknownEntity) Contains(Entity) bool { return false } | ||
func (unknownEntity) RelDecodeString(input string) (Entity, error) { | ||
// FIXME: support more providers' cloning URLs | ||
if strings.HasPrefix(input, "git@github.com:") { | ||
input = strings.Replace(input, "git@github.com:", "https://github.com/", 1) | ||
} | ||
u, err := url.Parse(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if isProviderScheme(u.Scheme) { | ||
input = input[len(u.Scheme)+3:] | ||
switch u.Scheme { | ||
case string(GitHubProvider): | ||
return gitHubRelDecodeString(getHostname(input), "", "", input, true) | ||
case string(GitLabProvider): | ||
return gitLabRelDecodeString(getHostname(input), "", "", input, true) | ||
//case string(JiraProvider): | ||
//case string(TrelloProvider): | ||
} | ||
} | ||
|
||
if u.Scheme == "" && u.Host == "" && u.Path != "" { // github.com/x/x | ||
u.Host = strings.Split(u.Path, "/")[0] | ||
// u.Path = u.Path[len(u.Host)+1:] | ||
} | ||
|
||
switch u.Scheme { | ||
case "", "https", "http": | ||
switch u.Host { | ||
case "github.com", "api.github.com": | ||
return gitHubRelDecodeString("", "", "", input, true) | ||
case "gitlab.com": | ||
return gitLabRelDecodeString("", "", "", input, true) | ||
case "trello.com": | ||
return trelloRelDecodeString(input, true) | ||
// case "jira.com", "atlassian.com": | ||
} | ||
} | ||
|
||
return nil, fmt.Errorf("ambiguous uri %q", input) | ||
} | ||
func (unknownEntity) LocalID() string { return "" } |
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package multipmuri | ||
|
||
import "fmt" | ||
|
||
func ExampleDecodeString() { | ||
for _, uri := range []string{ | ||
"https://github.com", | ||
"github.com", | ||
"github.com/moul", | ||
"@moul", | ||
"github.com/moul/depviz", | ||
"moul/depviz", | ||
"moul/depviz/milestone/1", | ||
"moul/depviz#1", | ||
"github.com/moul/depviz/issues/2", | ||
"github.com/moul/depviz/pull/1", | ||
"https://github.com/moul/depviz/issues/1", | ||
"https://github.com/moul/depviz#1", | ||
"github://moul/depviz#1", | ||
"github://github.com/moul/depviz#1", | ||
"github://https://github.com/moul/depviz#1", | ||
"github://ghenterprise.company.com/a/b#42", | ||
"github://https://ghenterprise.company.com", | ||
"git@github.com:moul/depviz", | ||
} { | ||
decoded, err := DecodeString(uri) | ||
if err != nil { | ||
fmt.Printf("%-42s error: %v\n", uri, err) | ||
continue | ||
} | ||
fmt.Printf("%-42s %-48s %-8s %s\n", uri, decoded.String(), decoded.Provider(), decoded.Kind()) | ||
} | ||
// Output: | ||
// https://github.com https://github.com/ github service | ||
// github.com https://github.com/ github service | ||
// github.com/moul https://github.com/moul github user-or-organization | ||
// @moul error: ambiguous uri "@moul" | ||
// github.com/moul/depviz https://github.com/moul/depviz github project | ||
// moul/depviz error: ambiguous uri "moul/depviz" | ||
// moul/depviz/milestone/1 error: ambiguous uri "moul/depviz/milestone/1" | ||
// moul/depviz#1 error: ambiguous uri "moul/depviz#1" | ||
// github.com/moul/depviz/issues/2 https://github.com/moul/depviz/issues/2 github issue | ||
// github.com/moul/depviz/pull/1 https://github.com/moul/depviz/issues/1 github merge-request | ||
// https://github.com/moul/depviz/issues/1 https://github.com/moul/depviz/issues/1 github issue | ||
// https://github.com/moul/depviz#1 https://github.com/moul/depviz/issues/1 github issue-or-merge-request | ||
// github://moul/depviz#1 https://github.com/moul/depviz/issues/1 github issue-or-merge-request | ||
// github://github.com/moul/depviz#1 https://github.com/moul/depviz/issues/1 github issue-or-merge-request | ||
// github://https://github.com/moul/depviz#1 https://github.com/moul/depviz/issues/1 github issue-or-merge-request | ||
// github://ghenterprise.company.com/a/b#42 https://ghenterprise.company.com/a/b/issues/42 github issue-or-merge-request | ||
// github://https://ghenterprise.company.com https://ghenterprise.company.com/ github service | ||
// git@github.com:moul/depviz https://github.com/moul/depviz github project | ||
} |
Oops, something went wrong.