From 399e04a697e42c9a684f14349f6d94208e719832 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 17 Nov 2017 01:08:55 +0100 Subject: main(): Don't update commit status unless commits were pushed There are a bunch of events that can trigger the `pull_request` webhook. These are: "assigned", "unassigned", "review_requested", "review_request_removed", "labeled", "unlabeled", "opened", "edited", "closed", or "reopened". And "synchronize". We only care about "opened" and "synchronize" because those are the only two where new commits can come through. Since we don't set commit statuses unless that commit is part of a pull request, we need a way to update the status the first time a pull request is opened, thus the "opened" action. When new commits are added we also want to update statuses, so "synchronize". But for the others, we don't want to be duplicating work and adding duplicate unnecessary statuses to PR commits. --- src/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 3bb2dbb..12d71eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ use std::time::Duration; use getopts::Options; use kipper::jenkins; -use kipper::pull_request::CommitRef; +use kipper::pull_request::{CommitRef, pull_request_opened_or_synchronized}; const DEFAULT_PORT: u16 = 8000; @@ -139,6 +139,11 @@ fn main() { }, }; + if !pull_request_opened_or_synchronized(json.clone()) { + return rouille::Response::text("No status update needed.") + .with_status_code(200) + } + let commit_ref = match CommitRef::new(json) { Ok(cr) => cr, Err(e) => { -- cgit v1.2.3