Skip to content

Commit 84447df

Browse files
wolfogrewxiaoguang
andauthored
Support Issue forms and PR forms (#20987)
* feat: extend issue template for yaml * feat: support yaml template * feat: render form to markdown * feat: support yaml template for pr * chore: rename to Fields * feat: template unmarshal * feat: split template * feat: render to markdown * feat: use full name as template file name * chore: remove useless file * feat: use dropdown of fomantic ui * feat: update input style * docs: more comments * fix: render text without render * chore: fix lint error * fix: support use description as about in markdown * fix: add field class in form * chore: generate swagger * feat: validate template * feat: support is_nummber and regex * test: fix broken unit tests * fix: ignore empty body of md template * fix: make multiple easymde editors work in one page * feat: better UI * fix: js error in pr form * chore: generate swagger * feat: support regex validation * chore: generate swagger * fix: refresh each markdown editor * chore: give up required validation * fix: correct issue template candidates * fix: correct checkboxes style * chore: ignore .hugo_build.lock in docs * docs: separate out a new doc for merge templates * docs: introduce syntax of yaml template * feat: show a alert for invalid templates * test: add case for a valid template * fix: correct attributes of required checkbox * fix: add class not-under-easymde for dropzone * fix: use more back-quotes * chore: remove translation in zh-CN * fix EasyMDE statusbar margin * fix: remove repeated blocks * fix: reuse regex for quotes Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent b7a4b45 commit 84447df

30 files changed

+1773
-173
lines changed

docs/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ public/
22
templates/swagger/v1_json.tmpl
33
themes/
44
resources/
5+
6+
# Temporary lock file while building
7+
/.hugo_build.lock

docs/content/doc/usage/issue-pull-request-templates.en-us.md

Lines changed: 187 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,53 @@ main branch of the repository so that they can autopopulate the form when users
2525
creating issues and pull requests. This will cut down on the initial back and forth
2626
of getting some clarifying details.
2727

28+
Additionally, the New Issue page URL can be suffixed with `?title=Issue+Title&body=Issue+Text` and the form will be populated with those strings. Those strings will be used instead of the template if there is one.
29+
30+
## File names
31+
2832
Possible file names for issue templates:
2933

3034
- `ISSUE_TEMPLATE.md`
35+
- `ISSUE_TEMPLATE.yaml`
36+
- `ISSUE_TEMPLATE.yml`
3137
- `issue_template.md`
38+
- `issue_template.yaml`
39+
- `issue_template.yml`
3240
- `.gitea/ISSUE_TEMPLATE.md`
41+
- `.gitea/ISSUE_TEMPLATE.yaml`
42+
- `.gitea/ISSUE_TEMPLATE.yml`
43+
- `.gitea/issue_template.md`
44+
- `.gitea/issue_template.yaml`
3345
- `.gitea/issue_template.md`
3446
- `.github/ISSUE_TEMPLATE.md`
47+
- `.github/ISSUE_TEMPLATE.yaml`
48+
- `.github/ISSUE_TEMPLATE.yml`
3549
- `.github/issue_template.md`
50+
- `.github/issue_template.yaml`
51+
- `.github/issue_template.yml`
3652

3753
Possible file names for PR templates:
3854

3955
- `PULL_REQUEST_TEMPLATE.md`
56+
- `PULL_REQUEST_TEMPLATE.yaml`
57+
- `PULL_REQUEST_TEMPLATE.yml`
4058
- `pull_request_template.md`
59+
- `pull_request_template.yaml`
60+
- `pull_request_template.yml`
4161
- `.gitea/PULL_REQUEST_TEMPLATE.md`
62+
- `.gitea/PULL_REQUEST_TEMPLATE.yaml`
63+
- `.gitea/PULL_REQUEST_TEMPLATE.yml`
4264
- `.gitea/pull_request_template.md`
65+
- `.gitea/pull_request_template.yaml`
66+
- `.gitea/pull_request_template.yml`
4367
- `.github/PULL_REQUEST_TEMPLATE.md`
68+
- `.github/PULL_REQUEST_TEMPLATE.yaml`
69+
- `.github/PULL_REQUEST_TEMPLATE.yml`
4470
- `.github/pull_request_template.md`
71+
- `.github/pull_request_template.yaml`
72+
- `.github/pull_request_template.yml`
4573

46-
Possible file names for PR default merge message templates:
47-
48-
- `.gitea/default_merge_message/MERGE_TEMPLATE.md`
49-
- `.gitea/default_merge_message/REBASE_TEMPLATE.md`
50-
- `.gitea/default_merge_message/REBASE-MERGE_TEMPLATE.md`
51-
- `.gitea/default_merge_message/SQUASH_TEMPLATE.md`
52-
- `.gitea/default_merge_message/MANUALLY-MERGED_TEMPLATE.md`
53-
- `.gitea/default_merge_message/REBASE-UPDATE-ONLY_TEMPLATE.md`
54-
55-
You can use the following variables enclosed in `${}` inside these templates which follow [os.Expand](https://pkg.go.dev/os#Expand) syntax:
56-
57-
- BaseRepoOwnerName: Base repository owner name of this pull request
58-
- BaseRepoName: Base repository name of this pull request
59-
- BaseBranch: Base repository target branch name of this pull request
60-
- HeadRepoOwnerName: Head repository owner name of this pull request
61-
- HeadRepoName: Head repository name of this pull request
62-
- HeadBranch: Head repository branch name of this pull request
63-
- PullRequestTitle: Pull request's title
64-
- PullRequestDescription: Pull request's description
65-
- PullRequestPosterName: Pull request's poster name
66-
- PullRequestIndex: Pull request's index number
67-
- PullRequestReference: Pull request's reference char with index number. i.e. #1, !2
68-
- ClosingIssues: return a string contains all issues which will be closed by this pull request i.e. `close #1, close #2`
69-
70-
Additionally, the New Issue page URL can be suffixed with `?title=Issue+Title&body=Issue+Text` and the form will be populated with those strings. Those strings will be used instead of the template if there is one.
71-
72-
## Issue Template Directory
74+
## Directory names
7375

7476
Alternatively, users can create multiple issue templates inside a special directory and allow users to choose one that more specifically
7577
addresses their problem.
@@ -85,7 +87,9 @@ Possible directory names for issue templates:
8587
- `.gitlab/ISSUE_TEMPLATE`
8688
- `.gitlab/issue_template`
8789

88-
Inside the directory can be multiple markdown (`.md`) issue templates of the form
90+
Inside the directory can be multiple markdown (`.md`) or yaml (`.yaml`/`.yml`) issue templates of the form.
91+
92+
## Syntax for markdown template
8993

9094
```md
9195
---
@@ -108,3 +112,158 @@ In the above example, when a user is presented with the list of issues they can
108112
`This template is for testing!`. When submitting an issue with the above example, the issue title would be pre-populated with
109113
`[TEST] ` while the issue body would be pre-populated with `This is the template!`. The issue would also be assigned two labels,
110114
`bug` and `help needed`, and the issue will have a reference to `main`.
115+
116+
## Syntax for yaml template
117+
118+
This example YAML configuration file defines an issue form using several inputs to report a bug.
119+
120+
```yaml
121+
name: Bug Report
122+
about: File a bug report
123+
title: "[Bug]: "
124+
body:
125+
- type: markdown
126+
attributes:
127+
value: |
128+
Thanks for taking the time to fill out this bug report!
129+
- type: input
130+
id: contact
131+
attributes:
132+
label: Contact Details
133+
description: How can we get in touch with you if we need more info?
134+
placeholder: ex. email@example.com
135+
validations:
136+
required: false
137+
- type: textarea
138+
id: what-happened
139+
attributes:
140+
label: What happened?
141+
description: Also tell us, what did you expect to happen?
142+
placeholder: Tell us what you see!
143+
value: "A bug happened!"
144+
validations:
145+
required: true
146+
- type: dropdown
147+
id: version
148+
attributes:
149+
label: Version
150+
description: What version of our software are you running?
151+
options:
152+
- 1.0.2 (Default)
153+
- 1.0.3 (Edge)
154+
validations:
155+
required: true
156+
- type: dropdown
157+
id: browsers
158+
attributes:
159+
label: What browsers are you seeing the problem on?
160+
multiple: true
161+
options:
162+
- Firefox
163+
- Chrome
164+
- Safari
165+
- Microsoft Edge
166+
- type: textarea
167+
id: logs
168+
attributes:
169+
label: Relevant log output
170+
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
171+
render: shell
172+
- type: checkboxes
173+
id: terms
174+
attributes:
175+
label: Code of Conduct
176+
description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com)
177+
options:
178+
- label: I agree to follow this project's Code of Conduct
179+
required: true
180+
```
181+
182+
### Markdown
183+
184+
You can use a `markdown` element to display Markdown in your form that provides extra context to the user, but is not submitted.
185+
186+
Attributes:
187+
188+
| Key | Description | Required | Type | Default | Valid values |
189+
|-------|--------------------------------------------------------------|----------|--------|---------|--------------|
190+
| value | The text that is rendered. Markdown formatting is supported. | Required | String | - | - |
191+
192+
### Textarea
193+
194+
You can use a `textarea` element to add a multi-line text field to your form. Contributors can also attach files in `textarea` fields.
195+
196+
Attributes:
197+
198+
| Key | Description | Required | Type | Default | Valid values |
199+
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|--------|--------------|---------------------------|
200+
| label | A brief description of the expected user input, which is also displayed in the form. | Required | String | - | - |
201+
| description | A description of the text area to provide context or guidance, which is displayed in the form. | Optional | String | Empty String | - |
202+
| placeholder | A semi-opaque placeholder that renders in the text area when empty. | Optional | String | Empty String | - |
203+
| value | Text that is pre-filled in the text area. | Optional | String | - | - |
204+
| render | If a value is provided, submitted text will be formatted into a codeblock. When this key is provided, the text area will not expand for file attachments or Markdown editing. | Optional | String | - | Languages known to Gitea. |
205+
206+
Validations:
207+
208+
| Key | Description | Required | Type | Default | Valid values |
209+
|----------|------------------------------------------------------|----------|---------|---------|--------------|
210+
| required | Prevents form submission until element is completed. | Optional | Boolean | false | - |
211+
212+
### Input
213+
214+
You can use an `input` element to add a single-line text field to your form.
215+
216+
Attributes:
217+
218+
| Key | Description | Required | Type | Default | Valid values |
219+
|-------------|--------------------------------------------------------------------------------------------|----------|--------|--------------|--------------|
220+
| label | A brief description of the expected user input, which is also displayed in the form. | Required | String | - | - |
221+
| description | A description of the field to provide context or guidance, which is displayed in the form. | Optional | String | Empty String | - |
222+
| placeholder | A semi-transparent placeholder that renders in the field when empty. | Optional | String | Empty String | - |
223+
| value | Text that is pre-filled in the field. | Optional | String | - | - |
224+
225+
Validations:
226+
227+
| Key | Description | Required | Type | Default | Valid values |
228+
|-----------|--------------------------------------------------------------------------------------------------|----------|---------|---------|--------------------------------------------------------------------------|
229+
| required | Prevents form submission until element is completed. | Optional | Boolean | false | - |
230+
| is_number | Prevents form submission until element is filled with a number. | Optional | Boolean | false | - |
231+
| 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) |
232+
233+
### Dropdown
234+
235+
You can use a `dropdown` element to add a dropdown menu in your form.
236+
237+
Attributes:
238+
239+
| Key | Description | Required | Type | Default | Valid values |
240+
|-------------|-----------------------------------------------------------------------------------------------------|----------|--------------|--------------|--------------|
241+
| label | A brief description of the expected user input, which is displayed in the form. | Required | String | - | - |
242+
| description | A description of the dropdown to provide extra context or guidance, which is displayed in the form. | Optional | String | Empty String | - |
243+
| multiple | Determines if the user can select more than one option. | Optional | Boolean | false | - |
244+
| options | An array of options the user can choose from. Cannot be empty and all choices must be distinct. | Required | String array | - | - |
245+
246+
Validations:
247+
248+
| Key | Description | Required | Type | Default | Valid values |
249+
|----------|------------------------------------------------------|----------|---------|---------|--------------|
250+
| required | Prevents form submission until element is completed. | Optional | Boolean | false | - |
251+
252+
### Checkboxes
253+
254+
You can use the `checkboxes` element to add a set of checkboxes to your form.
255+
256+
Attributes:
257+
258+
| Key | Description | Required | Type | Default | Valid values |
259+
|-------------|-------------------------------------------------------------------------------------------------------|----------|--------|--------------|--------------|
260+
| label | A brief description of the expected user input, which is displayed in the form. | Required | String | - | - |
261+
| description | A description of the set of checkboxes, which is displayed in the form. Supports Markdown formatting. | Optional | String | Empty String | - |
262+
| options | An array of checkboxes that the user can select. For syntax, see below. | Required | Array | - | - |
263+
264+
For each value in the options array, you can set the following keys.
265+
266+
| Key | Description | Required | Type | Default | Options |
267+
|----------|------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|---------|---------|
268+
| 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 | - | - |
269+
| required | Prevents form submission until element is completed. | Optional | Boolean | false | - |
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
date: "2022-08-31T17:35:40+08:00"
3+
title: "Usage: Merge Message templates"
4+
slug: "merge-message-templates"
5+
weight: 15
6+
toc: false
7+
draft: false
8+
menu:
9+
sidebar:
10+
parent: "usage"
11+
name: "Merge Message templates"
12+
weight: 15
13+
identifier: "merge-message-templates"
14+
---
15+
16+
# Merge Message templates
17+
18+
**Table of Contents**
19+
20+
{{< toc >}}
21+
22+
## File names
23+
24+
Possible file names for PR default merge message templates:
25+
26+
- `.gitea/default_merge_message/MERGE_TEMPLATE.md`
27+
- `.gitea/default_merge_message/REBASE_TEMPLATE.md`
28+
- `.gitea/default_merge_message/REBASE-MERGE_TEMPLATE.md`
29+
- `.gitea/default_merge_message/SQUASH_TEMPLATE.md`
30+
- `.gitea/default_merge_message/MANUALLY-MERGED_TEMPLATE.md`
31+
- `.gitea/default_merge_message/REBASE-UPDATE-ONLY_TEMPLATE.md`
32+
33+
## Variables
34+
35+
You can use the following variables enclosed in `${}` inside these templates which follow [os.Expand](https://pkg.go.dev/os#Expand) syntax:
36+
37+
- BaseRepoOwnerName: Base repository owner name of this pull request
38+
- BaseRepoName: Base repository name of this pull request
39+
- BaseBranch: Base repository target branch name of this pull request
40+
- HeadRepoOwnerName: Head repository owner name of this pull request
41+
- HeadRepoName: Head repository name of this pull request
42+
- HeadBranch: Head repository branch name of this pull request
43+
- PullRequestTitle: Pull request's title
44+
- PullRequestDescription: Pull request's description
45+
- PullRequestPosterName: Pull request's poster name
46+
- PullRequestIndex: Pull request's index number
47+
- PullRequestReference: Pull request's reference char with index number. i.e. #1, !2
48+
- ClosingIssues: return a string contains all issues which will be closed by this pull request i.e. `close #1, close #2`

0 commit comments

Comments
 (0)