@@ -4,12 +4,12 @@ package review |
| 4 | 4 | |
| 5 | 5 | import ( |
| 6 | 6 | "context" |
| 7 | | - "path/filepath" |
| 8 | 7 | |
| 9 | 8 | "github.com/jackc/pgx/v5/pgtype" |
| 10 | 9 | "github.com/jackc/pgx/v5/pgxpool" |
| 11 | 10 | |
| 12 | 11 | pullsdb "github.com/tenseleyFlow/shithub/internal/pulls/sqlc" |
| 12 | + "github.com/tenseleyFlow/shithub/internal/repos/protection" |
| 13 | 13 | reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc" |
| 14 | 14 | ) |
| 15 | 15 | |
@@ -58,7 +58,7 @@ func Evaluate(ctx context.Context, pool *pgxpool.Pool, in GateInputs, prAuthorUs |
| 58 | 58 | if err != nil { |
| 59 | 59 | return GateResult{}, err |
| 60 | 60 | } |
| 61 | | - rule, hasRule := matchRule(rules, in.BaseRef) |
| 61 | + rule, hasRule := protection.MatchLongestRule(rules, in.BaseRef) |
| 62 | 62 | |
| 63 | 63 | // If there's no rule, approve count + request_changes still gate |
| 64 | 64 | // the merge per spec ("no unresolved request_changes reviews"). |
@@ -97,25 +97,7 @@ func loadProtectionRules(ctx context.Context, pool *pgxpool.Pool, repoID int64) |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // matchRule duplicates the longest-pattern-wins algorithm from |
| 100 | | -// internal/repos/protection so this package doesn't pull that import |
| 101 | | -// graph. Same behaviour: longest pattern (alphabetical tiebreaker) |
| 102 | | -// wins, no rule means no match. |
| 103 | | -func matchRule(rules []reposdb.BranchProtectionRule, branch string) (reposdb.BranchProtectionRule, bool) { |
| 104 | | - var best reposdb.BranchProtectionRule |
| 105 | | - bestLen := -1 |
| 106 | | - for _, r := range rules { |
| 107 | | - ok, _ := filepath.Match(r.Pattern, branch) |
| 108 | | - if !ok { |
| 109 | | - continue |
| 110 | | - } |
| 111 | | - if len(r.Pattern) > bestLen || |
| 112 | | - (len(r.Pattern) == bestLen && r.Pattern < best.Pattern) { |
| 113 | | - best = r |
| 114 | | - bestLen = len(r.Pattern) |
| 115 | | - } |
| 116 | | - } |
| 117 | | - return best, bestLen >= 0 |
| 118 | | -} |
| 100 | +// (matchRule extracted to protection.MatchLongestRule — see audit fix.) |
| 119 | 101 | |
| 120 | 102 | // latestPerAuthor reduces reviews to a per-author "winning" state. |
| 121 | 103 | // approve and request_changes update the author's tally; comment-state |