-
-
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 <[email protected]>
- Loading branch information
Showing
8 changed files
with
156 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,53 @@ | ||
package labeler | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/google/go-github/v50/github" | ||
) | ||
|
||
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) { | ||
if matcher.LastModified == nil { | ||
return false, fmt.Errorf("no last modified conditions are set in config") | ||
} | ||
// Determine the last modification time of the issue or PR | ||
var lastModifiedAt *github.Timestamp | ||
if target.ghIssue != nil { | ||
lastModifiedAt = target.ghIssue.UpdatedAt | ||
} else if target.ghPR != nil { | ||
lastModifiedAt = target.ghPR.UpdatedAt | ||
} else { | ||
return false, fmt.Errorf("no issue or PR found in target") | ||
} | ||
duration := time.Since(lastModifiedAt.Time) | ||
|
||
if matcher.LastModified.AtMost != "" { | ||
maxDuration, err := parseExtendedDuration(matcher.LastModified.AtMost) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to parse `last-modified.at-most` parameter in configuration: %v", err) | ||
} | ||
return duration <= maxDuration, nil | ||
} | ||
|
||
if matcher.LastModified.AtLeast != "" { | ||
minDuration, err := parseExtendedDuration(matcher.LastModified.AtLeast) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to parse `last-modified.at-least` parameter in configuration: %v", err) | ||
} | ||
return duration >= minDuration, nil | ||
} | ||
|
||
return false, fmt.Errorf("no last modified conditions are set in config") | ||
|
||
}, | ||
} | ||
} |
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,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.