Skip to content

Commit 1a305c8

Browse files
committed
chore: Add dependabot and toktok-releaser to trusted authors.
For bots, we need 2 human approvers with write access to the repo. Once 2 humans approved, we trust the bots enough to automerge.
1 parent 24f8f00 commit 1a305c8

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/GitHub/Tools/AutoMerge.hs

+25-14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module GitHub.Tools.AutoMerge
66
, trustedAuthors
77
) where
88

9+
import Control.Monad (unless)
910
import qualified Data.ByteString.Char8 as BS8
1011
import Data.Text (Text)
1112
import qualified Data.Text as Text
@@ -26,11 +27,12 @@ trustedAuthors :: [Text]
2627
trustedAuthors =
2728
[ "Green-Sky"
2829
, "JFreegman"
29-
, "TokTok"
30+
, "dependabot[bot]"
3031
, "iphydf"
3132
, "nurupo"
3233
, "robinlinden"
3334
, "sudden6"
35+
, "toktok-releaser"
3436
, "zugz"
3537
]
3638

@@ -68,9 +70,13 @@ autoMerge token ownerName PullRequestInfo{prRepoName, prUser, prBranch, prOrigin
6870
setCurrentDirectory workDir
6971

7072

71-
mergeable :: PullRequestInfo -> Bool
72-
mergeable PullRequestInfo{prState, prTrustworthy, prUser} =
73-
prState == "clean" && (prTrustworthy || prUser `elem` trustedAuthors)
73+
clean :: PullRequestInfo -> Bool
74+
clean PullRequestInfo{prState} = prState == "clean"
75+
76+
77+
trustworthy :: PullRequestInfo -> Bool
78+
trustworthy PullRequestInfo{prTrustworthy, prUser} =
79+
prTrustworthy || prUser `elem` trustedAuthors
7480

7581

7682
autoMergePullRequest
@@ -81,16 +87,21 @@ autoMergePullRequest
8187
autoMergePullRequest token ownerName repoName = do
8288
let auth = Just . GitHub.OAuth . BS8.pack $ token
8389
mgr <- newManager tlsManagerSettings
84-
pulls <- (V.toList <$>
85-
request auth mgr (GitHub.pullRequestsForR ownerName repoName GitHub.stateOpen GitHub.FetchAll))
86-
>>= fmap (map $ makePullRequestInfo repoName) . getPrInfos auth mgr ownerName repoName
87-
putStrLn $ "found " <> show (length pulls) <> " pulls"
90+
pulls <- request auth mgr (GitHub.pullRequestsForR ownerName repoName GitHub.stateOpen GitHub.FetchAll)
91+
>>= (fmap (map $ makePullRequestInfo repoName) . getPrInfos auth mgr ownerName repoName) . V.toList
92+
putStrLn $ "found " <> show (length pulls) <> " pulls in " <> Text.unpack (GitHub.untagName repoName)
93+
94+
let cleanPulls = filter clean pulls
95+
putStrLn $ "out of these, " <> show (length cleanPulls) <> " are clean pulls"
8896

89-
let mergeablePulls = filter mergeable pulls
90-
putStrLn $ "selected " <> show (length mergeablePulls) <> " mergeable pulls:"
91-
mapM_ print mergeablePulls
97+
let trustworthyPulls = filter trustworthy cleanPulls
98+
if null trustworthyPulls
99+
then putStrLn "no clean, trustworthy pulls found"
100+
else do
101+
putStrLn $ "selected " <> show (length trustworthyPulls) <> " clean, trustworthy pulls:"
102+
mapM_ print trustworthyPulls
92103

93-
mapM_ (autoMerge token ownerName) mergeablePulls
104+
mapM_ (autoMerge token ownerName) trustworthyPulls
94105

95106

96107
autoMergeAll
@@ -100,5 +111,5 @@ autoMergeAll
100111
-> IO ()
101112
autoMergeAll orgName ownerName token = do
102113
let auth = Just . GitHub.OAuth . BS8.pack $ token
103-
pulls <- filter mergeable . concat <$> getPullInfos orgName ownerName auth
104-
mapM_ (autoMerge token ownerName) pulls
114+
trustworthyPulls <- filter (\p -> clean p && trustworthy p) . concat <$> getPullInfos orgName ownerName auth
115+
mapM_ (autoMerge token ownerName) trustworthyPulls

0 commit comments

Comments
 (0)