Skip to content

Commit

Permalink
[Automatic Import] Use datastream description in readme (elastic#203236)
Browse files Browse the repository at this point in the history
## Release note

Use provided data stream description in generated README

## Summary

Closes [elastic#201294](elastic#201294)

This PR fixes use of `datastream description` that the user entered in
the input field.


![image](https://github.com/user-attachments/assets/b093c978-2102-4bdc-824e-d60aa3fd908b)
  • Loading branch information
bhapas authored Dec 10, 2024
1 parent cbee44b commit d3161ab
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,24 +209,29 @@ describe('buildPackage', () => {

await buildPackage(testIntegration);

expect(createReadme).toHaveBeenCalledWith(integrationPath, testIntegration.name, [
{
datastream: firstDatastreamName,
fields: [
{ name: 'name a', description: 'description 1', type: 'type 1' },
expect(createReadme).toHaveBeenCalledWith(
integrationPath,
testIntegration.name,
testIntegration.dataStreams,
[
{
datastream: firstDatastreamName,
fields: [
{ name: 'name a', description: 'description 1', type: 'type 1' },

{ name: 'name b', description: 'description 1', type: 'type 1' },
],
},
{
datastream: secondDatastreamName,
fields: [
{ name: 'name c', description: 'description 2', type: 'type 2' },
{ name: 'name d', description: 'description 2', type: 'type 2' },
{ name: 'name e', description: 'description 3', type: 'type 3' },
],
},
]);
{ name: 'name b', description: 'description 1', type: 'type 1' },
],
},
{
datastream: secondDatastreamName,
fields: [
{ name: 'name c', description: 'description 2', type: 'type 2' },
{ name: 'name d', description: 'description 2', type: 'type 2' },
{ name: 'name e', description: 'description 3', type: 'type 3' },
],
},
]
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function buildPackage(integration: Integration): Promise<Buffer> {
};
});

createReadme(packageDir, integration.name, fieldsPerDatastream);
createReadme(packageDir, integration.name, integration.dataStreams, fieldsPerDatastream);
const zipBuffer = await createZipArchive(workingDir, packageDirectoryName);

removeDirSync(workingDir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('createReadme', () => {
},
];

createReadme(integrationPath, testIntegration.name, fields);
createReadme(integrationPath, testIntegration.name, testIntegration.dataStreams, fields);

expect(createSync).toHaveBeenCalledWith(
`${integrationPath}/_dev/build/docs/README.md`,
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('createReadme', () => {
},
];

createReadme(integrationPath, testIntegration.name, fields);
createReadme(integrationPath, testIntegration.name, testIntegration.dataStreams, fields);

const firstDatastreamFieldsDisplayed = `
| Field | Description | Type |
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('createReadme', () => {
},
];

createReadme(integrationPath, testIntegration.name, fields);
createReadme(integrationPath, testIntegration.name, testIntegration.dataStreams, fields);

expect(createSync).toHaveBeenCalledWith(
`${integrationPath}/_dev/build/docs/README.md`,
Expand All @@ -165,7 +165,7 @@ describe('createReadme', () => {
},
];

createReadme(integrationPath, testIntegration.name, fields);
createReadme(integrationPath, testIntegration.name, testIntegration.dataStreams, fields);

const firstDatastreamFieldsDisplayed = `
| Field | Description | Type |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,46 @@
import { Environment, FileSystemLoader } from 'nunjucks';

import { join as joinPath } from 'path';
import { DataStream } from '../../common';
import { createSync, ensureDirSync } from '../util';

export function createReadme(packageDir: string, integrationName: string, fields: object[]) {
createPackageReadme(packageDir, integrationName, fields);
createBuildReadme(packageDir, integrationName, fields);
export function createReadme(
packageDir: string,
integrationName: string,
datastreams: DataStream[],
fields: object[]
) {
createPackageReadme(packageDir, integrationName, datastreams, fields);
createBuildReadme(packageDir, integrationName, datastreams, fields);
}

function createPackageReadme(packageDir: string, integrationName: string, fields: object[]) {
function createPackageReadme(
packageDir: string,
integrationName: string,
datastreams: DataStream[],
fields: object[]
) {
const dirPath = joinPath(packageDir, 'docs/');
// The readme nunjucks template files should be named in the format `somename_readme.md.njk` and not just `readme.md.njk`
// since any file with `readme.*` pattern is skipped in build process in buildkite.
createReadmeFile(dirPath, 'package_readme.md.njk', integrationName, fields);
createReadmeFile(dirPath, 'package_readme.md.njk', integrationName, datastreams, fields);
}

function createBuildReadme(packageDir: string, integrationName: string, fields: object[]) {
function createBuildReadme(
packageDir: string,
integrationName: string,
datastreams: DataStream[],
fields: object[]
) {
const dirPath = joinPath(packageDir, '_dev/build/docs/');
createReadmeFile(dirPath, 'build_readme.md.njk', integrationName, fields);
createReadmeFile(dirPath, 'build_readme.md.njk', integrationName, datastreams, fields);
}

function createReadmeFile(
targetDir: string,
templateName: string,
integrationName: string,
datastreams: DataStream[],
fields: object[]
) {
ensureDirSync(targetDir);
Expand All @@ -44,6 +61,7 @@ function createReadmeFile(

const renderedTemplate = template.render({
package_name: integrationName,
datastreams,
fields,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% include "./description_readme.njk" %}
{% for data_stream in fields %}
### {{ data_stream.datastream }}

Insert a description of the datastream here.
{% for datastream in datastreams %}
### {{ datastream.title }}

{{ datastream.description }}{% endfor %}
{% for data_stream in fields %}
{% raw %}{{fields {% endraw %}"{{ data_stream.datastream }}"{% raw %}}}{% endraw %}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ Check the [overview guidelines](https://www.elastic.co/guide/en/integrations-dev

## Datastreams

Provide a high-level overview of the kind of data that is collected by the integration.
Check the [datastreams guidelines](https://www.elastic.co/guide/en/integrations-developer/current/documentation-guidelines.html#idg-docs-guidelines-datastreams) for more information.
{% for datastream in datastreams %}
### {{ datastream.title }}

{{ datastream.description }}
{% endfor %}

## Requirements

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% include "./description_readme.njk" %}
{% for data_stream in fields %}
### {{ data_stream.datastream }}
{% for datastream in datastreams %}
### {{ datastream.title }}

Insert a description of the datastream here.
{{ datastream.description }}{% endfor %}

**ECS Field Reference**

Please refer to the following [document](https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html) for detailed information on ECS fields.

**Exported fields**

{% for data_stream in fields %}
| Field | Description | Type |
|---|---|---|
{% for field in data_stream.fields %}| {{ field.name }} | {{ field.description | default('') | replace('\n', ' ') | trim }} | {{ field.type }} |
Expand Down

0 comments on commit d3161ab

Please sign in to comment.