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

[Automatic Import] Use datastream description in readme #203236

Merged
merged 5 commits into from
Dec 10, 2024
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
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
Loading