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

Extend issue template yaml engine #29274

Merged
merged 48 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b74923b
format tables
6543 Feb 19, 2024
f451c37
document feature first :D
6543 Feb 19, 2024
a5e7a03
fix docu and add support in validation
6543 Feb 19, 2024
7913bae
make checkbox able to hide and to not be subbmitted
6543 Feb 20, 2024
e01a7c0
make optional markdown submit work
6543 Feb 20, 2024
f73b444
make hide option work
6543 Feb 20, 2024
91662c1
extend example
6543 Feb 20, 2024
a788fb7
Update modules/issue/template/template.go
6543 Feb 20, 2024
e029f7d
Update templates/repo/issue/fields/checkboxes.tmpl
6543 Feb 20, 2024
22d6154
Update modules/issue/template/unmarshal.go
6543 Feb 20, 2024
fb83a79
Merge branch 'main' into extend-issue-template-engine
6543 Feb 20, 2024
0a27610
docs add newline
6543 Feb 20, 2024
f03b527
update swagger
6543 Feb 20, 2024
45c9a39
extend tests
6543 Feb 20, 2024
a4c2713
simplify
6543 Feb 20, 2024
c56c140
finish unit-test adjustments
6543 Feb 20, 2024
a70fe23
check agains required and hidden fields
6543 Feb 20, 2024
bd9cf13
Merge branch 'main' into extend-issue-template-engine
6543 Feb 20, 2024
b2119ac
hide -> hide_on_form
6543 Feb 20, 2024
1e00be7
submit -> skip_submit
6543 Feb 20, 2024
13b1bcc
update templates
6543 Feb 20, 2024
a72ec63
fix test
6543 Feb 20, 2024
333d7e7
Merge branch 'main' into extend-issue-template-engine
6543 Feb 21, 2024
7205492
Merge branch 'main' into extend-issue-template-engine
6543 Feb 22, 2024
bd35e54
Merge branch 'main' into extend-issue-template-engine
6543 Feb 22, 2024
69c4a4f
Merge branch 'main' into extend-issue-template-engine
6543 Feb 23, 2024
b77c75b
Merge branch 'main' into extend-issue-template-engine
6543 Feb 23, 2024
d607f94
Merge branch 'main' into extend-issue-template-engine
6543 Feb 23, 2024
52f58f1
Merge branch 'main' into extend-issue-template-engine
6543 Feb 24, 2024
6259cfb
Merge branch 'main' into extend-issue-template-engine
6543 Feb 25, 2024
60fb756
Merge branch 'main' into extend-issue-template-engine
6543 Feb 26, 2024
683222e
Merge branch 'main' into extend-issue-template-engine
6543 Feb 27, 2024
611dd7a
Apply suggestions from code review
6543 Feb 27, 2024
b2842d6
Merge branch 'main' into extend-issue-template-engine
6543 Mar 1, 2024
58a728f
migrate to Visible in main issue form fields
6543 Mar 1, 2024
0e08e43
migrate to Visible in main issue forms [tests]
6543 Mar 1, 2024
8a0f25e
swagger docs: cant set enum for string type
6543 Mar 1, 2024
c675bc5
handle checkboxes golang
6543 Mar 1, 2024
201fb3a
handle checkboxes templates take1
6543 Mar 1, 2024
7461a8b
handle checkboxes templates take2
6543 Mar 1, 2024
43c7b47
Merge branch 'main' into extend-issue-template-engine
6543 Mar 1, 2024
e331c0e
fix lint
6543 Mar 1, 2024
350a948
Merge branch 'main' into extend-issue-template-engine
6543 Mar 3, 2024
2c8deab
Merge branch 'main' into extend-issue-template-engine
6543 Mar 3, 2024
edbc7ed
Update modules/issue/template/unmarshal.go
6543 Mar 3, 2024
26ea464
apply suggested rename
6543 Mar 3, 2024
4111e76
docs wording
6543 Mar 3, 2024
e726ce0
docs better wording
6543 Mar 3, 2024
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
64 changes: 49 additions & 15 deletions docs/content/usage/issue-pull-request-templates.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ body:
attributes:
value: |
Thanks for taking the time to fill out this bug report!
# some markdown witch will be visible only in the created issue
6543 marked this conversation as resolved.
Show resolved Hide resolved
- type: markdown
attributes:
value: |
This issue git created by an issue **template** :)
6543 marked this conversation as resolved.
Show resolved Hide resolved
hide_on_form: true
skip_submit: false
- type: input
id: contact
attributes:
Expand Down Expand Up @@ -187,18 +194,27 @@ body:
options:
- label: I agree to follow this project's Code of Conduct
required: true
- label: I also have read the CONTRIBUTION.MD
6543 marked this conversation as resolved.
Show resolved Hide resolved
required: true
skip_submit: true
- label: This is a TODO only visible after issue creation
hide_on_form: true
```

### Markdown

You can use a `markdown` element to display Markdown in your form that provides extra context to the user, but is not submitted.
You can use a `markdown` element to display Markdown in your form that provides extra context to the user, but is not submitted by default.

Attributes:

| Key | Description | Required | Type | Default | Valid values |
|-------|--------------------------------------------------------------|----------|--------|---------|--------------|
| value | The text that is rendered. Markdown formatting is supported. | Required | String | - | - |

skip_submit: Default is **true**
lunny marked this conversation as resolved.
Show resolved Hide resolved

hide_on_form: Default is **false**

### Textarea

You can use a `textarea` element to add a multi-line text field to your form. Contributors can also attach files in `textarea` fields.
Expand All @@ -219,6 +235,10 @@ Validations:
|----------|------------------------------------------------------|----------|---------|---------|--------------|
| required | Prevents form submission until element is completed. | Optional | Boolean | false | - |

skip_submit: Default is **false**

hide_on_form: Default is **false**

### Input

You can use an `input` element to add a single-line text field to your form.
Expand All @@ -240,6 +260,10 @@ Validations:
| is_number | Prevents form submission until element is filled with a number. | Optional | Boolean | false | - |
| regex | Prevents form submission until element is filled with a value that match the regular expression. | Optional | String | - | a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) |

skip_submit: Default is **false**

hide_on_form: Default is **false**

### Dropdown

You can use a `dropdown` element to add a dropdown menu in your form.
Expand All @@ -259,24 +283,34 @@ Validations:
|----------|------------------------------------------------------|----------|---------|---------|--------------|
| required | Prevents form submission until element is completed. | Optional | Boolean | false | - |

skip_submit: Default is **false**

hide_on_form: Default is **false**

### Checkboxes

You can use the `checkboxes` element to add a set of checkboxes to your form.

Attributes:

| Key | Description | Required | Type | Default | Valid values |
|-------------|-------------------------------------------------------------------------------------------------------|----------|--------|--------------|--------------|
| ----------- | ----------------------------------------------------------------------------------------------------- | -------- | ------ | ------------ | ------------ |
| label | A brief description of the expected user input, which is displayed in the form. | Required | String | - | - |
| description | A description of the set of checkboxes, which is displayed in the form. Supports Markdown formatting. | Optional | String | Empty String | - |
| options | An array of checkboxes that the user can select. For syntax, see below. | Required | Array | - | - |

For each value in the options array, you can set the following keys.

| Key | Description | Required | Type | Default | Options |
|----------|------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------|---------|
| label | The identifier for the option, which is displayed in the form. Markdown is supported for bold or italic text formatting, and hyperlinks. | Required | String | - | - |
| required | Prevents form submission until element is completed. | Optional | Boolean | false | - |
| Key | Description | Required | Type | Default | Options |
|--------------|------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------|---------|
| label | The identifier for the option, which is displayed in the form. Markdown is supported for bold or italic text formatting, and hyperlinks. | Required | String | - | - |
| required | Prevents form submission until element is completed. | Optional | Boolean | false | - |
| skip_submit | The specific checkbox that is rendered, will not be submitted. | Optional | Boolean | false | - |
| hide_on_form | Do not render in the from. | Optional | Boolean | false | - |
6543 marked this conversation as resolved.
Show resolved Hide resolved

skip_submit: Default is **false**

hide_on_form: Default is **false**

## Syntax for issue config

Expand All @@ -292,15 +326,15 @@ contact_links:

### Possible Options

| Key | Description | Type | Default |
|----------------------|-------------------------------------------------------------------------------------------------------|--------------------|----------------|
| blank_issues_enabled | If set to false, the User is forced to use a Template | Boolean | true |
| contact_links | Custom Links to show in the Choose Box | Contact Link Array | Empty Array |
| Key | Description | Type | Default |
|----------------------|-------------------------------------------------------|--------------------|-------------|
| blank_issues_enabled | If set to false, the User is forced to use a Template | Boolean | true |
| contact_links | Custom Links to show in the Choose Box | Contact Link Array | Empty Array |

### Contact Link

| Key | Description | Type | Required |
|----------------------|-------------------------------------------------------------------------------------------------------|---------|----------|
| name | the name of your link | String | true |
| url | The URL of your Link | String | true |
| about | A short description of your Link | String | true |
| Key | Description | Type | Required |
|-------|----------------------------------|--------|----------|
| name | the name of your link | String | true |
| url | The URL of your Link | String | true |
| about | A short description of your Link | String | true |
57 changes: 50 additions & 7 deletions modules/issue/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ func validateRequired(field *api.IssueFormField, idx int) error {
// The label is not required for a markdown or checkboxes field
return nil
}
return validateBoolItem(newErrorPosition(idx, field.Type), field.Validations, "required")
if err := validateBoolItem(newErrorPosition(idx, field.Type), field.Validations, "required"); err != nil {
return err
}
if required, _ := field.Validations["required"].(bool); required && field.HideOnForm {
return newErrorPosition(idx, field.Type).Errorf("can not require a hidden field")
}
return nil
}

func validateID(field *api.IssueFormField, idx int, ids container.Set[string]) error {
Expand Down Expand Up @@ -177,6 +183,18 @@ func validateOptions(field *api.IssueFormField, idx int) error {
return position.Errorf("'required' should be a bool")
}
}

if skipSubmit, ok := opt["skip_submit"]; ok {
if _, ok := skipSubmit.(bool); !ok {
return position.Errorf("'skip_submit' should be a bool")
}
}

if hide, ok := opt["hide_on_form"]; ok {
if _, ok := hide.(bool); !ok {
return position.Errorf("'hide_on_form' should be a bool")
}
}
}
}
return nil
Expand Down Expand Up @@ -238,7 +256,7 @@ func RenderToMarkdown(template *api.IssueTemplate, values url.Values) string {
IssueFormField: field,
Values: values,
}
if f.ID == "" {
if f.ID == "" || f.NoSubmit() {
continue
}
f.WriteTo(builder)
Expand All @@ -253,11 +271,6 @@ type valuedField struct {
}

func (f *valuedField) WriteTo(builder *strings.Builder) {
if f.Type == api.IssueFormFieldTypeMarkdown {
// markdown blocks do not appear in output
return
}

// write label
if !f.HideLabel() {
_, _ = fmt.Fprintf(builder, "### %s\n\n", f.Label())
Expand All @@ -269,6 +282,9 @@ func (f *valuedField) WriteTo(builder *strings.Builder) {
switch f.Type {
case api.IssueFormFieldTypeCheckboxes:
for _, option := range f.Options() {
if option.NoSubmit() {
continue
}
checked := " "
if option.IsChecked() {
checked = "x"
Expand Down Expand Up @@ -302,6 +318,10 @@ func (f *valuedField) WriteTo(builder *strings.Builder) {
} else {
_, _ = fmt.Fprintf(builder, "%s\n", value)
}
case api.IssueFormFieldTypeMarkdown:
if value, ok := f.Attributes["value"].(string); ok {
_, _ = fmt.Fprintf(builder, "%s\n", value)
}
}
_, _ = fmt.Fprintln(builder)
}
Expand All @@ -313,7 +333,19 @@ func (f *valuedField) Label() string {
return ""
}

func (f *valuedField) NoSubmit() bool {
// handle default case
if f.SkipSubmit == nil {
// markdown blocks do not appear in output by default
return f.Type != api.IssueFormFieldTypeMarkdown
}
return *f.SkipSubmit
}

func (f *valuedField) HideLabel() bool {
if f.Type == api.IssueFormFieldTypeMarkdown {
return true
}
if label, ok := f.Attributes["hide_label"].(bool); ok {
return label
}
Expand Down Expand Up @@ -385,6 +417,17 @@ func (o *valuedOption) IsChecked() bool {
return false
}

func (o *valuedOption) NoSubmit() bool {
if o.field.Type == api.IssueFormFieldTypeCheckboxes {
6543 marked this conversation as resolved.
Show resolved Hide resolved
if vs, ok := o.data.(map[string]any); ok {
if v, ok := vs["skip_submit"].(bool); ok {
return v
}
}
}
return false
}

var minQuotesRegex = regexp.MustCompilePOSIX("^`{3,}")

// minQuotes return 3 or more back-quotes.
Expand Down
Loading
Loading