-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Galo Navarro <anglorvaroa@gmail.com>
- Loading branch information
Showing
7 changed files
with
110 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package labeler | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func LastModifiedCondition(l *Labeler) Condition { | ||
return Condition{ | ||
GetName: func() string { | ||
return "Last modification of issue/PR" | ||
}, | ||
CanEvaluate: func(target *Target) bool { | ||
return target.ghIssue != nil || target.ghPR != nil | ||
}, | ||
Evaluate: func(target *Target, matcher LabelMatcher) (bool, error) { | ||
// Parse the age from the configuration | ||
threshold, err := parseExtendedDuration(matcher.LastModified) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to parse last-modified parameter in configuration: %v", err) | ||
} | ||
|
||
// Determine the last modification time of the issue or PR | ||
var lastModified time.Time | ||
if target.ghIssue != nil { | ||
lastModified = target.ghIssue.UpdatedAt.Time | ||
} else if target.ghPR != nil { | ||
lastModified = target.ghPR.UpdatedAt.Time | ||
} | ||
|
||
return time.Since(lastModified) > threshold, nil | ||
}, | ||
} | ||
} |
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,30 @@ | ||
package labeler | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func parseExtendedDuration(s string) (time.Duration, error) { | ||
multiplier := time.Hour * 24 // default to days | ||
|
||
if strings.HasSuffix(s, "w") { | ||
multiplier = time.Hour * 24 * 7 // weeks | ||
s = strings.TrimSuffix(s, "w") | ||
} else if strings.HasSuffix(s, "y") { | ||
multiplier = time.Hour * 24 * 365 // years | ||
s = strings.TrimSuffix(s, "y") | ||
} else if strings.HasSuffix(s, "d") { | ||
s = strings.TrimSuffix(s, "d") // days | ||
} else { | ||
return time.ParseDuration(s) // default to time.ParseDuration for hours, minutes, seconds | ||
} | ||
|
||
value, err := strconv.Atoi(s) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return time.Duration(value) * multiplier, nil | ||
} |
File renamed without changes.