computeRequiredCheckStatus determines the aggregate check status considering only the checks whose name/context appears in requiredChecks. If a required check hasn't reported yet (not present in contexts), it is treated as pending.
(contexts []checkContextNode, requiredChecks map[string]bool)
| 784 | // If a required check hasn't reported yet (not present in contexts), it is |
| 785 | // treated as pending. |
| 786 | func computeRequiredCheckStatus(contexts []checkContextNode, requiredChecks map[string]bool) github.CheckStatus { |
| 787 | // Track which required checks we've seen |
| 788 | seen := make(map[string]bool, len(requiredChecks)) |
| 789 | hasPending := false |
| 790 | hasFail := false |
| 791 | |
| 792 | for _, ctx := range contexts { |
| 793 | name := contextName(ctx) |
| 794 | if !requiredChecks[name] { |
| 795 | continue |
| 796 | } |
| 797 | seen[name] = true |
| 798 | |
| 799 | switch ctx.TypeName { |
| 800 | case "CheckRun": |
| 801 | switch ctx.Status { |
| 802 | case "COMPLETED": |
| 803 | if ctx.Conclusion == nil { |
| 804 | hasFail = true |
| 805 | } else { |
| 806 | switch *ctx.Conclusion { |
| 807 | case "SUCCESS", "NEUTRAL", "SKIPPED": |
| 808 | // pass |
| 809 | default: |
| 810 | hasFail = true |
| 811 | } |
| 812 | } |
| 813 | default: |
| 814 | // IN_PROGRESS, QUEUED, REQUESTED, WAITING, PENDING |
| 815 | hasPending = true |
| 816 | } |
| 817 | case "StatusContext": |
| 818 | switch ctx.State { |
| 819 | case "SUCCESS": |
| 820 | // pass |
| 821 | case "PENDING", "EXPECTED": |
| 822 | hasPending = true |
| 823 | default: |
| 824 | hasFail = true |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | // Any required check that hasn't reported yet is pending |
| 830 | for name := range requiredChecks { |
| 831 | if !seen[name] { |
| 832 | hasPending = true |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | if hasFail { |
| 837 | return github.CheckStatusFail |
| 838 | } |
| 839 | if hasPending { |
| 840 | return github.CheckStatusPending |
| 841 | } |
| 842 | return github.CheckStatusPass |
| 843 | } |