From a1e3e00c11127d862ca44f3a9ee473fb208aaa9b Mon Sep 17 00:00:00 2001 From: omkarkhatavkar Date: Thu, 2 Feb 2023 00:43:06 +0530 Subject: [PATCH] added feature to ignore checks fixed #38 --- action.yml | 5 ++++ app/services/github_checks_verifier.rb | 2 ++ .../services/github_checks_verifier_spec.rb | 26 +++++++++++++++++-- entrypoint.rb | 3 +++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index d782063..49af05d 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,10 @@ inputs: description: "Array of allowed conclusions" required: false default: success,skipped + ignore_checks: + description: "Arry of ignore checks" + required: false + default: "" check-name: description: "A name of a check that has to pass" required: false @@ -65,6 +69,7 @@ runs: shell: bash env: ALLOWED_CONCLUSIONS: ${{ inputs.allowed-conclusions }} + IGNORE_CHECKS: ${{ inputs.ignore_checks }} CHECK_NAME: ${{ inputs.check-name }} CHECK_REGEXP: ${{ inputs.check-regexp }} REF: ${{ inputs.ref }} diff --git a/app/services/github_checks_verifier.rb b/app/services/github_checks_verifier.rb index 56f69a2..fde853e 100644 --- a/app/services/github_checks_verifier.rb +++ b/app/services/github_checks_verifier.rb @@ -15,6 +15,7 @@ class GithubChecksVerifier < ApplicationService config_accessor(:check_regexp) { "" } config_accessor(:allowed_conclusions) { ["success", "skipped"] } config_accessor(:verbose) { true } + config_accessor(:ignore_checks){[]} def call wait_for_checks @@ -47,6 +48,7 @@ def log_checks(checks, msg) def apply_filters(checks) checks.reject! { |check| check.name == workflow_name } + checks.reject! { |check| ignore_checks.include?(check.name) } checks.select! { |check| check.name == check_name } if check_name.present? log_checks(checks, "Checks after check_name filter:") apply_regexp_filter(checks) diff --git a/app/spec/services/github_checks_verifier_spec.rb b/app/spec/services/github_checks_verifier_spec.rb index 5037b31..0e2d7d1 100644 --- a/app/spec/services/github_checks_verifier_spec.rb +++ b/app/spec/services/github_checks_verifier_spec.rb @@ -117,7 +117,7 @@ }.not_to raise_error end end - + describe "#show_checks_conclusion_message" do it "prints successful message to standard output" do checks = [OpenStruct.new(name: "check_completed", status: "completed", conclusion: "success")] @@ -139,6 +139,17 @@ service.send(:apply_filters, checks) expect(checks.map(&:name)).to all(eq "check_name") end + + it "filters out only ignore_checks" do + checks = [ + OpenStruct.new(name: "check_name", status: "queued"), + OpenStruct.new(name: "other_check", status: "queued") + ] + + service.config.ignore_checks = ["check_name"] + service.send(:apply_filters, checks) + expect(checks.map(&:name)).to all(eq "other_check") + end it "does not filter by check_name if it's empty" do checks = [ @@ -163,7 +174,18 @@ expect(checks.map(&:name)).not_to include("workflow_name") end - + + it "does not filter if ignore checks are empty" do + all_checks = [ + OpenStruct.new(name: "test1", status: "completed", conclusion: "success"), + OpenStruct.new(name: "test2", status: "completed", conclusion: "skipped") + ] + service.config.ignore_checks = [] + service.send(:apply_filters, checks) + + expect(checks.size).to eq 2 + end + it "apply the regexp filter" do checks = [ OpenStruct.new(name: "test", status: "pending"), diff --git a/entrypoint.rb b/entrypoint.rb index 1793097..43c8529 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -11,9 +11,12 @@ wait = ENV["WAIT_INTERVAL"] workflow_name = ENV["RUNNING_WORKFLOW_NAME"] api_endpoint = ENV.fetch("API_ENDPOINT", "") +ignore_checks = ENV["IGNORE_CHECKS"] + GithubChecksVerifier.configure do |config| config.allowed_conclusions = allowed_conclusions.split(",").map(&:strip) + config.ignore_checks = ignore_checks.split(",").map(&:strip) config.check_name = check_name config.check_regexp = check_regexp config.client = Octokit::Client.new(auto_paginate: true)