Skip to content

Commit

Permalink
chore: fixup inconsistent access method
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmoellerdev committed Dec 18, 2024
1 parent 46a9e2c commit 407988a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions api/ocm/extensions/accessmethods/git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ The artifact content is provided as gnu-zipped tar archive
This method implements the access of the content of a git commit stored in a
git repository.

Supported specification version is `v1`
Supported specification version is `v1alpha1`

### Specification Versions

#### Version `v1`
#### Version `v1alpha1`

The type specific specification fields are:

- **`repoUrl`** *string*
- **`repository`** *string*

Repository URL with or without scheme.

Expand Down
22 changes: 11 additions & 11 deletions api/ocm/extensions/accessmethods/git/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func init() {
type AccessSpec struct {
runtime.ObjectVersionedType `json:",inline"`

// RepoURL is the repository URL
RepoURL string `json:"repository"`
// Repository is the repository URL
Repository string `json:"repository"`

// Ref defines the hash of the commit
Ref string `json:"ref"`
Ref string `json:"ref,omitempty"`

// Commit defines the hash of the commit in string format to checkout from the Ref
Commit string `json:"commit"`
Commit string `json:"commit,omitempty"`
}

// AccessSpecOptions defines a set of options which can be applied to the access spec.
Expand All @@ -63,7 +63,7 @@ func WithRef(ref string) AccessSpecOptions {
func New(url string, opts ...AccessSpecOptions) *AccessSpec {
s := &AccessSpec{
ObjectVersionedType: runtime.NewVersionedTypedObject(Type),
RepoURL: url,
Repository: url,
}
for _, o := range opts {
o(s)
Expand All @@ -72,7 +72,7 @@ func New(url string, opts ...AccessSpecOptions) *AccessSpec {
}

func (a *AccessSpec) Describe(internal.Context) string {
return fmt.Sprintf("git commit %s[%s]", a.RepoURL, a.Ref)
return fmt.Sprintf("git commit %s[%s]", a.Repository, a.Ref)
}

func (*AccessSpec) IsLocal(internal.Context) bool {
Expand All @@ -88,24 +88,24 @@ func (*AccessSpec) GetType() string {
}

func (a *AccessSpec) AccessMethod(cva internal.ComponentVersionAccess) (internal.AccessMethod, error) {
_, err := giturls.Parse(a.RepoURL)
_, err := giturls.Parse(a.Repository)
if err != nil {
return nil, errors.ErrInvalidWrap(err, "repository repoURL", a.RepoURL)
return nil, errors.ErrInvalidWrap(err, "repository repoURL", a.Repository)
}
if err := plumbing.ReferenceName(a.Ref).Validate(); err != nil {
return nil, errors.ErrInvalidWrap(err, "commit hash", a.Ref)
}
creds, _, err := getCreds(a.RepoURL, cva.GetContext().CredentialsContext())
creds, _, err := getCreds(a.Repository, cva.GetContext().CredentialsContext())
if err != nil {
return nil, fmt.Errorf("failed to get credentials for repository %s: %w", a.RepoURL, err)
return nil, fmt.Errorf("failed to get credentials for repository %s: %w", a.Repository, err)
}

octx := cva.GetContext()

opts := []gitblob.Option{
gitblob.WithLoggingContext(octx),
gitblob.WithCredentialContext(octx),
gitblob.WithURL(a.RepoURL),
gitblob.WithURL(a.Repository),
gitblob.WithRef(a.Ref),
gitblob.WithCommit(a.Commit),
gitblob.WithCachingFileSystem(vfsattr.Get(octx)),
Expand Down

0 comments on commit 407988a

Please sign in to comment.