summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorsillyguodong <33891828+sillyguodong@users.noreply.github.com>2024-03-29 04:40:35 +0800
committerGitHub <noreply@github.com>2024-03-28 20:40:35 +0000
commit62b073e6f31645e446c7e8d6b5a506f61b47924e (patch)
tree9a82f10165ab8de01e1c6219e69762402a42c41d /modules
parent61036235966773a0af6b690b10b33ff8222df1d7 (diff)
downloadgitea-62b073e6f31645e446c7e8d6b5a506f61b47924e.tar.gz
gitea-62b073e6f31645e446c7e8d6b5a506f61b47924e.zip
Add API for `Variables` (#29520)
close #27801 --------- Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'modules')
-rw-r--r--modules/structs/variable.go37
-rw-r--r--modules/util/util.go9
-rw-r--r--modules/util/util_test.go5
3 files changed, 51 insertions, 0 deletions
diff --git a/modules/structs/variable.go b/modules/structs/variable.go
new file mode 100644
index 0000000000..cc846cf0ec
--- /dev/null
+++ b/modules/structs/variable.go
@@ -0,0 +1,37 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package structs
+
+// CreateVariableOption the option when creating variable
+// swagger:model
+type CreateVariableOption struct {
+ // Value of the variable to create
+ //
+ // required: true
+ Value string `json:"value" binding:"Required"`
+}
+
+// UpdateVariableOption the option when updating variable
+// swagger:model
+type UpdateVariableOption struct {
+ // New name for the variable. If the field is empty, the variable name won't be updated.
+ Name string `json:"name"`
+ // Value of the variable to update
+ //
+ // required: true
+ Value string `json:"value" binding:"Required"`
+}
+
+// ActionVariable return value of the query API
+// swagger:model
+type ActionVariable struct {
+ // the owner to which the variable belongs
+ OwnerID int64 `json:"owner_id"`
+ // the repository to which the variable belongs
+ RepoID int64 `json:"repo_id"`
+ // the name of the variable
+ Name string `json:"name"`
+ // the value of the variable
+ Data string `json:"data"`
+}
diff --git a/modules/util/util.go b/modules/util/util.go
index c94fb91047..b6e730eb54 100644
--- a/modules/util/util.go
+++ b/modules/util/util.go
@@ -221,3 +221,12 @@ func IfZero[T comparable](v, def T) T {
}
return v
}
+
+func ReserveLineBreakForTextarea(input string) string {
+ // Since the content is from a form which is a textarea, the line endings are \r\n.
+ // It's a standard behavior of HTML.
+ // But we want to store them as \n like what GitHub does.
+ // And users are unlikely to really need to keep the \r.
+ // Other than this, we should respect the original content, even leading or trailing spaces.
+ return strings.ReplaceAll(input, "\r\n", "\n")
+}
diff --git a/modules/util/util_test.go b/modules/util/util_test.go
index 819e12ee91..5c5b13d04b 100644
--- a/modules/util/util_test.go
+++ b/modules/util/util_test.go
@@ -235,3 +235,8 @@ func TestToPointer(t *testing.T) {
val123 := 123
assert.False(t, &val123 == ToPointer(val123))
}
+
+func TestReserveLineBreakForTextarea(t *testing.T) {
+ assert.Equal(t, ReserveLineBreakForTextarea("test\r\ndata"), "test\ndata")
+ assert.Equal(t, ReserveLineBreakForTextarea("test\r\ndata\r\n"), "test\ndata\n")
+}