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

Added Description Field for Secrets and Variables #33526

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

LaoQi
Copy link
Contributor

@LaoQi LaoQi commented Feb 6, 2025

Fixes #33484

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 6, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 6, 2025
@github-actions github-actions bot added modifies/translation modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/migrations labels Feb 6, 2025
@lunny lunny added this to the 1.24.0 milestone Feb 6, 2025
@@ -77,6 +81,15 @@
placeholder="{{ctx.Locale.Tr "secrets.creation.name_placeholder"}}"
>
</div>
<div class="field">
<label for="dialog-variable-description">{{ctx.Locale.Tr "secrets.creation.description"}}</label>
<input
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably also add max length to this field

@LaoQi
Copy link
Contributor Author

LaoQi commented Feb 8, 2025

Is there a standardized length limit for these texts in the project? Maybe we should define constants for these. For now, I've capped them all at 4096 characters

@lunny
Copy link
Member

lunny commented Feb 9, 2025

LGTM except #33526 (comment)

Screenshots are necessary.

@LaoQi
Copy link
Contributor Author

LaoQi commented Feb 9, 2025

I noticed that the data field also doesn't have a length restriction. I'll add a length constraint to it as well. For this field, I think a limit of 65536 would be appropriate, although we can truncate the display when showing it.
The input data is generally UTF-8 encoded, so I will use UTF-8 character counting.
eg:

const (
	VariableDataMaxLength        = 65536
	VariableDescriptionMaxLength = 4096
)
if utf8.RuneCountInString(data) > VariableDataMaxLength {
	data = string([]rune(data)[:VariableDataMaxLength])
}

if utf8.RuneCountInString(description) > VariableDescriptionMaxLength {
	description = string([]rune(description)[:VariableDescriptionMaxLength])
}

Any other suggestions?

@LaoQi
Copy link
Contributor Author

LaoQi commented Feb 9, 2025

034215
034046
034021

@lunny
Copy link
Member

lunny commented Feb 9, 2025

I think the description should be moved under value because it's optional. And it's better to have 2 rows at least.

@LaoQi
Copy link
Contributor Author

LaoQi commented Feb 10, 2025

I think the description should be moved under value because it's optional. And it's better to have 2 rows at least.

Does it refer only to the form, or does it also include the list? Perhaps it would be better to place the description in the list above.

@LaoQi
Copy link
Contributor Author

LaoQi commented Feb 10, 2025

225010

if ownerID != 0 && repoID != 0 {
// It's trying to create a variable that belongs to a repository, but OwnerID has been set accidentally.
// Remove OwnerID to avoid confusion; it's not worth returning an error here.
ownerID = 0
}

if utf8.RuneCountInString(data) > VariableDataMaxLength {
Copy link
Member

@lunny lunny Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return failure here because data should not be truncated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you are right

data = string([]rune(data)[:VariableDataMaxLength])
}

if utf8.RuneCountInString(description) > VariableDescriptionMaxLength {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use util.SplitStringAtByteN directly.

@@ -67,15 +74,25 @@ func InsertEncryptedSecret(ctx context.Context, ownerID, repoID int64, name, dat
return nil, fmt.Errorf("%w: ownerID and repoID cannot be both zero, global secrets are not supported", util.ErrInvalidArgument)
}

if len(data) > SecretDataMaxLength {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return failure here because data should not be truncated.

data = data[:SecretDataMaxLength]
}

if utf8.RuneCountInString(description) > SecretDescriptionMaxLength {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use util.SplitStringAtByteN directly.

@@ -62,7 +65,6 @@
<input autofocus required
id="secret-name"
name="name"
value="{{.name}}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this property actually needed? I don't see it used anywhere, and the template isn't setting its value.

@@ -72,7 +77,6 @@
<input autofocus required
name="name"
id="dialog-variable-name"
value="{{.name}}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above

@@ -24,6 +25,9 @@
<div class="flex-item-title">
{{.Name}}
</div>
<div class="flex-item-body">
{{if .Description}} {{.Description}} {{else}} - {{end}}
Copy link
Member

@silverwind silverwind Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{if .Description}} {{.Description}} {{else}} - {{end}}
{{if .Description}}{{.Description}}{{else}}-{{end}}

Whitespace inside HTML tags is irrelevant in flexbox. If you really need it for spacing, use &nbsp; or add margin classes.

@@ -22,6 +22,9 @@
<div class="flex-item-title">
{{.Name}}
</div>
<div class="flex-item-body">
{{if .Description}} {{.Description}} {{else}} - {{end}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{if .Description}} {{.Description}} {{else}} - {{end}}
{{if .Description}}{{.Description}}{{else}}-{{end}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code modifies/migrations modifies/templates This PR modifies the template files modifies/translation size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Description Field for Secrets and Variables
5 participants