mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-31 12:00:01 +02:00
Add spent time to referenced issue in commit message (#12220)
This commit is contained in:
parent
4c557eff5d
commit
e710a34981
4 changed files with 184 additions and 40 deletions
|
@ -37,6 +37,8 @@ var (
|
|||
crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+[#!][0-9]+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
|
||||
// spaceTrimmedPattern let's us find the trailing space
|
||||
spaceTrimmedPattern = regexp.MustCompile(`(?:.*[0-9a-zA-Z-_])\s`)
|
||||
// timeLogPattern matches string for time tracking
|
||||
timeLogPattern = regexp.MustCompile(`(?:\s|^|\(|\[)(@([0-9]+([\.,][0-9]+)?(w|d|m|h))+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`)
|
||||
|
||||
issueCloseKeywordsPat, issueReopenKeywordsPat *regexp.Regexp
|
||||
issueKeywordsOnce sync.Once
|
||||
|
@ -62,10 +64,11 @@ const (
|
|||
|
||||
// IssueReference contains an unverified cross-reference to a local issue or pull request
|
||||
type IssueReference struct {
|
||||
Index int64
|
||||
Owner string
|
||||
Name string
|
||||
Action XRefAction
|
||||
Index int64
|
||||
Owner string
|
||||
Name string
|
||||
Action XRefAction
|
||||
TimeLog string
|
||||
}
|
||||
|
||||
// RenderizableReference contains an unverified cross-reference to with rendering information
|
||||
|
@ -91,16 +94,18 @@ type rawReference struct {
|
|||
issue string
|
||||
refLocation *RefSpan
|
||||
actionLocation *RefSpan
|
||||
timeLog string
|
||||
}
|
||||
|
||||
func rawToIssueReferenceList(reflist []*rawReference) []IssueReference {
|
||||
refarr := make([]IssueReference, len(reflist))
|
||||
for i, r := range reflist {
|
||||
refarr[i] = IssueReference{
|
||||
Index: r.index,
|
||||
Owner: r.owner,
|
||||
Name: r.name,
|
||||
Action: r.action,
|
||||
Index: r.index,
|
||||
Owner: r.owner,
|
||||
Name: r.name,
|
||||
Action: r.action,
|
||||
TimeLog: r.timeLog,
|
||||
}
|
||||
}
|
||||
return refarr
|
||||
|
@ -386,6 +391,38 @@ func findAllIssueReferencesBytes(content []byte, links []string) []*rawReference
|
|||
}
|
||||
}
|
||||
|
||||
if len(ret) == 0 {
|
||||
return ret
|
||||
}
|
||||
|
||||
pos = 0
|
||||
|
||||
for {
|
||||
match := timeLogPattern.FindSubmatchIndex(content[pos:])
|
||||
if match == nil {
|
||||
break
|
||||
}
|
||||
|
||||
timeLogEntry := string(content[match[2]+pos+1 : match[3]+pos])
|
||||
|
||||
var f *rawReference
|
||||
for _, ref := range ret {
|
||||
if ref.refLocation != nil && ref.refLocation.End < match[2]+pos && (f == nil || f.refLocation.End < ref.refLocation.End) {
|
||||
f = ref
|
||||
}
|
||||
}
|
||||
|
||||
pos = match[1] + pos
|
||||
|
||||
if f == nil {
|
||||
f = ret[0]
|
||||
}
|
||||
|
||||
if len(f.timeLog) == 0 {
|
||||
f.timeLog = timeLogEntry
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue