diff --git a/README.md b/README.md index e4a2179..e0e54d2 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ Features - [Automated bugzilla, github, and trello references](#automated-references) - [Auto-merging approved & passing PRs](#auto-merge) -- [Canceling stale Travis-CI builds](#canceling-stale) - @@ -101,10 +99,3 @@ _Note_: at the moment the Dlang-Bot doesn't store _any_ authentication token, so it can't perform actions on behalf of others. - -Canceling stale Travis-CI builds --------------------------------- - -To avoid wasteful resource consumption with Travis CI, -the Dlang-Bot will automatically cancel the previous, possibly running build of -a PR on a new commit event (push or synchronization by a user). diff --git a/source/dlangbot/app.d b/source/dlangbot/app.d index e44d58b..fcd892d 100644 --- a/source/dlangbot/app.d +++ b/source/dlangbot/app.d @@ -1,11 +1,10 @@ module dlangbot.app; -import dlangbot.bugzilla, dlangbot.github, dlangbot.travis, dlangbot.trello, +import dlangbot.bugzilla, dlangbot.github, dlangbot.trello, dlangbot.utils; public import dlangbot.bugzilla : bugzillaURL; public import dlangbot.github : githubAPIURL, githubAuth, hookSecret; -public import dlangbot.travis : travisAPIURL; public import dlangbot.trello : trelloAPIURL, trelloAuth, trelloSecret; string cronDailySecret; @@ -45,7 +44,6 @@ shared static this() trelloSecret = environment["TRELLO_SECRET"]; trelloAuth = "key="~environment["TRELLO_KEY"]~"&token="~environment["TRELLO_TOKEN"]; hookSecret = environment["GH_HOOK_SECRET"]; - travisAuth = "token " ~ environment["TRAVIS_TOKEN"]; cronDailySecret = environment["CRON_DAILY_SECRET"]; // workaround for stupid openssl.conf on Heroku @@ -214,7 +212,4 @@ void handlePR(string action, PullRequest* _pr) if (runTrello) updateTrelloCard(action, pr.htmlURL, refs, descs); - - // wait until builds for the current push are created - setTimer(30.seconds, { dedupTravisBuilds(action, pr.repoSlug, pr.number); }); } diff --git a/source/dlangbot/travis.d b/source/dlangbot/travis.d deleted file mode 100644 index 03cbc91..0000000 --- a/source/dlangbot/travis.d +++ /dev/null @@ -1,66 +0,0 @@ -module dlangbot.travis; - -string travisAPIURL = "https://api.travis-ci.org"; -string travisAuth; - -import vibe.core.log; - -//============================================================================== -// Dedup Travis-CI builds -//============================================================================== - -void cancelBuild(size_t buildId) -{ - import std.format : format; - import vibe.http.client : requestHTTP; - import vibe.http.common : HTTPMethod; - import vibe.stream.operations : readAllUTF8; - - auto url = "%s/builds/%s/cancel".format(travisAPIURL, buildId); - requestHTTP(url, (scope req) { - req.headers["Authorization"] = travisAuth; - req.method = HTTPMethod.POST; - }, (scope res) { - if (res.statusCode / 100 == 2) - logInfo("Canceled Build %s\n", buildId); - else - logWarn("POST %s failed; %s %s.\n%s", url, res.statusPhrase, - res.statusCode, res.bodyReader.readAllUTF8); - }); -} - -void dedupTravisBuilds(string action, string repoSlug, uint pullRequestNumber) -{ - import std.algorithm.iteration : filter; - import std.format : format; - import std.range : drop; - import vibe.http.client : requestHTTP; - - if (action != "synchronize" && action != "merged") - return; - - static bool activeState(string state) - { - switch (state) - { - case "created", "queued", "started": return true; - default: return false; - } - } - - auto url = "%s/repos/%s/builds?event_type=pull_request".format(travisAPIURL, repoSlug); - auto activeBuildsForPR = requestHTTP(url, (scope req) { - req.headers["Authorization"] = travisAuth; - req.headers["Accept"] = "application/vnd.travis-ci.2+json"; - }) - .readJson["builds"][] - .filter!(b => activeState(b["state"].get!string)) - .filter!(b => b["pull_request_number"].get!uint == pullRequestNumber); - - // Keep only the most recent build for this PR. Kill all builds - // when it got merged as it'll be retested after the merge anyhow. - foreach (b; activeBuildsForPR.drop(action == "merged" ? 0 : 1)) - cancelBuild(b["id"].get!size_t); -} - - diff --git a/test/utils.d b/test/utils.d index 7035213..6e3bb65 100644 --- a/test/utils.d +++ b/test/utils.d @@ -65,7 +65,6 @@ void startFakeAPIServer() githubAPIURL = fakeAPIServerURL ~ "/github"; trelloAPIURL = fakeAPIServerURL ~ "/trello"; - travisAPIURL = fakeAPIServerURL ~ "/travis"; bugzillaURL = fakeAPIServerURL ~ "/bugzilla"; }