forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor parseSignatureFromCommitLine (go-gitea#29054)
Replace go-gitea#28849. Thanks to @yp05327 for the looking into the problem. Fix go-gitea#28840 The old behavior of newSignatureFromCommitline is not right. The new parseSignatureFromCommitLine: 1. never fails 2. only accept one format (if there is any other, it could be easily added) And add some tests.
- Loading branch information
1 parent
da2f037
commit a24e1da
Showing
8 changed files
with
104 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package git | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParseSignatureFromCommitLine(t *testing.T) { | ||
tests := []struct { | ||
line string | ||
want *Signature | ||
}{ | ||
{ | ||
line: "a b <c@d.com> 12345 +0100", | ||
want: &Signature{ | ||
Name: "a b", | ||
Email: "c@d.com", | ||
When: time.Unix(12345, 0).In(time.FixedZone("", 3600)), | ||
}, | ||
}, | ||
{ | ||
line: "bad line", | ||
want: &Signature{Name: "bad line"}, | ||
}, | ||
{ | ||
line: "bad < line", | ||
want: &Signature{Name: "bad < line"}, | ||
}, | ||
{ | ||
line: "bad > line", | ||
want: &Signature{Name: "bad > line"}, | ||
}, | ||
{ | ||
line: "bad-line <name@example.com>", | ||
want: &Signature{Name: "bad-line <name@example.com>"}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
got := parseSignatureFromCommitLine(test.line) | ||
assert.EqualValues(t, test.want, got) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters