Skip to content

Commit

Permalink
Merge pull request DataDog#10279 from DataDog/david.jones/integration…
Browse files Browse the repository at this point in the history
…-collisions

Integration name collision and img update
  • Loading branch information
cswatt authored Apr 13, 2021
2 parents 2da078d + 2729638 commit b6cebe2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions local/bin/py/build/actions/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,16 @@ def process_images(self, file_name):
copyfile(file_name, full_destination_path)

@staticmethod
def replace_image_src(markdown_string):
def replace_image_src(markdown_string, integration_name):
"""
Takes a markdown string and replaces any image markdown with our img shortcode, pointing to the static/images folder.
This is needed when dealing with Marketplace Integrations to properly display images pulled from a private repo.
"""
markdown_img_search_regex = r"!\[(.*?)\]\((.*?)\)"
img_shortcode = "{{< img src=\"\\2\" alt=\"\\1\" >}}"
integration_img_prefix = 'https://raw.githubusercontent.com/DataDog/marketplace/master/'
img_shortcode = "{{< img src=\"marketplace/" + integration_name + "/\\2\" alt=\"\\1\" >}}"
integration_img_prefix = 'https://raw.githubusercontent.com/DataDog/marketplace/master/{}/'.format(integration_name)

replaced_markdown_string = markdown_string.replace(integration_img_prefix, 'marketplace/')
replaced_markdown_string = markdown_string.replace(integration_img_prefix, '')
regex_result = re.sub(markdown_img_search_regex, img_shortcode, replaced_markdown_string, 0, re.MULTILINE)

if regex_result:
Expand Down Expand Up @@ -541,7 +541,10 @@ def process_integration_readme(self, file_name, marketplace=False):
new_file_name = "{}.md".format(
basename(dirname(file_name))
)
exist_already = exists(
# is this the same as a committed hardcoded integration
exist_already = (self.content_integrations_dir + new_file_name in self.initial_integration_files)
# is this overwriting another generated integration
exist_collision = exists(
self.content_integrations_dir + new_file_name
)

Expand All @@ -558,7 +561,7 @@ def process_integration_readme(self, file_name, marketplace=False):
else:
with open(file_name, 'r+') as f:
markdown_string = f.read()
markdown_with_replaced_images = self.replace_image_src(markdown_string)
markdown_with_replaced_images = self.replace_image_src(markdown_string, basename(dirname(file_name)))
updated_markdown = self.remove_markdown_section(markdown_with_replaced_images, '## Setup')
is_marketplace_integration_markdown_valid = self.validate_marketplace_integration_markdown(updated_markdown)

Expand Down Expand Up @@ -617,20 +620,31 @@ def process_integration_readme(self, file_name, marketplace=False):
0,
)

result = self.add_integration_frontmatter(
new_file_name, result, dependencies
)

if not exist_already and no_integration_issue:
# lets only write out file.md if its going to be public
if manifest_json.get("is_public", False):
with open(self.content_integrations_dir + new_file_name, "w", ) as out:
out_name = self.content_integrations_dir + new_file_name

# if the same integration exists in multiple locations try name md after manifest name entry
if exist_collision:
f_name = manifest_json.get("name", new_file_name)
f_name = f_name if f_name.endswith('.md') else f_name + ".md"
out_name = self.content_integrations_dir + f_name
print("\x1b[33mWARNING\x1b[0m: Collision, duplicate integration {} trying as {}".format(
new_file_name, f_name))
new_file_name = f_name

result = self.add_integration_frontmatter(
new_file_name, result, dependencies
)

with open(out_name, "w", ) as out:
out.write(result)

## Reformating all links now that all processing is done
if tab_logic:
final_text = format_link_file(self.content_integrations_dir + new_file_name,regex_skip_sections_start,regex_skip_sections_end)
with open(self.content_integrations_dir + new_file_name, 'w') as final_file:
final_text = format_link_file(out_name, regex_skip_sections_start, regex_skip_sections_end)
with open(out_name, 'w') as final_file:
final_file.write(final_text)

def add_integration_frontmatter(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b6cebe2

Please sign in to comment.