Skip to content

Commit f19da14

Browse files
authored
enhancement: add signoff option in commit form (go-gitea#14516)
Signed-off-by: a1012112796 <[email protected]>
1 parent f761c82 commit f19da14

File tree

11 files changed

+51
-8
lines changed

11 files changed

+51
-8
lines changed

modules/forms/repo_form.go

+3
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ type EditRepoFileForm struct {
698698
CommitChoice string `binding:"Required;MaxSize(50)"`
699699
NewBranchName string `binding:"GitRefName;MaxSize(100)"`
700700
LastCommit string
701+
Signoff bool
701702
}
702703

703704
// Validate validates the fields
@@ -733,6 +734,7 @@ type UploadRepoFileForm struct {
733734
CommitChoice string `binding:"Required;MaxSize(50)"`
734735
NewBranchName string `binding:"GitRefName;MaxSize(100)"`
735736
Files []string
737+
Signoff bool
736738
}
737739

738740
// Validate validates the fields
@@ -766,6 +768,7 @@ type DeleteRepoFileForm struct {
766768
CommitChoice string `binding:"Required;MaxSize(50)"`
767769
NewBranchName string `binding:"GitRefName;MaxSize(100)"`
768770
LastCommit string
771+
Signoff bool
769772
}
770773

771774
// Validate validates the fields

modules/repofiles/delete.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type DeleteRepoFileOptions struct {
2525
Author *IdentityOptions
2626
Committer *IdentityOptions
2727
Dates *CommitDateOptions
28+
Signoff bool
2829
}
2930

3031
// DeleteRepoFile deletes a file in the given repository
@@ -199,9 +200,9 @@ func DeleteRepoFile(repo *models.Repository, doer *models.User, opts *DeleteRepo
199200
// Now commit the tree
200201
var commitHash string
201202
if opts.Dates != nil {
202-
commitHash, err = t.CommitTreeWithDate(author, committer, treeHash, message, opts.Dates.Author, opts.Dates.Committer)
203+
commitHash, err = t.CommitTreeWithDate(author, committer, treeHash, message, opts.Signoff, opts.Dates.Author, opts.Dates.Committer)
203204
} else {
204-
commitHash, err = t.CommitTree(author, committer, treeHash, message)
205+
commitHash, err = t.CommitTree(author, committer, treeHash, message, opts.Signoff)
205206
}
206207
if err != nil {
207208
return nil, err

modules/repofiles/temp_repo.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ func (t *TemporaryUploadRepository) GetLastCommitByRef(ref string) (string, erro
185185
}
186186

187187
// CommitTree creates a commit from a given tree for the user with provided message
188-
func (t *TemporaryUploadRepository) CommitTree(author, committer *models.User, treeHash string, message string) (string, error) {
189-
return t.CommitTreeWithDate(author, committer, treeHash, message, time.Now(), time.Now())
188+
func (t *TemporaryUploadRepository) CommitTree(author, committer *models.User, treeHash string, message string, signoff bool) (string, error) {
189+
return t.CommitTreeWithDate(author, committer, treeHash, message, signoff, time.Now(), time.Now())
190190
}
191191

192192
// CommitTreeWithDate creates a commit from a given tree for the user with provided message
193-
func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models.User, treeHash string, message string, authorDate, committerDate time.Time) (string, error) {
193+
func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models.User, treeHash string, message string, signoff bool, authorDate, committerDate time.Time) (string, error) {
194194
authorSig := author.NewGitSig()
195195
committerSig := committer.NewGitSig()
196196

@@ -236,6 +236,13 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models
236236
}
237237
}
238238

239+
if signoff {
240+
// Signed-off-by
241+
_, _ = messageBytes.WriteString("\n")
242+
_, _ = messageBytes.WriteString("Signed-off-by: ")
243+
_, _ = messageBytes.WriteString(committerSig.String())
244+
}
245+
239246
env = append(env,
240247
"GIT_COMMITTER_NAME="+committerSig.Name,
241248
"GIT_COMMITTER_EMAIL="+committerSig.Email,

modules/repofiles/update.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type UpdateRepoFileOptions struct {
5151
Author *IdentityOptions
5252
Committer *IdentityOptions
5353
Dates *CommitDateOptions
54+
Signoff bool
5455
}
5556

5657
func detectEncodingAndBOM(entry *git.TreeEntry, repo *models.Repository) (string, bool) {
@@ -417,9 +418,9 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up
417418
// Now commit the tree
418419
var commitHash string
419420
if opts.Dates != nil {
420-
commitHash, err = t.CommitTreeWithDate(author, committer, treeHash, message, opts.Dates.Author, opts.Dates.Committer)
421+
commitHash, err = t.CommitTreeWithDate(author, committer, treeHash, message, opts.Signoff, opts.Dates.Author, opts.Dates.Committer)
421422
} else {
422-
commitHash, err = t.CommitTree(author, committer, treeHash, message)
423+
commitHash, err = t.CommitTree(author, committer, treeHash, message, opts.Signoff)
423424
}
424425
if err != nil {
425426
return nil, err

modules/repofiles/upload.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type UploadRepoFileOptions struct {
2424
TreePath string
2525
Message string
2626
Files []string // In UUID format.
27+
Signoff bool
2728
}
2829

2930
type uploadInfo struct {
@@ -143,7 +144,7 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
143144
committer := doer
144145

145146
// Now commit the tree
146-
commitHash, err := t.CommitTree(author, committer, treeHash, opts.Message)
147+
commitHash, err := t.CommitTree(author, committer, treeHash, opts.Message, opts.Signoff)
147148
if err != nil {
148149
return err
149150
}

modules/structs/repo_file.go

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type FileOptions struct {
1717
Author Identity `json:"author"`
1818
Committer Identity `json:"committer"`
1919
Dates CommitDateOptions `json:"dates"`
20+
// Add a Signed-off-by trailer by the committer at the end of the commit log message.
21+
Signoff bool `json:"signoff"`
2022
}
2123

2224
// CreateFileOptions options for creating files

options/locale/locale_en-US.ini

+1
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ editor.add = Add '%s'
874874
editor.update = Update '%s'
875875
editor.delete = Delete '%s'
876876
editor.commit_message_desc = Add an optional extended description…
877+
editor.signoff_desc = Add a Signed-off-by trailer by the committer at the end of the commit log message.
877878
editor.commit_directly_to_this_branch = Commit directly to the <strong class="branch-name">%s</strong> branch.
878879
editor.create_new_branch = Create a <strong>new branch</strong> for this commit and start a pull request.
879880
editor.create_new_branch_np = Create a <strong>new branch</strong> for this commit.

routers/api/v1/repo/file.go

+3
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func CreateFile(ctx *context.APIContext) {
235235
Author: apiOpts.Dates.Author,
236236
Committer: apiOpts.Dates.Committer,
237237
},
238+
Signoff: apiOpts.Signoff,
238239
}
239240
if opts.Dates.Author.IsZero() {
240241
opts.Dates.Author = time.Now()
@@ -323,6 +324,7 @@ func UpdateFile(ctx *context.APIContext) {
323324
Author: apiOpts.Dates.Author,
324325
Committer: apiOpts.Dates.Committer,
325326
},
327+
Signoff: apiOpts.Signoff,
326328
}
327329
if opts.Dates.Author.IsZero() {
328330
opts.Dates.Author = time.Now()
@@ -449,6 +451,7 @@ func DeleteFile(ctx *context.APIContext) {
449451
Author: apiOpts.Dates.Author,
450452
Committer: apiOpts.Dates.Committer,
451453
},
454+
Signoff: apiOpts.Signoff,
452455
}
453456
if opts.Dates.Author.IsZero() {
454457
opts.Dates.Author = time.Now()

routers/repo/editor.go

+3
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
240240
Message: message,
241241
Content: strings.ReplaceAll(form.Content, "\r", ""),
242242
IsNewFile: isNewFile,
243+
Signoff: form.Signoff,
243244
}); err != nil {
244245
// This is where we handle all the errors thrown by repofiles.CreateOrUpdateRepoFile
245246
if git.IsErrNotExist(err) {
@@ -442,6 +443,7 @@ func DeleteFilePost(ctx *context.Context) {
442443
NewBranch: branchName,
443444
TreePath: ctx.Repo.TreePath,
444445
Message: message,
446+
Signoff: form.Signoff,
445447
}); err != nil {
446448
// This is where we handle all the errors thrown by repofiles.DeleteRepoFile
447449
if git.IsErrNotExist(err) || models.IsErrRepoFileDoesNotExist(err) {
@@ -650,6 +652,7 @@ func UploadFilePost(ctx *context.Context) {
650652
TreePath: form.TreePath,
651653
Message: message,
652654
Files: form.Files,
655+
Signoff: form.Signoff,
653656
}); err != nil {
654657
if models.IsErrLFSFileLocked(err) {
655658
ctx.Data["Err_TreePath"] = true

templates/repo/editor/commit_form.tmpl

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
<div class="field">
1515
<textarea name="commit_message" placeholder="{{.i18n.Tr "repo.editor.commit_message_desc"}}" rows="5">{{.commit_message}}</textarea>
1616
</div>
17+
<div class="inline field">
18+
<div class="ui checkbox">
19+
<input name="signoff" type="checkbox" tabindex="0" class="hidden">
20+
<label>{{.i18n.Tr "repo.editor.signoff_desc"}}</label>
21+
</div>
22+
</div>
1723
<div class="quick-pull-choice js-quick-pull-choice">
1824
<div class="field">
1925
<div class="ui radio checkbox {{if not .CanCommitToBranch.CanCommitToBranch}}disabled{{end}}">

templates/swagger/v1_json.tmpl

+15
Original file line numberDiff line numberDiff line change
@@ -12023,6 +12023,11 @@
1202312023
"description": "new_branch (optional) will make a new branch from `branch` before creating the file",
1202412024
"type": "string",
1202512025
"x-go-name": "NewBranchName"
12026+
},
12027+
"signoff": {
12028+
"description": "Add a Signed-off-by trailer by the committer at the end of the commit log message.",
12029+
"type": "boolean",
12030+
"x-go-name": "Signoff"
1202612031
}
1202712032
},
1202812033
"x-go-package": "code.gitea.io/gitea/modules/structs"
@@ -12731,6 +12736,11 @@
1273112736
"description": "sha is the SHA for the file that already exists",
1273212737
"type": "string",
1273312738
"x-go-name": "SHA"
12739+
},
12740+
"signoff": {
12741+
"description": "Add a Signed-off-by trailer by the committer at the end of the commit log message.",
12742+
"type": "boolean",
12743+
"x-go-name": "Signoff"
1273412744
}
1273512745
},
1273612746
"x-go-package": "code.gitea.io/gitea/modules/structs"
@@ -15762,6 +15772,11 @@
1576215772
"description": "sha is the SHA for the file that already exists",
1576315773
"type": "string",
1576415774
"x-go-name": "SHA"
15775+
},
15776+
"signoff": {
15777+
"description": "Add a Signed-off-by trailer by the committer at the end of the commit log message.",
15778+
"type": "boolean",
15779+
"x-go-name": "Signoff"
1576515780
}
1576615781
},
1576715782
"x-go-package": "code.gitea.io/gitea/modules/structs"

0 commit comments

Comments
 (0)