|
| 1 | +import yaml |
| 2 | +import os |
| 3 | + |
| 4 | +# Read the CODEOWNERS file |
| 5 | +codeowners_path = os.path.join(os.path.dirname(__file__), "..", "CODEOWNERS") |
| 6 | +with open(codeowners_path, "r") as file: |
| 7 | + lines = file.readlines() |
| 8 | + |
| 9 | +# Parse the CODEOWNERS file to extract areas and their paths |
| 10 | +areas = [] |
| 11 | +sample_section_found = False |
| 12 | + |
| 13 | +for line in lines: |
| 14 | + line = line.strip() |
| 15 | + if line.startswith("# Samples"): |
| 16 | + sample_section_found = True |
| 17 | + continue |
| 18 | + |
| 19 | + if sample_section_found: |
| 20 | + if line.startswith("#"): |
| 21 | + continue |
| 22 | + elif line: |
| 23 | + path, codeowner = line.split() |
| 24 | + if path in areas: |
| 25 | + raise ValueError(f"Path:{path} has been found two times inside CODEOWNERS file") |
| 26 | + areas.append(path) |
| 27 | + |
| 28 | + |
| 29 | +# Sort the areas in lexicographical order |
| 30 | +areas = sorted(areas) |
| 31 | + |
| 32 | +# Generate the YAML structure |
| 33 | +yaml_form = { |
| 34 | + "name": "Issue with a sample", |
| 35 | + "description": "Report a problem you have with a specific sample.", |
| 36 | + "title": "[path/to/sample]: ", |
| 37 | + "body": [] |
| 38 | +} |
| 39 | + |
| 40 | +dropdown = { |
| 41 | + "type": "dropdown", |
| 42 | + "id": "sample_area", |
| 43 | + "attributes": { |
| 44 | + "label": "Which is the area where the sample lives?", |
| 45 | + "description": "Select the area where you're experiencing the problem.", |
| 46 | + "options": areas |
| 47 | + }, |
| 48 | + "validations": { |
| 49 | + "required": True |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +# Add a description field |
| 54 | +description_field = { |
| 55 | + "type": "textarea", |
| 56 | + "id": "description", |
| 57 | + "attributes": { |
| 58 | + "label": "Describe the issue", |
| 59 | + "description": "Provide a clear and concise description of what the issue is." |
| 60 | + }, |
| 61 | + "validations": { |
| 62 | + "required": True |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +yaml_form["body"].append(dropdown) |
| 67 | +yaml_form["body"].append(description_field) |
| 68 | + |
| 69 | +# Write the YAML to a file |
| 70 | +output_path = os.path.join(os.path.dirname(__file__), "sample_issue.yml") |
| 71 | +with open(output_path, "w") as outfile: |
| 72 | + yaml.dump(yaml_form, outfile, sort_keys=False) |
0 commit comments