From a16d264537960713348d5b56ab026a2d99f32d31 Mon Sep 17 00:00:00 2001 From: Daniel Morrison Date: Tue, 9 Jan 2024 16:19:51 -0500 Subject: [PATCH 1/3] Remove webhook from the Circle config and describe new method for enabling. --- .circleci/config.yml | 3 --- README.md | 8 +------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 09d852e..4bb18bd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -38,6 +38,3 @@ jobs: command: yarn build:css - run: command: bundle exec rake -notify: - webhooks: - - url: https://buildlight.collectiveidea.com diff --git a/README.md b/README.md index 0a2589f..8eb3b6a 100644 --- a/README.md +++ b/README.md @@ -43,13 +43,7 @@ notifications: ### Circle CI -Simply add this to your `.circle/config.yml` file: - -``` -notify: - webhooks: - - url: https://buildlight.collectiveidea.com -``` +Go to your project settings in Circle CI and add a new Webhook with `https://buildlight.collectiveidea.com` as the Receiver URL. Ensure the the "Workflow Completed" event is checked. ## Viewing Status From 287b988e49cf03fcbd00faf2e6a746cfadabd89f Mon Sep 17 00:00:00 2001 From: Daniel Morrison Date: Tue, 9 Jan 2024 17:15:00 -0500 Subject: [PATCH 2/3] Switch Circle config to new webhook format --- app/controllers/webhooks_controller.rb | 4 +-- app/interactors/parse_circle.rb | 23 +++++--------- spec/controllers/webhooks_controller_spec.rb | 32 -------------------- spec/fixtures/circle.json | 2 +- spec/interactors/parse_circle_spec.rb | 21 ++----------- spec/requests/circle_webhooks_spec.rb | 29 ++++++++++++++++++ 6 files changed, 42 insertions(+), 69 deletions(-) create mode 100644 spec/requests/circle_webhooks_spec.rb diff --git a/app/controllers/webhooks_controller.rb b/app/controllers/webhooks_controller.rb index b2d3c3f..792f125 100644 --- a/app/controllers/webhooks_controller.rb +++ b/app/controllers/webhooks_controller.rb @@ -7,8 +7,8 @@ def create elsif params[:payload].blank? && params[:repository]&.include?("/") ParseGithub.call(params) head :ok && return - elsif params[:payload] - ParseCircle.call(params[:payload]) + elsif request.headers.env["HTTP_CIRCLECI_EVENT_TYPE"].present? + ParseCircle.call(params) head :ok && return end diff --git a/app/interactors/parse_circle.rb b/app/interactors/parse_circle.rb index 8794573..5bf1d67 100644 --- a/app/interactors/parse_circle.rb +++ b/app/interactors/parse_circle.rb @@ -1,25 +1,18 @@ class ParseCircle def self.call(payload) - return unless payload["pull_requests"].blank? + return unless payload["type"] == "workflow-completed" - status = Status.find_or_initialize_by(service: "circle", username: payload["username"], project_name: payload["reponame"]) + status = Status.find_or_initialize_by(service: "circle", username: payload["organization"]["name"], project_name: payload["project"]["name"]) status.payload = payload if Rails.configuration.x.debug - set_colors(status, payload["status"]) + set_colors(status, payload["workflow"]["status"]) status.save! end - # Options - # :retried, :canceled, :infrastructure_fail, :timedout, :not_run, :running, - # :failed, :queued, :scheduled, :not_running, :no_tests, :fixed, :success + # Potential Statuses + # See: https://circleci.com/docs/webhooks/#event-specifications + # "success", "failed", "error", "canceled", "unauthorized" def self.set_colors(status, code) - status.yellow = false - case code - when "running", "queued", "scheduled" - status.yellow = true - when "success", "fixed" - status.red = false - else - status.red = true - end + status.yellow = false # currently no way to set yellow on Circle + status.red = code != "success" end end diff --git a/spec/controllers/webhooks_controller_spec.rb b/spec/controllers/webhooks_controller_spec.rb index d31dd94..c40ac7d 100644 --- a/spec/controllers/webhooks_controller_spec.rb +++ b/spec/controllers/webhooks_controller_spec.rb @@ -46,38 +46,6 @@ end end - describe "from Circle CI" do - it "recieves a json payload" do - post :create, params: JSON.parse(json_fixture("circle.json")) - expect(response).to be_successful - end - - it "saves useful data" do - post :create, params: JSON.parse(json_fixture("circle.json")) - status = Status.order("created_at DESC").first - expect(status.red).to be(false) - expect(status.service).to eq("circle") - expect(status.project_id).to be_nil - expect(status.project_name).to eq("buildlight") - expect(status.username).to eq("collectiveidea") - end - - it "ignores pull requests" do - expect(Status.count).to eq(0) - data = JSON.parse(json_fixture("circle_pr.json")) - data["payload"]["pull_requests"] = [{not: "empty"}] - post :create, params: data - expect(Status.count).to eq(0) - end - - it "notifies Particle" do - FactoryBot.create(:device, :with_identifier, usernames: ["collectiveidea"]) - allow(Particle).to receive(:publish) - post :create, params: JSON.parse(json_fixture("circle.json")) - expect(Particle).to have_received(:publish).with(name: "build_state", data: "passing", ttl: 3600, private: false) - end - end - describe "from GitHub Actions" do it "recieves a json payload" do post :create, params: JSON.parse(json_fixture("github.json")) diff --git a/spec/fixtures/circle.json b/spec/fixtures/circle.json index ea6525f..9bd8452 100644 --- a/spec/fixtures/circle.json +++ b/spec/fixtures/circle.json @@ -1 +1 @@ -{"payload":{"compare":"https://github.com/collectiveidea/buildlight/commit/f3f6569ec571","previous_successful_build":{"build_num":1,"status":"success","build_time_millis":169610},"build_parameters":null,"oss":true,"all_commit_details_truncated":false,"committer_date":"2016-10-12T15:06:55-04:00","steps":[{"name":"Starting the build","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Starting the build","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:24.970Z","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/e41e476f42c10afb5e98ef75-collectiveidea-buildlight-0-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=fUqb2qbT2aB3cYfEfmMM86mX%2FA4%3D","start_time":"2016-10-12T19:07:17.027Z","exit_code":null,"canceled":null,"step":0,"run_time_millis":7943,"has_output":true}]},{"name":"Start container","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Start container","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:38.373Z","source":"config","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/f41e476f42c10afbce98ef75-collectiveidea-buildlight-1-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=VKStQ6VwYPSxEyTXSXG1gWWxMmY%3D","start_time":"2016-10-12T19:07:24.979Z","exit_code":0,"canceled":null,"step":1,"run_time_millis":13394,"has_output":true}]},{"name":"Enable SSH","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Enable SSH","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:42.549Z","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/151e476f42c10afbaf98ef75-collectiveidea-buildlight-2-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=%2Fv4EOKy1Gd73Ahm9Pg8mvBU77Xw%3D","start_time":"2016-10-12T19:07:38.380Z","exit_code":null,"canceled":null,"step":2,"run_time_millis":4169,"has_output":true}]},{"name":"Restore source cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Restore source cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:46.821Z","source":"cache","type":"checkout","output_url":"https://circle-production-action-output.s3.amazonaws.com/251e476f42c10afbef98ef75-collectiveidea-buildlight-3-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=V8%2BnS17%2FjKwR1eHcJIIXm52MAqk%3D","start_time":"2016-10-12T19:07:42.561Z","exit_code":null,"canceled":null,"step":3,"run_time_millis":4260,"has_output":true}]},{"name":"Checkout using deploy key: be:c8:85:1f:ea:b2:b3:88:e4:2e:d8:99:9a:f9:d0:77","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Checkout using deploy key: be:c8:85:1f:ea:b2:b3:88:e4:2e:d8:99:9a:f9:d0:77","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:53.420Z","source":"config","type":"checkout","output_url":"https://circle-production-action-output.s3.amazonaws.com/351e476f42c10afb20a8ef75-collectiveidea-buildlight-4-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=J7Z9mbvqqua8o4uLXHVy7Q1SErM%3D","start_time":"2016-10-12T19:07:46.829Z","exit_code":0,"canceled":null,"step":4,"run_time_millis":6591,"has_output":true}]},{"name":"Configure the build","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Configure the build","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:00.435Z","source":"cache","type":"machine","start_time":"2016-10-12T19:07:53.427Z","exit_code":null,"canceled":null,"step":5,"run_time_millis":7008,"has_output":false}]},{"name":"Restore cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Restore cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:33.083Z","source":"cache","type":"machine","output_url":"https://circle-production-action-output.s3.amazonaws.com/551e476f42c10afb01a8ef75-collectiveidea-buildlight-6-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=eBdwatbGVcqnVfWOIHhL%2B1m77Hg%3D","start_time":"2016-10-12T19:08:00.441Z","exit_code":null,"canceled":null,"step":6,"run_time_millis":32642,"has_output":true}]},{"name":"Exporting RAILS_ENV, RACK_ENV","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Exporting RAILS_ENV, RACK_ENV","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:35.227Z","source":"inference","type":"dependencies","output_url":"https://circle-production-action-output.s3.amazonaws.com/651e476f42c10afb13a8ef75-collectiveidea-buildlight-7-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=MuIkVFJOueK5lThJjWf44AHTDH0%3D","start_time":"2016-10-12T19:08:33.097Z","exit_code":0,"canceled":null,"step":7,"run_time_millis":2130,"has_output":true}]},{"name":"bundle install","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"bundle install","bash_command":"bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 ","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:37.769Z","source":"inference","type":"dependencies","output_url":"https://circle-production-action-output.s3.amazonaws.com/751e476f42c10afb33a8ef75-collectiveidea-buildlight-8-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=I2YJeHyKfDn0EqaRyDkCwSelRLc%3D","start_time":"2016-10-12T19:08:35.237Z","exit_code":0,"canceled":null,"step":8,"run_time_millis":2532,"has_output":true}]},{"name":"Generate database.yml","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Generate database.yml","bash_command":"mkdir -p config\necho 'test:\n database: circle_ruby_test\n adapter: postgresql\n encoding: unicode\n pool: 15\n username: ubuntu\n host: localhost\n' > config/database.yml\n","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:39.905Z","source":"inference","type":"database","start_time":"2016-10-12T19:08:37.776Z","exit_code":0,"canceled":null,"step":9,"run_time_millis":2129,"has_output":false}]},{"name":"rake db:create db:schema:load","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"rake db:create db:schema:load","bash_command":"export RAILS_ENV=\"test\"\nexport RACK_ENV=\"test\"\nbundle exec rake db:create db:schema:load --trace\n","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:44.150Z","source":"inference","type":"database","output_url":"https://circle-production-action-output.s3.amazonaws.com/951e476f42c10afb73a8ef75-collectiveidea-buildlight-10-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=DCToHiE1S%2B7gAXkPTAZcnXGtuUo%3D","start_time":"2016-10-12T19:08:39.911Z","exit_code":0,"canceled":null,"step":10,"run_time_millis":4239,"has_output":true}]},{"name":"Save cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Save cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:49.034Z","source":"cache","type":"database","output_url":"https://circle-production-action-output.s3.amazonaws.com/a51e476f42c10afbc3a8ef75-collectiveidea-buildlight-11-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=A06tfQ4KddG8IM6h9%2B7uR%2B61FKc%3D","start_time":"2016-10-12T19:08:44.159Z","exit_code":null,"canceled":null,"step":11,"run_time_millis":4875,"has_output":true}]},{"name":"RSpec","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"RSpec","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:53.583Z","source":"inference","type":"test","output_url":"https://circle-production-action-output.s3.amazonaws.com/b51e476f42c10afb14a8ef75-collectiveidea-buildlight-12-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=xgIVVL3Xwgr48uVfQaV3vi0hPCg%3D","start_time":"2016-10-12T19:08:49.043Z","exit_code":0,"canceled":null,"step":12,"run_time_millis":4540,"has_output":true}]},{"name":"Collect test metadata","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Collect test metadata","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:57.962Z","type":"teardown","output_url":"https://circle-production-action-output.s3.amazonaws.com/c51e476f42c10afb54a8ef75-collectiveidea-buildlight-13-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=c46jQv2s%2BAruZUjJvnWYIT4IThU%3D","start_time":"2016-10-12T19:08:53.593Z","exit_code":null,"canceled":null,"step":13,"run_time_millis":4369,"has_output":true}]},{"name":"Collect artifacts","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Collect artifacts","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:09:15.012Z","type":"teardown","output_url":"https://circle-production-action-output.s3.amazonaws.com/d51e476f42c10afb94a8ef75-collectiveidea-buildlight-14-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=8Zy6%2BNnGSsDSZj2JCmIKK9hyObE%3D","start_time":"2016-10-12T19:08:57.969Z","exit_code":null,"canceled":null,"step":14,"run_time_millis":17043,"has_output":true}]},{"name":"Disable SSH","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Disable SSH","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:09:15.023Z","type":"teardown","start_time":"2016-10-12T19:09:15.019Z","exit_code":null,"canceled":null,"step":17,"run_time_millis":4,"has_output":false}]}],"body":"","usage_queued_at":"2016-10-12T19:08:05.605Z","fail_reason":null,"retry_of":null,"reponame":"buildlight","ssh_users":[],"build_url":"https://circleci.com/gh/collectiveidea/buildlight/2","parallel":1,"failed":null,"branch":"circle-ci","username":"collectiveidea","author_date":"2016-10-12T15:06:55-04:00","why":"github","user":{"is_user":true,"login":"danielmorrison","avatar_url":"https://avatars.githubusercontent.com/u/125?v=3","name":"Daniel Morrison","vcs_type":"github","id":125},"vcs_revision":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","owners":["danielmorrison"],"vcs_tag":null,"pull_requests":[],"build_num":2,"infrastructure_fail":false,"committer_email":"daniel@collectiveidea.com","previous":null,"status":"success","committer_name":"Daniel Morrison","retries":null,"subject":"Configure circle ci to send us a webhook","vcs_type":"github","timedout":false,"dont_build":null,"lifecycle":"finished","no_dependency_cache":false,"stop_time":"2016-10-12T19:09:15.768Z","ssh_disabled":false,"build_time_millis":120142,"circle_yml":{"string":"notify:\n webhooks:\n - url: https://buildlight.collectiveidea.com"},"messages":[],"is_first_green_build":false,"job_name":null,"start_time":"2016-10-12T19:07:15.626Z","canceler":null,"all_commit_details":[{"committer_date":"2016-10-12T15:06:55-04:00","body":"","branch":"circle-ci","author_date":"2016-10-12T15:06:55-04:00","committer_email":"daniel@collectiveidea.com","commit":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","committer_login":"danielmorrison","committer_name":"Daniel Morrison","subject":"Configure circle ci to send us a webhook","commit_url":"https://github.com/collectiveidea/buildlight/commit/f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","author_login":"danielmorrison","author_name":"Daniel Morrison","author_email":"daniel@collectiveidea.com"}],"outcome":"success","vcs_url":"https://github.com/collectiveidea/buildlight","author_name":"Daniel Morrison","node":[{"public_ip_addr":"54.80.1.32","port":64687,"username":"ubuntu","image_id":"https://s3.amazonaws.com/circle-downloads/build-image-trusty-692-1323f09.tar.gz","ssh_enabled":null}],"queued_at":"2016-10-12T19:07:15.571Z","canceled":false,"author_email":"daniel@collectiveidea.com"},"controller":"webhooks","action":"create","webhook":{"payload":{"compare":"https://github.com/collectiveidea/buildlight/commit/f3f6569ec571","previous_successful_build":{"build_num":1,"status":"success","build_time_millis":169610},"build_parameters":null,"oss":true,"all_commit_details_truncated":false,"committer_date":"2016-10-12T15:06:55-04:00","steps":[{"name":"Starting the build","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Starting the build","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:24.970Z","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/e41e476f42c10afb5e98ef75-collectiveidea-buildlight-0-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=fUqb2qbT2aB3cYfEfmMM86mX%2FA4%3D","start_time":"2016-10-12T19:07:17.027Z","exit_code":null,"canceled":null,"step":0,"run_time_millis":7943,"has_output":true}]},{"name":"Start container","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Start container","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:38.373Z","source":"config","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/f41e476f42c10afbce98ef75-collectiveidea-buildlight-1-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=VKStQ6VwYPSxEyTXSXG1gWWxMmY%3D","start_time":"2016-10-12T19:07:24.979Z","exit_code":0,"canceled":null,"step":1,"run_time_millis":13394,"has_output":true}]},{"name":"Enable SSH","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Enable SSH","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:42.549Z","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/151e476f42c10afbaf98ef75-collectiveidea-buildlight-2-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=%2Fv4EOKy1Gd73Ahm9Pg8mvBU77Xw%3D","start_time":"2016-10-12T19:07:38.380Z","exit_code":null,"canceled":null,"step":2,"run_time_millis":4169,"has_output":true}]},{"name":"Restore source cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Restore source cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:46.821Z","source":"cache","type":"checkout","output_url":"https://circle-production-action-output.s3.amazonaws.com/251e476f42c10afbef98ef75-collectiveidea-buildlight-3-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=V8%2BnS17%2FjKwR1eHcJIIXm52MAqk%3D","start_time":"2016-10-12T19:07:42.561Z","exit_code":null,"canceled":null,"step":3,"run_time_millis":4260,"has_output":true}]},{"name":"Checkout using deploy key: be:c8:85:1f:ea:b2:b3:88:e4:2e:d8:99:9a:f9:d0:77","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Checkout using deploy key: be:c8:85:1f:ea:b2:b3:88:e4:2e:d8:99:9a:f9:d0:77","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:53.420Z","source":"config","type":"checkout","output_url":"https://circle-production-action-output.s3.amazonaws.com/351e476f42c10afb20a8ef75-collectiveidea-buildlight-4-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=J7Z9mbvqqua8o4uLXHVy7Q1SErM%3D","start_time":"2016-10-12T19:07:46.829Z","exit_code":0,"canceled":null,"step":4,"run_time_millis":6591,"has_output":true}]},{"name":"Configure the build","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Configure the build","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:00.435Z","source":"cache","type":"machine","start_time":"2016-10-12T19:07:53.427Z","exit_code":null,"canceled":null,"step":5,"run_time_millis":7008,"has_output":false}]},{"name":"Restore cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Restore cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:33.083Z","source":"cache","type":"machine","output_url":"https://circle-production-action-output.s3.amazonaws.com/551e476f42c10afb01a8ef75-collectiveidea-buildlight-6-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=eBdwatbGVcqnVfWOIHhL%2B1m77Hg%3D","start_time":"2016-10-12T19:08:00.441Z","exit_code":null,"canceled":null,"step":6,"run_time_millis":32642,"has_output":true}]},{"name":"Exporting RAILS_ENV, RACK_ENV","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Exporting RAILS_ENV, RACK_ENV","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:35.227Z","source":"inference","type":"dependencies","output_url":"https://circle-production-action-output.s3.amazonaws.com/651e476f42c10afb13a8ef75-collectiveidea-buildlight-7-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=MuIkVFJOueK5lThJjWf44AHTDH0%3D","start_time":"2016-10-12T19:08:33.097Z","exit_code":0,"canceled":null,"step":7,"run_time_millis":2130,"has_output":true}]},{"name":"bundle install","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"bundle install","bash_command":"bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 ","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:37.769Z","source":"inference","type":"dependencies","output_url":"https://circle-production-action-output.s3.amazonaws.com/751e476f42c10afb33a8ef75-collectiveidea-buildlight-8-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=I2YJeHyKfDn0EqaRyDkCwSelRLc%3D","start_time":"2016-10-12T19:08:35.237Z","exit_code":0,"canceled":null,"step":8,"run_time_millis":2532,"has_output":true}]},{"name":"Generate database.yml","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Generate database.yml","bash_command":"mkdir -p config\necho 'test:\n database: circle_ruby_test\n adapter: postgresql\n encoding: unicode\n pool: 15\n username: ubuntu\n host: localhost\n' > config/database.yml\n","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:39.905Z","source":"inference","type":"database","start_time":"2016-10-12T19:08:37.776Z","exit_code":0,"canceled":null,"step":9,"run_time_millis":2129,"has_output":false}]},{"name":"rake db:create db:schema:load","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"rake db:create db:schema:load","bash_command":"export RAILS_ENV=\"test\"\nexport RACK_ENV=\"test\"\nbundle exec rake db:create db:schema:load --trace\n","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:44.150Z","source":"inference","type":"database","output_url":"https://circle-production-action-output.s3.amazonaws.com/951e476f42c10afb73a8ef75-collectiveidea-buildlight-10-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=DCToHiE1S%2B7gAXkPTAZcnXGtuUo%3D","start_time":"2016-10-12T19:08:39.911Z","exit_code":0,"canceled":null,"step":10,"run_time_millis":4239,"has_output":true}]},{"name":"Save cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Save cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:49.034Z","source":"cache","type":"database","output_url":"https://circle-production-action-output.s3.amazonaws.com/a51e476f42c10afbc3a8ef75-collectiveidea-buildlight-11-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=A06tfQ4KddG8IM6h9%2B7uR%2B61FKc%3D","start_time":"2016-10-12T19:08:44.159Z","exit_code":null,"canceled":null,"step":11,"run_time_millis":4875,"has_output":true}]},{"name":"RSpec","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"RSpec","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:53.583Z","source":"inference","type":"test","output_url":"https://circle-production-action-output.s3.amazonaws.com/b51e476f42c10afb14a8ef75-collectiveidea-buildlight-12-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=xgIVVL3Xwgr48uVfQaV3vi0hPCg%3D","start_time":"2016-10-12T19:08:49.043Z","exit_code":0,"canceled":null,"step":12,"run_time_millis":4540,"has_output":true}]},{"name":"Collect test metadata","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Collect test metadata","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:57.962Z","type":"teardown","output_url":"https://circle-production-action-output.s3.amazonaws.com/c51e476f42c10afb54a8ef75-collectiveidea-buildlight-13-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=c46jQv2s%2BAruZUjJvnWYIT4IThU%3D","start_time":"2016-10-12T19:08:53.593Z","exit_code":null,"canceled":null,"step":13,"run_time_millis":4369,"has_output":true}]},{"name":"Collect artifacts","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Collect artifacts","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:09:15.012Z","type":"teardown","output_url":"https://circle-production-action-output.s3.amazonaws.com/d51e476f42c10afb94a8ef75-collectiveidea-buildlight-14-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=8Zy6%2BNnGSsDSZj2JCmIKK9hyObE%3D","start_time":"2016-10-12T19:08:57.969Z","exit_code":null,"canceled":null,"step":14,"run_time_millis":17043,"has_output":true}]},{"name":"Disable SSH","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Disable SSH","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:09:15.023Z","type":"teardown","start_time":"2016-10-12T19:09:15.019Z","exit_code":null,"canceled":null,"step":17,"run_time_millis":4,"has_output":false}]}],"body":"","usage_queued_at":"2016-10-12T19:08:05.605Z","fail_reason":null,"retry_of":null,"reponame":"buildlight","ssh_users":[],"build_url":"https://circleci.com/gh/collectiveidea/buildlight/2","parallel":1,"failed":null,"branch":"circle-ci","username":"collectiveidea","author_date":"2016-10-12T15:06:55-04:00","why":"github","user":{"is_user":true,"login":"danielmorrison","avatar_url":"https://avatars.githubusercontent.com/u/125?v=3","name":"Daniel Morrison","vcs_type":"github","id":125},"vcs_revision":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","owners":["danielmorrison"],"vcs_tag":null,"pull_requests":[],"build_num":2,"infrastructure_fail":false,"committer_email":"daniel@collectiveidea.com","previous":null,"status":"success","committer_name":"Daniel Morrison","retries":null,"subject":"Configure circle ci to send us a webhook","vcs_type":"github","timedout":false,"dont_build":null,"lifecycle":"finished","no_dependency_cache":false,"stop_time":"2016-10-12T19:09:15.768Z","ssh_disabled":false,"build_time_millis":120142,"circle_yml":{"string":"notify:\n webhooks:\n - url: https://buildlight.collectiveidea.com"},"messages":[],"is_first_green_build":false,"job_name":null,"start_time":"2016-10-12T19:07:15.626Z","canceler":null,"all_commit_details":[{"committer_date":"2016-10-12T15:06:55-04:00","body":"","branch":"circle-ci","author_date":"2016-10-12T15:06:55-04:00","committer_email":"daniel@collectiveidea.com","commit":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","committer_login":"danielmorrison","committer_name":"Daniel Morrison","subject":"Configure circle ci to send us a webhook","commit_url":"https://github.com/collectiveidea/buildlight/commit/f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","author_login":"danielmorrison","author_name":"Daniel Morrison","author_email":"daniel@collectiveidea.com"}],"outcome":"success","vcs_url":"https://github.com/collectiveidea/buildlight","author_name":"Daniel Morrison","node":[{"public_ip_addr":"54.80.1.32","port":64687,"username":"ubuntu","image_id":"https://s3.amazonaws.com/circle-downloads/build-image-trusty-692-1323f09.tar.gz","ssh_enabled":null}],"queued_at":"2016-10-12T19:07:15.571Z","canceled":false,"author_email":"daniel@collectiveidea.com"}}} +{"type":"workflow-completed","id":"5a0111d5-3fa7-3180-926d-63a61a4b81a8","happened_at":"2024-01-09T21:10:40.799826Z","webhook":{"id":"e6b36f33-5e50-4492-9a16-cced97041b64","name":"Webhook Bin"},"workflow":{"id":"a2a8d81e-9de0-4e07-981c-cb14dbbe0a89","name":"workflow","created_at":"2024-01-09T21:09:36.583Z","stopped_at":"2024-01-09T21:10:40.684Z","url":"https://app.circleci.com/pipelines/github/collectiveidea/buildlight/350/workflows/a2a8d81e-9de0-4e07-981c-cb14dbbe0a89","status":"success"},"pipeline":{"id":"2b13912c-88e7-47e3-999b-30c164c573d9","number":350,"created_at":"2024-01-09T20:53:23.960Z","trigger":{"type":"webhook"},"vcs":{"provider_name":"github","origin_repository_url":"https://github.com/collectiveidea/buildlight","target_repository_url":"https://github.com/collectiveidea/buildlight","revision":"3287ff41025001a2aff89d6aaa57387851f9d588","commit":{"subject":"Merge pull request #233 from collectiveidea/upgrade","body":"Upgrade to Rails 7.1","author":{"name":"Daniel Morrison","email":"daniel@collectiveidea.com"},"authored_at":"2024-01-09T20:53:21Z","committer":{"name":"GitHub","email":"noreply@github.com"},"committed_at":"2024-01-09T20:53:21Z"},"branch":"main"}},"project":{"id":"b7548785-2c2f-44e2-9062-35b4f960875c","name":"buildlight","slug":"github/collectiveidea/buildlight"},"organization":{"id":"cfdfbe86-a83b-41cb-a584-916c604f08bc","name":"collectiveidea"}} diff --git a/spec/interactors/parse_circle_spec.rb b/spec/interactors/parse_circle_spec.rb index c10dbe8..126bb09 100644 --- a/spec/interactors/parse_circle_spec.rb +++ b/spec/interactors/parse_circle_spec.rb @@ -12,27 +12,10 @@ expect(@status.yellow).to be(false) end - it "sets fixed to green" do - ParseCircle.set_colors(@status, "fixed") - expect(@status.red).to be(false) - expect(@status.yellow).to be(false) - end - - it "sets timedout to red" do - ParseCircle.set_colors(@status, "timedout") + it "sets failed to red" do + ParseCircle.set_colors(@status, "failed") expect(@status.red).to be(true) expect(@status.yellow).to be(false) end - - it "sets running to yellow" do - ParseCircle.set_colors(@status, "running") - expect(@status.yellow).to be(true) - end - - it "keeps the red color if yellow" do - @status.red = true - ParseCircle.set_colors(@status, "running") - expect(@status.red).to be(true) - end end end diff --git a/spec/requests/circle_webhooks_spec.rb b/spec/requests/circle_webhooks_spec.rb new file mode 100644 index 0000000..b9e7c77 --- /dev/null +++ b/spec/requests/circle_webhooks_spec.rb @@ -0,0 +1,29 @@ +require "rails_helper" + +describe "Webhooks from Circle CI" do + before do + allow(Particle).to receive(:publish) + end + + it "recieves a json payload" do + post "/", params: json_fixture("circle.json"), headers: {"content-type": "application/json", "Circleci-Event-Type": "workflow-completed"} + expect(response).to be_successful + end + + it "saves useful data" do + post "/", params: json_fixture("circle.json"), headers: {"content-type": "application/json", "Circleci-Event-Type": "workflow-completed"} + status = Status.order("created_at DESC").first + expect(status.red).to be(false) + expect(status.service).to eq("circle") + expect(status.project_id).to be_nil + expect(status.project_name).to eq("buildlight") + expect(status.username).to eq("collectiveidea") + end + + it "notifies Particle" do + FactoryBot.create(:device, :with_identifier, usernames: ["collectiveidea"]) + allow(Particle).to receive(:publish) + post "/", params: json_fixture("circle.json"), headers: {"content-type": "application/json", "Circleci-Event-Type": "workflow-completed"} + expect(Particle).to have_received(:publish).with(name: "build_state", data: "passing", ttl: 3600, private: false) + end +end From 822e99765b0dc2762a86b6b0b9f5a10b573835d4 Mon Sep 17 00:00:00 2001 From: Daniel Morrison Date: Wed, 10 Jan 2024 11:21:38 -0500 Subject: [PATCH 3/3] Ignore circle's PR builds --- app/interactors/parse_circle.rb | 2 ++ spec/fixtures/circle_pr.json | 2 +- spec/requests/circle_webhooks_spec.rb | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/interactors/parse_circle.rb b/app/interactors/parse_circle.rb index 5bf1d67..3779e78 100644 --- a/app/interactors/parse_circle.rb +++ b/app/interactors/parse_circle.rb @@ -1,6 +1,8 @@ class ParseCircle def self.call(payload) return unless payload["type"] == "workflow-completed" + # Ignore pull requests. We can't really determine a PR build, so we ignore any branches other than main/master. + return unless payload.dig("pipeline", "vcs", "branch").in? ["main", "master"] status = Status.find_or_initialize_by(service: "circle", username: payload["organization"]["name"], project_name: payload["project"]["name"]) status.payload = payload if Rails.configuration.x.debug diff --git a/spec/fixtures/circle_pr.json b/spec/fixtures/circle_pr.json index 67b3b06..fd9b64a 100644 --- a/spec/fixtures/circle_pr.json +++ b/spec/fixtures/circle_pr.json @@ -1 +1 @@ -{"payload":{"compare":"https://github.com/collectiveidea/buildlight/commit/f3f6569ec571","previous_successful_build":{"build_num":1,"status":"success","build_time_millis":169610},"build_parameters":null,"oss":true,"all_commit_details_truncated":false,"committer_date":"2016-10-12T15:06:55-04:00","steps":[{"name":"Starting the build","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Starting the build","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:24.970Z","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/e41e476f42c10afb5e98ef75-collectiveidea-buildlight-0-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=fUqb2qbT2aB3cYfEfmMM86mX%2FA4%3D","start_time":"2016-10-12T19:07:17.027Z","exit_code":null,"canceled":null,"step":0,"run_time_millis":7943,"has_output":true}]},{"name":"Start container","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Start container","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:38.373Z","source":"config","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/f41e476f42c10afbce98ef75-collectiveidea-buildlight-1-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=VKStQ6VwYPSxEyTXSXG1gWWxMmY%3D","start_time":"2016-10-12T19:07:24.979Z","exit_code":0,"canceled":null,"step":1,"run_time_millis":13394,"has_output":true}]},{"name":"Enable SSH","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Enable SSH","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:42.549Z","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/151e476f42c10afbaf98ef75-collectiveidea-buildlight-2-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=%2Fv4EOKy1Gd73Ahm9Pg8mvBU77Xw%3D","start_time":"2016-10-12T19:07:38.380Z","exit_code":null,"canceled":null,"step":2,"run_time_millis":4169,"has_output":true}]},{"name":"Restore source cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Restore source cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:46.821Z","source":"cache","type":"checkout","output_url":"https://circle-production-action-output.s3.amazonaws.com/251e476f42c10afbef98ef75-collectiveidea-buildlight-3-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=V8%2BnS17%2FjKwR1eHcJIIXm52MAqk%3D","start_time":"2016-10-12T19:07:42.561Z","exit_code":null,"canceled":null,"step":3,"run_time_millis":4260,"has_output":true}]},{"name":"Checkout using deploy key: be:c8:85:1f:ea:b2:b3:88:e4:2e:d8:99:9a:f9:d0:77","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Checkout using deploy key: be:c8:85:1f:ea:b2:b3:88:e4:2e:d8:99:9a:f9:d0:77","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:53.420Z","source":"config","type":"checkout","output_url":"https://circle-production-action-output.s3.amazonaws.com/351e476f42c10afb20a8ef75-collectiveidea-buildlight-4-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=J7Z9mbvqqua8o4uLXHVy7Q1SErM%3D","start_time":"2016-10-12T19:07:46.829Z","exit_code":0,"canceled":null,"step":4,"run_time_millis":6591,"has_output":true}]},{"name":"Configure the build","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Configure the build","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:00.435Z","source":"cache","type":"machine","start_time":"2016-10-12T19:07:53.427Z","exit_code":null,"canceled":null,"step":5,"run_time_millis":7008,"has_output":false}]},{"name":"Restore cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Restore cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:33.083Z","source":"cache","type":"machine","output_url":"https://circle-production-action-output.s3.amazonaws.com/551e476f42c10afb01a8ef75-collectiveidea-buildlight-6-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=eBdwatbGVcqnVfWOIHhL%2B1m77Hg%3D","start_time":"2016-10-12T19:08:00.441Z","exit_code":null,"canceled":null,"step":6,"run_time_millis":32642,"has_output":true}]},{"name":"Exporting RAILS_ENV, RACK_ENV","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Exporting RAILS_ENV, RACK_ENV","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:35.227Z","source":"inference","type":"dependencies","output_url":"https://circle-production-action-output.s3.amazonaws.com/651e476f42c10afb13a8ef75-collectiveidea-buildlight-7-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=MuIkVFJOueK5lThJjWf44AHTDH0%3D","start_time":"2016-10-12T19:08:33.097Z","exit_code":0,"canceled":null,"step":7,"run_time_millis":2130,"has_output":true}]},{"name":"bundle install","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"bundle install","bash_command":"bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 ","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:37.769Z","source":"inference","type":"dependencies","output_url":"https://circle-production-action-output.s3.amazonaws.com/751e476f42c10afb33a8ef75-collectiveidea-buildlight-8-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=I2YJeHyKfDn0EqaRyDkCwSelRLc%3D","start_time":"2016-10-12T19:08:35.237Z","exit_code":0,"canceled":null,"step":8,"run_time_millis":2532,"has_output":true}]},{"name":"Generate database.yml","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Generate database.yml","bash_command":"mkdir -p config\necho 'test:\n database: circle_ruby_test\n adapter: postgresql\n encoding: unicode\n pool: 15\n username: ubuntu\n host: localhost\n' > config/database.yml\n","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:39.905Z","source":"inference","type":"database","start_time":"2016-10-12T19:08:37.776Z","exit_code":0,"canceled":null,"step":9,"run_time_millis":2129,"has_output":false}]},{"name":"rake db:create db:schema:load","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"rake db:create db:schema:load","bash_command":"export RAILS_ENV=\"test\"\nexport RACK_ENV=\"test\"\nbundle exec rake db:create db:schema:load --trace\n","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:44.150Z","source":"inference","type":"database","output_url":"https://circle-production-action-output.s3.amazonaws.com/951e476f42c10afb73a8ef75-collectiveidea-buildlight-10-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=DCToHiE1S%2B7gAXkPTAZcnXGtuUo%3D","start_time":"2016-10-12T19:08:39.911Z","exit_code":0,"canceled":null,"step":10,"run_time_millis":4239,"has_output":true}]},{"name":"Save cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Save cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:49.034Z","source":"cache","type":"database","output_url":"https://circle-production-action-output.s3.amazonaws.com/a51e476f42c10afbc3a8ef75-collectiveidea-buildlight-11-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=A06tfQ4KddG8IM6h9%2B7uR%2B61FKc%3D","start_time":"2016-10-12T19:08:44.159Z","exit_code":null,"canceled":null,"step":11,"run_time_millis":4875,"has_output":true}]},{"name":"RSpec","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"RSpec","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:53.583Z","source":"inference","type":"test","output_url":"https://circle-production-action-output.s3.amazonaws.com/b51e476f42c10afb14a8ef75-collectiveidea-buildlight-12-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=xgIVVL3Xwgr48uVfQaV3vi0hPCg%3D","start_time":"2016-10-12T19:08:49.043Z","exit_code":0,"canceled":null,"step":12,"run_time_millis":4540,"has_output":true}]},{"name":"Collect test metadata","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Collect test metadata","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:57.962Z","type":"teardown","output_url":"https://circle-production-action-output.s3.amazonaws.com/c51e476f42c10afb54a8ef75-collectiveidea-buildlight-13-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=c46jQv2s%2BAruZUjJvnWYIT4IThU%3D","start_time":"2016-10-12T19:08:53.593Z","exit_code":null,"canceled":null,"step":13,"run_time_millis":4369,"has_output":true}]},{"name":"Collect artifacts","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Collect artifacts","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:09:15.012Z","type":"teardown","output_url":"https://circle-production-action-output.s3.amazonaws.com/d51e476f42c10afb94a8ef75-collectiveidea-buildlight-14-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=8Zy6%2BNnGSsDSZj2JCmIKK9hyObE%3D","start_time":"2016-10-12T19:08:57.969Z","exit_code":null,"canceled":null,"step":14,"run_time_millis":17043,"has_output":true}]},{"name":"Disable SSH","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Disable SSH","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:09:15.023Z","type":"teardown","start_time":"2016-10-12T19:09:15.019Z","exit_code":null,"canceled":null,"step":17,"run_time_millis":4,"has_output":false}]}],"body":"","usage_queued_at":"2016-10-12T19:08:05.605Z","fail_reason":null,"retry_of":null,"reponame":"buildlight","ssh_users":[],"build_url":"https://circleci.com/gh/collectiveidea/buildlight/2","parallel":1,"failed":null,"branch":"circle-ci","username":"collectiveidea","author_date":"2016-10-12T15:06:55-04:00","why":"github","user":{"is_user":true,"login":"danielmorrison","avatar_url":"https://avatars.githubusercontent.com/u/125?v=3","name":"Daniel Morrison","vcs_type":"github","id":125},"vcs_revision":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","owners":["danielmorrison"],"vcs_tag":null,"pull_requests":[{"head_sha":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","url":"https://github.com/collectiveidea/buildlight/pull/25"}],"build_num":2,"infrastructure_fail":false,"committer_email":"daniel@collectiveidea.com","previous":null,"status":"success","committer_name":"Daniel Morrison","retries":null,"subject":"Configure circle ci to send us a webhook","vcs_type":"github","timedout":false,"dont_build":null,"lifecycle":"finished","no_dependency_cache":false,"stop_time":"2016-10-12T19:09:15.768Z","ssh_disabled":false,"build_time_millis":120142,"circle_yml":{"string":"notify:\n webhooks:\n - url: https://buildlight.collectiveidea.com"},"messages":[],"is_first_green_build":false,"job_name":null,"start_time":"2016-10-12T19:07:15.626Z","canceler":null,"all_commit_details":[{"committer_date":"2016-10-12T15:06:55-04:00","body":"","branch":"circle-ci","author_date":"2016-10-12T15:06:55-04:00","committer_email":"daniel@collectiveidea.com","commit":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","committer_login":"danielmorrison","committer_name":"Daniel Morrison","subject":"Configure circle ci to send us a webhook","commit_url":"https://github.com/collectiveidea/buildlight/commit/f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","author_login":"danielmorrison","author_name":"Daniel Morrison","author_email":"daniel@collectiveidea.com"}],"outcome":"success","vcs_url":"https://github.com/collectiveidea/buildlight","author_name":"Daniel Morrison","node":[{"public_ip_addr":"54.80.1.32","port":64687,"username":"ubuntu","image_id":"https://s3.amazonaws.com/circle-downloads/build-image-trusty-692-1323f09.tar.gz","ssh_enabled":null}],"queued_at":"2016-10-12T19:07:15.571Z","canceled":false,"author_email":"daniel@collectiveidea.com"},"controller":"webhooks","action":"create","webhook":{"payload":{"compare":"https://github.com/collectiveidea/buildlight/commit/f3f6569ec571","previous_successful_build":{"build_num":1,"status":"success","build_time_millis":169610},"build_parameters":null,"oss":true,"all_commit_details_truncated":false,"committer_date":"2016-10-12T15:06:55-04:00","steps":[{"name":"Starting the build","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Starting the build","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:24.970Z","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/e41e476f42c10afb5e98ef75-collectiveidea-buildlight-0-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=fUqb2qbT2aB3cYfEfmMM86mX%2FA4%3D","start_time":"2016-10-12T19:07:17.027Z","exit_code":null,"canceled":null,"step":0,"run_time_millis":7943,"has_output":true}]},{"name":"Start container","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Start container","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:38.373Z","source":"config","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/f41e476f42c10afbce98ef75-collectiveidea-buildlight-1-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=VKStQ6VwYPSxEyTXSXG1gWWxMmY%3D","start_time":"2016-10-12T19:07:24.979Z","exit_code":0,"canceled":null,"step":1,"run_time_millis":13394,"has_output":true}]},{"name":"Enable SSH","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Enable SSH","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:42.549Z","type":"infrastructure","output_url":"https://circle-production-action-output.s3.amazonaws.com/151e476f42c10afbaf98ef75-collectiveidea-buildlight-2-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=%2Fv4EOKy1Gd73Ahm9Pg8mvBU77Xw%3D","start_time":"2016-10-12T19:07:38.380Z","exit_code":null,"canceled":null,"step":2,"run_time_millis":4169,"has_output":true}]},{"name":"Restore source cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Restore source cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:46.821Z","source":"cache","type":"checkout","output_url":"https://circle-production-action-output.s3.amazonaws.com/251e476f42c10afbef98ef75-collectiveidea-buildlight-3-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065756&Signature=V8%2BnS17%2FjKwR1eHcJIIXm52MAqk%3D","start_time":"2016-10-12T19:07:42.561Z","exit_code":null,"canceled":null,"step":3,"run_time_millis":4260,"has_output":true}]},{"name":"Checkout using deploy key: be:c8:85:1f:ea:b2:b3:88:e4:2e:d8:99:9a:f9:d0:77","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Checkout using deploy key: be:c8:85:1f:ea:b2:b3:88:e4:2e:d8:99:9a:f9:d0:77","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:07:53.420Z","source":"config","type":"checkout","output_url":"https://circle-production-action-output.s3.amazonaws.com/351e476f42c10afb20a8ef75-collectiveidea-buildlight-4-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=J7Z9mbvqqua8o4uLXHVy7Q1SErM%3D","start_time":"2016-10-12T19:07:46.829Z","exit_code":0,"canceled":null,"step":4,"run_time_millis":6591,"has_output":true}]},{"name":"Configure the build","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Configure the build","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:00.435Z","source":"cache","type":"machine","start_time":"2016-10-12T19:07:53.427Z","exit_code":null,"canceled":null,"step":5,"run_time_millis":7008,"has_output":false}]},{"name":"Restore cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Restore cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:33.083Z","source":"cache","type":"machine","output_url":"https://circle-production-action-output.s3.amazonaws.com/551e476f42c10afb01a8ef75-collectiveidea-buildlight-6-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=eBdwatbGVcqnVfWOIHhL%2B1m77Hg%3D","start_time":"2016-10-12T19:08:00.441Z","exit_code":null,"canceled":null,"step":6,"run_time_millis":32642,"has_output":true}]},{"name":"Exporting RAILS_ENV, RACK_ENV","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Exporting RAILS_ENV, RACK_ENV","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:35.227Z","source":"inference","type":"dependencies","output_url":"https://circle-production-action-output.s3.amazonaws.com/651e476f42c10afb13a8ef75-collectiveidea-buildlight-7-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=MuIkVFJOueK5lThJjWf44AHTDH0%3D","start_time":"2016-10-12T19:08:33.097Z","exit_code":0,"canceled":null,"step":7,"run_time_millis":2130,"has_output":true}]},{"name":"bundle install","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"bundle install","bash_command":"bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3 ","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:37.769Z","source":"inference","type":"dependencies","output_url":"https://circle-production-action-output.s3.amazonaws.com/751e476f42c10afb33a8ef75-collectiveidea-buildlight-8-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=I2YJeHyKfDn0EqaRyDkCwSelRLc%3D","start_time":"2016-10-12T19:08:35.237Z","exit_code":0,"canceled":null,"step":8,"run_time_millis":2532,"has_output":true}]},{"name":"Generate database.yml","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Generate database.yml","bash_command":"mkdir -p config\necho 'test:\n database: circle_ruby_test\n adapter: postgresql\n encoding: unicode\n pool: 15\n username: ubuntu\n host: localhost\n' > config/database.yml\n","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:39.905Z","source":"inference","type":"database","start_time":"2016-10-12T19:08:37.776Z","exit_code":0,"canceled":null,"step":9,"run_time_millis":2129,"has_output":false}]},{"name":"rake db:create db:schema:load","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"rake db:create db:schema:load","bash_command":"export RAILS_ENV=\"test\"\nexport RACK_ENV=\"test\"\nbundle exec rake db:create db:schema:load --trace\n","status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:44.150Z","source":"inference","type":"database","output_url":"https://circle-production-action-output.s3.amazonaws.com/951e476f42c10afb73a8ef75-collectiveidea-buildlight-10-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=DCToHiE1S%2B7gAXkPTAZcnXGtuUo%3D","start_time":"2016-10-12T19:08:39.911Z","exit_code":0,"canceled":null,"step":10,"run_time_millis":4239,"has_output":true}]},{"name":"Save cache","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"Save cache","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:49.034Z","source":"cache","type":"database","output_url":"https://circle-production-action-output.s3.amazonaws.com/a51e476f42c10afbc3a8ef75-collectiveidea-buildlight-11-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=A06tfQ4KddG8IM6h9%2B7uR%2B61FKc%3D","start_time":"2016-10-12T19:08:44.159Z","exit_code":null,"canceled":null,"step":11,"run_time_millis":4875,"has_output":true}]},{"name":"RSpec","actions":[{"truncated":false,"index":0,"parallel":false,"failed":null,"infrastructure_fail":null,"name":"RSpec","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:53.583Z","source":"inference","type":"test","output_url":"https://circle-production-action-output.s3.amazonaws.com/b51e476f42c10afb14a8ef75-collectiveidea-buildlight-12-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=xgIVVL3Xwgr48uVfQaV3vi0hPCg%3D","start_time":"2016-10-12T19:08:49.043Z","exit_code":0,"canceled":null,"step":12,"run_time_millis":4540,"has_output":true}]},{"name":"Collect test metadata","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Collect test metadata","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:08:57.962Z","type":"teardown","output_url":"https://circle-production-action-output.s3.amazonaws.com/c51e476f42c10afb54a8ef75-collectiveidea-buildlight-13-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=c46jQv2s%2BAruZUjJvnWYIT4IThU%3D","start_time":"2016-10-12T19:08:53.593Z","exit_code":null,"canceled":null,"step":13,"run_time_millis":4369,"has_output":true}]},{"name":"Collect artifacts","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Collect artifacts","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:09:15.012Z","type":"teardown","output_url":"https://circle-production-action-output.s3.amazonaws.com/d51e476f42c10afb94a8ef75-collectiveidea-buildlight-14-0?AWSAccessKeyId=AKIAIQ65EYQDTMSJK2DQ&Expires=1634065757&Signature=8Zy6%2BNnGSsDSZj2JCmIKK9hyObE%3D","start_time":"2016-10-12T19:08:57.969Z","exit_code":null,"canceled":null,"step":14,"run_time_millis":17043,"has_output":true}]},{"name":"Disable SSH","actions":[{"truncated":false,"index":0,"parallel":true,"failed":null,"infrastructure_fail":null,"name":"Disable SSH","bash_command":null,"status":"success","timedout":null,"continue":null,"end_time":"2016-10-12T19:09:15.023Z","type":"teardown","start_time":"2016-10-12T19:09:15.019Z","exit_code":null,"canceled":null,"step":17,"run_time_millis":4,"has_output":false}]}],"body":"","usage_queued_at":"2016-10-12T19:08:05.605Z","fail_reason":null,"retry_of":null,"reponame":"buildlight","ssh_users":[],"build_url":"https://circleci.com/gh/collectiveidea/buildlight/2","parallel":1,"failed":null,"branch":"circle-ci","username":"collectiveidea","author_date":"2016-10-12T15:06:55-04:00","why":"github","user":{"is_user":true,"login":"danielmorrison","avatar_url":"https://avatars.githubusercontent.com/u/125?v=3","name":"Daniel Morrison","vcs_type":"github","id":125},"vcs_revision":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","owners":["danielmorrison"],"vcs_tag":null,"pull_requests":[{"head_sha":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","url":"https://github.com/collectiveidea/buildlight/pull/25"}],"build_num":2,"infrastructure_fail":false,"committer_email":"daniel@collectiveidea.com","previous":null,"status":"success","committer_name":"Daniel Morrison","retries":null,"subject":"Configure circle ci to send us a webhook","vcs_type":"github","timedout":false,"dont_build":null,"lifecycle":"finished","no_dependency_cache":false,"stop_time":"2016-10-12T19:09:15.768Z","ssh_disabled":false,"build_time_millis":120142,"circle_yml":{"string":"notify:\n webhooks:\n - url: https://buildlight.collectiveidea.com"},"messages":[],"is_first_green_build":false,"job_name":null,"start_time":"2016-10-12T19:07:15.626Z","canceler":null,"all_commit_details":[{"committer_date":"2016-10-12T15:06:55-04:00","body":"","branch":"circle-ci","author_date":"2016-10-12T15:06:55-04:00","committer_email":"daniel@collectiveidea.com","commit":"f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","committer_login":"danielmorrison","committer_name":"Daniel Morrison","subject":"Configure circle ci to send us a webhook","commit_url":"https://github.com/collectiveidea/buildlight/commit/f3f6569ec57197a5382c38d6b8ba2e2fc74f0599","author_login":"danielmorrison","author_name":"Daniel Morrison","author_email":"daniel@collectiveidea.com"}],"outcome":"success","vcs_url":"https://github.com/collectiveidea/buildlight","author_name":"Daniel Morrison","node":[{"public_ip_addr":"54.80.1.32","port":64687,"username":"ubuntu","image_id":"https://s3.amazonaws.com/circle-downloads/build-image-trusty-692-1323f09.tar.gz","ssh_enabled":null}],"queued_at":"2016-10-12T19:07:15.571Z","canceled":false,"author_email":"daniel@collectiveidea.com"}}} +{"type":"workflow-completed","id":"49ebe776-6037-34dc-bf7f-4a15fe63b028","happened_at":"2024-01-10T15:45:30.693234Z","webhook":{"id":"e6b36f33-5e50-4492-9a16-cced97041b64","name":"Webhook Bin"},"workflow":{"id":"eff726c2-47ce-46ea-9b6d-f9481eca3123","name":"workflow","created_at":"2024-01-10T15:44:28.957Z","stopped_at":"2024-01-10T15:45:30.550Z","url":"https://app.circleci.com/pipelines/github/collectiveidea/buildlight/354/workflows/eff726c2-47ce-46ea-9b6d-f9481eca3123","status":"success"},"pipeline":{"id":"e623a4e6-27fc-4b79-87c6-0eda834d10b8","number":354,"created_at":"2024-01-10T15:44:28.800Z","trigger":{"type":"webhook"},"vcs":{"provider_name":"github","origin_repository_url":"https://github.com/collectiveidea/buildlight","target_repository_url":"https://github.com/collectiveidea/buildlight","revision":"2637f724b1e7a6f1a980f70a26c595e9014f273e","commit":{"subject":"Switch Circle config to new webhook format","body":"","author":{"name":"Daniel Morrison","email":"daniel@collectiveidea.com"},"authored_at":"2024-01-10T15:44:18Z","committer":{"name":"Daniel Morrison","email":"daniel@collectiveidea.com"},"committed_at":"2024-01-10T15:44:18Z"},"branch":"circle-webhook-upgrade"}},"project":{"id":"b7548785-2c2f-44e2-9062-35b4f960875c","name":"buildlight","slug":"github/collectiveidea/buildlight"},"organization":{"id":"cfdfbe86-a83b-41cb-a584-916c604f08bc","name":"collectiveidea"}} diff --git a/spec/requests/circle_webhooks_spec.rb b/spec/requests/circle_webhooks_spec.rb index b9e7c77..8bb632a 100644 --- a/spec/requests/circle_webhooks_spec.rb +++ b/spec/requests/circle_webhooks_spec.rb @@ -20,6 +20,12 @@ expect(status.username).to eq("collectiveidea") end + it "ignores pull requests" do + expect(Status.count).to eq(0) + post "/", params: json_fixture("circle_pr.json"), headers: {"content-type": "application/json", "Circleci-Event-Type": "workflow-completed"} + expect(Status.count).to eq(0) + end + it "notifies Particle" do FactoryBot.create(:device, :with_identifier, usernames: ["collectiveidea"]) allow(Particle).to receive(:publish)