Skip to content

Commit

Permalink
Support for multi-paragraph description (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
1ucian0 authored Feb 26, 2023
1 parent 819cd8b commit f3261b5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
35 changes: 24 additions & 11 deletions ecosystem/utils/submission_parser.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
"""Parser for issue submission."""
import re
from collections import defaultdict
import mdformat

from ecosystem.models.repository import Repository


def _clean_section(section: str) -> {str: str}:
"""For a section, return a tuple with a title and "clean section".
A clean section is without new lines and strip spaces"""
paragraphs = section.split("\n")
section = (" ").join(
[paragraph.strip() for paragraph in paragraphs[1:] if paragraph]
)
title = paragraphs[0].strip()
return (title, section)


def parse_submission_issue(body_of_issue: str) -> Repository:
"""Parse issue body.
Expand All @@ -16,19 +27,21 @@ def parse_submission_issue(body_of_issue: str) -> Repository:

issue_formatted = mdformat.text(body_of_issue)

parse = re.findall(r"^([\s\S]*?)(?:\n{2,}|\Z)", issue_formatted, re.M)
sections = defaultdict(
None, [_clean_section(s) for s in issue_formatted.split("### ")[1:]]
)

repo_name = parse[1].split("/")
repo_name = sections["Github repo"].split("/")[-1]

name = repo_name[-1]
url = parse[1]
description = parse[3]
contact_info = parse[5]
alternatives = parse[7]
licence = parse[9]
affiliations = parse[11]
name = repo_name
url = sections["Github repo"]
description = sections["Description"]
contact_info = sections["Email"]
alternatives = sections["Alternatives"]
licence = sections["License"]
affiliations = sections["Affiliations"]

labels = [l.strip() for l in parse[13].split(",")]
labels = [l.strip() for l in sections["Tags"].split(",")]

return Repository(
name,
Expand Down
4 changes: 4 additions & 0 deletions tests/resources/issue.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ http://github.com/awesome/awesome

An awesome repo for awesome project

multiple

paragraphs

### Email

[email protected]
Expand Down
3 changes: 2 additions & 1 deletion tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def test_parser_issue(self):
)
self.assertEqual(
output_value[2],
"::set-output name=SUBMISSION_DESCRIPTION::An awesome repo for awesome project",
"::set-output name=SUBMISSION_DESCRIPTION::An awesome repo for awesome project multiple"
" paragraphs",
)
self.assertEqual(
output_value[3], "::set-output name=SUBMISSION_LICENCE::Apache License 2.0"
Expand Down
3 changes: 2 additions & 1 deletion tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def test_issue_parsing(self):
self.assertEqual(parsed_result.name, "awesome")
self.assertEqual(parsed_result.url, "http://github.com/awesome/awesome")
self.assertEqual(
parsed_result.description, "An awesome repo for awesome project"
parsed_result.description,
"An awesome repo for awesome project multiple paragraphs",
)
self.assertEqual(parsed_result.contact_info, "[email protected]")
self.assertEqual(parsed_result.alternatives, "tititata")
Expand Down

0 comments on commit f3261b5

Please sign in to comment.