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

Add readme to the package API #128

Merged
merged 2 commits into from
Oct 23, 2019
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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Remove not needed files in Docker image. [#106](https://github.com/elastic/integrations-registry/pull/106)
* Add healthcheck to docker file. [#115](https://github.com/elastic/integrations-registry/pull/115)
* Make caching headers configurable per endpoint. [#116](https://github.com/elastic/integrations-registry/pull/116)
* Add readme entry to package endpoint. [#128](https://github.com/elastic/integrations-registry/pull/128)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion dev/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Build(sourceDir, publicDir string) error {
return nil
}

// CopyPackages copies the files of a package to the public directory
// CopyPackage copies the files of a package to the public directory
func CopyPackage(src, dst string) error {
fmt.Println(">> Copy package: " + src)
os.MkdirAll(dst, 0755)
Expand Down
3 changes: 2 additions & 1 deletion docs/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "example",
"title": "Example Integration",
"version": "1.0.0",
"readme": "/package/example-1.0.0/docs/README.md",
"description": "This is the example integration",
"type": "integration",
"categories": [
Expand Down Expand Up @@ -30,7 +31,7 @@
"assets": [
"/package/example-1.0.0/index.json",
"/package/example-1.0.0/manifest.yml",
"/package/example-1.0.0/docs/docs.asciidoc",
"/package/example-1.0.0/docs/README.md",
"/package/example-1.0.0/img/icon.png",
"/package/example-1.0.0/img/kibana-envoyproxy.jpg",
"/package/example-1.0.0/elasticsearch/ingest-pipeline/pipeline-entry.json",
Expand Down
3 changes: 3 additions & 0 deletions testdata/package/example-1.0.0/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Example readme

This is a readme.
22 changes: 0 additions & 22 deletions testdata/package/example-1.0.0/docs/docs.asciidoc

This file was deleted.

3 changes: 2 additions & 1 deletion testdata/package/example-1.0.0/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "example",
"title": "Example Integration",
"version": "1.0.0",
"readme": "/package/example-1.0.0/docs/README.md",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neptunian I made a change to the PR that this is now the full path like for all the other assets. Let me know what works best on your end.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, i missed this previously. this is preferable.

"description": "This is the example integration",
"type": "integration",
"categories": [
Expand Down Expand Up @@ -30,7 +31,7 @@
"assets": [
"/package/example-1.0.0/index.json",
"/package/example-1.0.0/manifest.yml",
"/package/example-1.0.0/docs/docs.asciidoc",
"/package/example-1.0.0/docs/README.md",
"/package/example-1.0.0/img/icon.png",
"/package/example-1.0.0/img/kibana-envoyproxy.jpg",
"/package/example-1.0.0/elasticsearch/ingest-pipeline/pipeline-entry.json",
Expand Down
16 changes: 16 additions & 0 deletions util/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Package struct {
Name string `yaml:"name" json:"name"`
Title *string `yaml:"title,omitempty" json:"title,omitempty"`
Version string `yaml:"version" json:"version"`
Readme *string `yaml:"readme,omitempty" json:"readme,omitempty"`
versionSemVer semver.Version
Description string `yaml:"description" json:"description"`
Type string `yaml:"type" json:"type"`
Expand Down Expand Up @@ -110,6 +111,21 @@ func NewPackage(basePath, packageName string) (*Package, error) {
return nil, err
}

readmePath := basePath + "/" + packageName + "/docs/README.md"
// Check if readme
readme, err := os.Stat(readmePath)
if err != nil && !os.IsNotExist(err) {
return nil, err
}

if readme != nil {
if readme.IsDir() {
return nil, fmt.Errorf("README.md is a directory")
}
readmePathShort := "/package/" + packageName + "/docs/README.md"
p.Readme = &readmePathShort
}

return p, nil
}

Expand Down