Skip to content
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

feat: merge multipmuri as a depviz/pkg #664

Merged
merged 1 commit into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/dvcore/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/cayleygraph/cayley/schema"
"go.uber.org/zap"
"moul.io/depviz/v3/pkg/dvparser"
"moul.io/multipmuri"
"moul.io/depviz/v3/pkg/multipmuri"
)

type FetchOpts struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dvcore/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"moul.io/depviz/v3/pkg/dvparser"
"moul.io/depviz/v3/pkg/dvstore"
"moul.io/depviz/v3/pkg/githubprovider"
"moul.io/depviz/v3/pkg/multipmuri"
"moul.io/godev"
"moul.io/graphman"
"moul.io/multipmuri"
)

type GenOpts struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dvcore/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/cayleygraph/quad"
"github.com/stretchr/testify/assert"
"moul.io/depviz/v3/pkg/dvstore"
"moul.io/depviz/v3/pkg/multipmuri"
"moul.io/depviz/v3/pkg/testutil"
"moul.io/multipmuri"
)

func TestPullAndSave(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dvparser/target.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dvparser

import "moul.io/multipmuri"
import "moul.io/depviz/v3/pkg/multipmuri"

func ParseTargets(args []string) ([]multipmuri.Entity, error) {
targets := []multipmuri.Entity{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dvserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"google.golang.org/grpc/credentials/insecure"
"moul.io/depviz/v3/pkg/chiutil"
"moul.io/depviz/v3/pkg/dvcore"
"moul.io/multipmuri"
"moul.io/depviz/v3/pkg/multipmuri"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/dvstore/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cayleygraph/quad"
"go.uber.org/zap"
"moul.io/depviz/v3/pkg/dvmodel"
"moul.io/multipmuri"
"moul.io/depviz/v3/pkg/multipmuri"
)

func LastUpdatedIssueInRepo(ctx context.Context, h *cayley.Handle, entity multipmuri.Entity) (time.Time, error) { // nolint:interfacer
Expand Down
2 changes: 1 addition & 1 deletion pkg/dvstore/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
_ "github.com/cayleygraph/quad/json"
"github.com/stretchr/testify/assert"
"moul.io/depviz/v3/pkg/dvparser"
"moul.io/depviz/v3/pkg/multipmuri"
"moul.io/depviz/v3/pkg/testutil"
"moul.io/godev"
"moul.io/multipmuri"
)

func TestLoadTasks(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/githubprovider/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.uber.org/zap"
"golang.org/x/oauth2"
"moul.io/depviz/v3/pkg/dvmodel"
"moul.io/multipmuri"
"moul.io/depviz/v3/pkg/multipmuri"
)

type Opts struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/githubprovider/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"go.uber.org/zap"
"moul.io/depviz/v3/pkg/dvmodel"
"moul.io/depviz/v3/pkg/dvparser"
"moul.io/multipmuri"
"moul.io/multipmuri/pmbodyparser"
"moul.io/depviz/v3/pkg/multipmuri"
"moul.io/depviz/v3/pkg/multipmuri/pmbodyparser"
)

const (
Expand Down
64 changes: 64 additions & 0 deletions pkg/multipmuri/decode.go
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 "" }
52 changes: 52 additions & 0 deletions pkg/multipmuri/decode_test.go
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
}
Loading