summaryrefslogtreecommitdiff
path: root/.github/ISSUE_TEMPLATE/sample_issue_generator.py
blob: 4b6eee640a68a3408babac6a30c8379e2d7ee39d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import yaml
import os

# Read the CODEOWNERS file
codeowners_path = os.path.join(os.path.dirname(__file__), "..", "CODEOWNERS")
with open(codeowners_path, "r") as file:
    lines = file.readlines()

# Parse the CODEOWNERS file to extract areas and their paths
areas = []
sample_section_found = False

for line in lines:
    line = line.strip()
    if line.startswith("# Samples"):
        sample_section_found = True
        continue

    if sample_section_found:
        if line.startswith("#"):
            continue
        elif line:
            path, codeowner = line.split()
            if path in areas:
                raise ValueError(f"Path:{path} has been found two times inside CODEOWNERS file")
            areas.append(path)


# Sort the areas in lexicographical order
areas = sorted(areas)

# Generate the YAML structure
yaml_form = {
    "name": "Issue with a sample",
    "description": "Report a problem you have with a specific sample.",
    "title": "[path/to/sample]: ",
    "body": []
}

dropdown = {
    "type": "dropdown",
    "id": "sample_area",
    "attributes": {
        "label": "Which is the area where the sample lives?",
        "description": "Select the area where you're experiencing the problem.",
        "options": areas
    },
    "validations": {
        "required": True
    }
}

# Add a description field
description_field = {
    "type": "textarea",
    "id": "description",
    "attributes": {
        "label": "Describe the issue",
        "description": "Provide a clear and concise description of what the issue is."
    },
    "validations": {
        "required": True
    }
}

yaml_form["body"].append(dropdown)
yaml_form["body"].append(description_field)

# Write the YAML to a file
output_path = os.path.join(os.path.dirname(__file__), "sample_issue.yml")
with open(output_path, "w") as outfile:
    yaml.dump(yaml_form, outfile, sort_keys=False)