Skip to content

Commit

Permalink
Stars and forks information
Browse files Browse the repository at this point in the history
Signed-off-by: AbstractionFactory <[email protected]>
  • Loading branch information
abstractionfactory committed Sep 10, 2024
1 parent bf96910 commit 06c935e
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 21 deletions.
2 changes: 1 addition & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/go-enry/go-license-detector/v4 v4.3.1
github.com/lib/pq v1.10.9
github.com/mitchellh/go-spdx v0.1.0
github.com/opentofu/libregistry v0.0.0-20240905103355-13386c198ea1
github.com/opentofu/libregistry v0.0.0-20240910082859-9c6ed0d4e8c9
github.com/opentofu/tofudl v0.0.0-20240730151408-3bd8529dae09
github.com/opentofu/tofutestutils v0.0.0-20240821111804-5fcfb797e0a7
golang.org/x/sync v0.8.0
Expand Down
4 changes: 4 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ github.com/opentofu/libregistry v0.0.0-20240902143137-5bc965332079 h1:GdkIdGChrf
github.com/opentofu/libregistry v0.0.0-20240902143137-5bc965332079/go.mod h1:irS/XyfQZdwi3Ggm105FfDyj3d9deFAi5GraORIeMsI=
github.com/opentofu/libregistry v0.0.0-20240905103355-13386c198ea1 h1:1+kxZxlnYwakDxdHf90YdaLwd9F+MBuY/70lIRmT2pA=
github.com/opentofu/libregistry v0.0.0-20240905103355-13386c198ea1/go.mod h1:irS/XyfQZdwi3Ggm105FfDyj3d9deFAi5GraORIeMsI=
github.com/opentofu/libregistry v0.0.0-20240910075953-6c45ad4f4556 h1:ISqSSUui7CutQaOYqtlHUnhELagGk6aSpotDRZPggnA=
github.com/opentofu/libregistry v0.0.0-20240910075953-6c45ad4f4556/go.mod h1:irS/XyfQZdwi3Ggm105FfDyj3d9deFAi5GraORIeMsI=
github.com/opentofu/libregistry v0.0.0-20240910082859-9c6ed0d4e8c9 h1:UgpXQNzmL0F4xCmOkllL0KBd67gNAqbG2gRIpOkhxmY=
github.com/opentofu/libregistry v0.0.0-20240910082859-9c6ed0d4e8c9/go.mod h1:irS/XyfQZdwi3Ggm105FfDyj3d9deFAi5GraORIeMsI=
github.com/opentofu/registry-address v0.0.0-20230922120653-901b9ae4061a h1:NyM/PPbc+kxxv2d4OKfE32C5fLtVTLceyg4YKKCYO9Y=
github.com/opentofu/registry-address v0.0.0-20230922120653-901b9ae4061a/go.mod h1:HzQhpVo/NJnGmN+7FPECCVCA5ijU7AUcvf39enBKYOc=
github.com/opentofu/tofudl v0.0.0-20240730151408-3bd8529dae09 h1:bA3Dy3Be9o896wdcQhK0Ky2Eco0ZwCWZgt73dSaYuDI=
Expand Down
53 changes: 40 additions & 13 deletions backend/internal/providerindex/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,8 @@ func (d *documentationGenerator) scrapeProvider(ctx context.Context, addr provid
continue
}
if !repoInfoFetched {
// Make sure to fetch the description for the search index:
d.extractRepoInfo(ctx, addr, providerData)
repoInfoFetched = true
repoInfo, err := d.vcsClient.GetRepositoryInfo(ctx, addr.ToRepositoryAddr())
if err != nil {
var repoNotFound *vcs.RepositoryNotFoundError
if errors.As(err, &repoNotFound) {
d.log.Warn(ctx, "Repository not found for provider %s, skipping... (%v)", addr.String(), err)
break
}
// We handle description errors as soft errors because they are purely presentational.
d.log.Warn(ctx, "Cannot update repository description for provider %s (%v)", addr.String(), err)
} else {
providerData.Description = repoInfo.Description
}
}

providerVersion, err := d.scrapeVersion(ctx, addr, canonicalAddr, version, blocked, blockedReason)
Expand Down Expand Up @@ -321,6 +309,45 @@ func (d *documentationGenerator) scrapeProvider(ctx context.Context, addr provid
return nil
}

func (d *documentationGenerator) extractRepoInfo(ctx context.Context, addr providertypes.ProviderAddr, providerData *providertypes.Provider) {
// Make sure to fetch the description for the search index:
repoInfo, err := d.vcsClient.GetRepositoryInfo(ctx, addr.ToRepositoryAddr())
if err != nil {
var repoNotFound *vcs.RepositoryNotFoundError
if errors.As(err, &repoNotFound) {
d.log.Warn(ctx, "Repository not found for provider %s, skipping... (%v)", addr.String(), err)
return
}
// We handle description errors as soft errors because they are purely presentational.
d.log.Warn(ctx, "Cannot update repository description for provider %s (%v)", addr.String(), err)
return
}
providerData.Description = repoInfo.Description
providerData.ForkCount = repoInfo.ForkCount

forkRepo := repoInfo.ForkOf
if forkRepo == nil {
return
}
link, err := d.vcsClient.GetRepositoryBrowseURL(ctx, *forkRepo)
if err != nil {
d.log.Warn(ctx, "Cannot determine repository browse URL for %s (%v)", forkRepo.String(), err)
return
}
providerData.ForkOfLink = link

forkedAddr, err := provider.AddrFromRepository(*forkRepo)
if err != nil {
d.log.Warn(ctx, "Cannot convert repository name %s to a provider addr (%v)", forkRepo.String(), err)
return
}
_, err = d.metadataAPI.GetProvider(ctx, forkedAddr, false)
if err != nil {
return
}
providerData.ForkOf = providertypes.Addr(forkedAddr)
}

func (d *documentationGenerator) scrapeVersion(ctx context.Context, addr providertypes.ProviderAddr, canonicalAddr provider.Addr, version provider.Version, blocked bool, blockedReason string) (providertypes.ProviderVersion, error) {
// We get the VCS version before normalizing as the tag name may be different.
vcsVersion := version.Version.ToVCSVersion()
Expand Down
11 changes: 11 additions & 0 deletions backend/internal/providerindex/providertypes/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ type Provider struct {
//
// required: true
Description string `json:"description"`
// Popularity indicates how popular the underlying repository is in the VCS system.
// required: true
Popularity int `json:"popularity"`
// ForkCount indicates how many forks this provider has.
// required: true
ForkCount int `json:"fork_count"`
// ForkOfLink may contain a link to a repository this provider is forked from.
ForkOfLink string `json:"fork_of_link,omitempty"`
// ForkOf indicates which provider this repository is forked from. This field may be empty even if
// the ForkOfLink field is filled.
ForkOf ProviderAddr `json:"fork_of,omitempty"`
// Versions holds the list of versions this provider supports.
//
// required: true
Expand Down
35 changes: 28 additions & 7 deletions backend/internal/server/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ definitions:
description: Examples lists all examples for this version.
type: object
id:
$ref: '#/definitions/VersionNumber'
$ref: '#/definitions/ModuleVersionNumber'
incompatible_license:
description: IncompatibleLicense indicates that there are no licenses or there is one or more license that are not approved.
type: boolean
Expand Down Expand Up @@ -431,7 +431,7 @@ definitions:
ModuleVersionDescriptor:
properties:
id:
$ref: '#/definitions/VersionNumber'
$ref: '#/definitions/ModuleVersionNumber'
published:
format: date-time
type: string
Expand All @@ -440,6 +440,12 @@ definitions:
- published
title: ModuleVersionDescriptor describes a single version.
type: object
ModuleVersionNumber:
description: |-
VersionNumber describes the semver version number. Note that in contrast to provider versions module versions
do not have a compulsory "v" prefix. Call ToVCSVersion() before you call Normalize() in order to get the correct
VCS version.
type: string
Output:
properties:
description:
Expand All @@ -462,8 +468,21 @@ definitions:
description:
description: Description is the extracted description for the provider. This may be empty.
type: string
fork_count:
description: ForkCount indicates how many forks this provider has.
format: int64
type: integer
fork_of:
$ref: '#/definitions/ProviderAddr'
fork_of_link:
description: ForkOfLink may contain a link to a repository this provider is forked from.
type: string
is_blocked:
type: boolean
popularity:
description: Popularity indicates how popular the underlying repository is in the VCS system.
format: int64
type: integer
reverse_aliases:
description: |-
ReverseAliases contains a list of providers that are aliases of the current one. This field is the inverse of
Expand All @@ -479,6 +498,8 @@ definitions:
required:
- addr
- description
- popularity
- fork_count
- versions
- is_blocked
title: Provider is a single provider with all its versions.
Expand Down Expand Up @@ -578,7 +599,7 @@ definitions:
docs:
$ref: '#/definitions/ProviderDocs'
id:
$ref: '#/definitions/VersionNumber'
$ref: '#/definitions/ProviderVersionNumber'
incompatible_license:
description: IncompatibleLicense indicates that there are no licenses or there is one or more license that are not approved.
type: boolean
Expand All @@ -601,7 +622,7 @@ definitions:
ProviderVersionDescriptor:
properties:
id:
$ref: '#/definitions/VersionNumber'
$ref: '#/definitions/ProviderVersionNumber'
published:
format: date-time
type: string
Expand All @@ -610,6 +631,9 @@ definitions:
- published
title: ProviderVersionDescriptor describes a provider version.
type: object
ProviderVersionNumber:
title: VersionNumber describes the semver version number.
type: string
Resource:
properties:
address:
Expand Down Expand Up @@ -733,9 +757,6 @@ definitions:
- required
title: Variable describes a variable as the UI expects it.
type: object
VersionNumber:
title: VersionNumber describes the semver version number.
type: string
host: api.opentofu.org
info:
description: The API to fetch documentation index and documentation files from the OpenTofu registry.
Expand Down
3 changes: 3 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go 1.22.1

use backend
Loading

0 comments on commit 06c935e

Please sign in to comment.