master
 1import { define, PullRequest } from '#src'
 2
 3export default define({
 4  url: import.meta.url,
 5  badges: ['this-is-fine'] as const,
 6  present(data, grant) {
 7    const pulls: PullRequest[] = []
 8
 9    for (const pull of data.pulls) {
10      if (!pull.merged) continue
11      if (pull.mergedBy?.login != data.user.login) continue
12
13      const commit = pull.lastCommit.nodes?.[0]?.commit
14      if (!commit) continue
15
16      const checkRuns = commit.checkSuites?.nodes?.flatMap(
17        (x) => x.lastCheckRun?.nodes,
18      )
19      if (!checkRuns || checkRuns?.length == 0) continue
20      const successCount = checkRuns.filter(
21        (x) => x?.conclusion == 'SUCCESS',
22      ).length
23      const failureCount = checkRuns.filter(
24        (x) => x?.conclusion == 'FAILURE',
25      ).length
26
27      if (successCount <= failureCount) {
28        pulls.push(pull)
29      }
30    }
31
32    if (pulls.length > 0) {
33      grant(
34        'this-is-fine',
35        'I merged a PR with failing checks',
36      ).evidencePRsWithTitle(...pulls)
37    }
38  },
39})