Bitbucket Required Builds
MediumHash Map · Atlassian
A Bitbucket repository only allows a commit to merge when its required builds have passed. You are given:
commits: rows[commit_id, repo].build_events: rows[commit_id, build_key, state, timestamp], wherestateis one of"SUCCESSFUL","FAILED","STOPPED"or"INPROGRESS". Events may arrive out of order.required: a dictionary mapping a repo name to the list of build keys that must pass. A repo missing fromrequiredhas no required builds.
For each (commit_id, build_key) pair, only the latest event counts: the one with the largest timestamp, and if timestamps are equal, the one that appears later in build_events. Builds that are not required for the commit's repo are ignored.
Classify each commit using its required builds:
"BLOCKED"if any required build's latest state is"FAILED"or"STOPPED";- otherwise
"MERGEABLE"if every required build's latest state is"SUCCESSFUL"(this includes a repo with no required builds); - otherwise
"PENDING"(some required build is still"INPROGRESS"or has not reported yet).
Return [commit_id, status] for each commit, in the order of commits.
Example 1
- Input:
- commits = [["a1", "web"], ["b2", "web"], ["c3", "api"]], build_events = [["a1", "unit", "FAILED", 10], ["a1", "unit", "SUCCESSFUL", 20], ["a1", "lint", "SUCCESSFUL", 15], ["b2", "unit", "SUCCESSFUL", 12], ["c3", "unit", "FAILED", 30]], required = {"web": ["unit", "lint"], "api": ["unit"]}
- Output:
- [["a1", "MERGEABLE"], ["b2", "PENDING"], ["c3", "BLOCKED"]]
- Explanation
a1's unit build failed at time 10 but succeeded at 20, and lint succeeded, so it is mergeable.b2has no lint result yet, so it is pending.c3's only required build failed, so it is blocked.
Example 2
- Input:
- commits = [["f9", "app"]], build_events = [["f9", "e2e", "SUCCESSFUL", 50], ["f9", "e2e", "FAILED", 40]], required = {"app": ["e2e"]}
- Output:
- [["f9", "MERGEABLE"]]
- Explanation
- The events arrive out of order: the failure at time 40 is older than the success at time 50, so the latest state is a success.
Example 3
- Input:
- commits = [["d4", "docs"]], build_events = [], required = {"web": ["unit"]}
- Output:
- [["d4", "MERGEABLE"]]
- Explanation
- The repo
docshas no entry inrequired, so the commit has nothing to wait for.
Constraints
0 <= commits.length <= 10^50 <= build_events.length <= 10^50 <= timestamp <= 10^9- Each repo requires at most 20 build keys; ids and keys are case-sensitive strings