Returns True if this review request needs to be verified.
(self, review_request)
| 111 | self.api(review_url, data) |
| 112 | |
| 113 | def needs_verification(self, review_request): |
| 114 | """Returns True if this review request needs to be verified.""" |
| 115 | print("Checking if review %s needs verification" % ( |
| 116 | review_request["id"])) |
| 117 | rb_date_format = "%Y-%m-%dT%H:%M:%SZ" |
| 118 | |
| 119 | # Now apply this review if not yet submitted. |
| 120 | if review_request["status"] == "submitted": |
| 121 | print("The review is already submitted") |
| 122 | return False |
| 123 | |
| 124 | # Skip if the review blocks another review. |
| 125 | if review_request["blocks"]: |
| 126 | print("Skipping blocking review %s" % review_request["id"]) |
| 127 | return False |
| 128 | |
| 129 | # Get the timestamp of the latest review from this script. |
| 130 | reviews_url = review_request["links"]["reviews"]["href"] |
| 131 | reviews = self.api(reviews_url + "?max-results=200") |
| 132 | review_time = None |
| 133 | for review in reversed(reviews["reviews"]): |
| 134 | if review["links"]["user"]["title"] == self.user: |
| 135 | timestamp = review["timestamp"] |
| 136 | review_time = datetime.strptime(timestamp, rb_date_format) |
| 137 | print("Latest review timestamp: %s" % review_time) |
| 138 | break |
| 139 | if not review_time: |
| 140 | # Never reviewed, the review request needs to be verified. |
| 141 | print("Patch never verified, needs verification") |
| 142 | return True |
| 143 | |
| 144 | # Every patch must have a diff. |
| 145 | latest_diff = self.api(review_request["links"]["diffs"]["href"]) |
| 146 | |
| 147 | # Get the timestamp of the latest diff. |
| 148 | timestamp = latest_diff["diffs"][-1]["timestamp"] |
| 149 | diff_time = datetime.strptime(timestamp, rb_date_format) |
| 150 | print("Latest diff timestamp: %s" % diff_time) |
| 151 | |
| 152 | # NOTE: We purposefully allow the bot to run again on empty reviews |
| 153 | # so that users can re-trigger the build. |
| 154 | if review_time < diff_time: |
| 155 | # There is a new diff, needs verification. |
| 156 | print("This patch has been updated since its last review, needs" |
| 157 | " verification.") |
| 158 | return True |
| 159 | |
| 160 | # TODO(dragoshsch): Apply this check recursively up the dependency |
| 161 | # chain. |
| 162 | changes_url = review_request["links"]["changes"]["href"] |
| 163 | changes = self.api(changes_url) |
| 164 | dependency_time = None |
| 165 | for change in changes["changes"]: |
| 166 | if "depends_on" in change["fields_changed"]: |
| 167 | timestamp = change["timestamp"] |
| 168 | dependency_time = datetime.strptime(timestamp, rb_date_format) |
| 169 | print("Latest dependency change timestamp: %s" % |
| 170 | dependency_time) |