Sha256: dbae1c4de4c89237c4b0852d86ac2ec5f0f20f1a569fb136e0900f8013eeb337

Contents?: true

Size: 1.26 KB

Versions: 22

Compression:

Stored size: 1.26 KB

Contents

require "danger/request_sources/github/github"

module Danger
  # ### CI Setup
  #
  # You can use `danger/danger` Action in your .github/main.workflow.
  #
  #  ```
  # action "Danger" {
  #    uses = "danger/danger"
  # }
  #  ```
  #
  # ### Token Setup
  #
  # Set DANGER_GITHUB_API_TOKEN to secrets, or you can also use GITHUB_TOKEN.
  #
  # ```
  # action "Danger" {
  #    uses = "danger/danger"
  #    secrets = ["GITHUB_TOKEN"]
  # }
  # ```
  #
  class GitHubActions < CI
    def self.validates_as_ci?(env)
      env.key? "GITHUB_ACTION"
    end

    def self.validates_as_pr?(env)
      env["GITHUB_EVENT_NAME"] == "pull_request"
    end

    def supported_request_sources
      @supported_request_sources ||= [Danger::RequestSources::GitHub]
    end

    def initialize(env)
      self.repo_slug = env["GITHUB_REPOSITORY"]
      pull_request_event = JSON.parse(File.read(env["GITHUB_EVENT_PATH"]))
      self.pull_request_id = pull_request_event['number']
      self.repo_url = pull_request_event['repository']['clone_url']

      # if environment variable DANGER_GITHUB_API_TOKEN is not set, use env GITHUB_TOKEN
      if (env.key? "GITHUB_ACTION") && (!env.key? 'DANGER_GITHUB_API_TOKEN')
        env['DANGER_GITHUB_API_TOKEN'] = env['GITHUB_TOKEN']
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
danger-6.3.1 lib/danger/ci_source/github_actions.rb
danger-6.3.0 lib/danger/ci_source/github_actions.rb
danger-6.2.2 lib/danger/ci_source/github_actions.rb
danger-6.2.1 lib/danger/ci_source/github_actions.rb
danger-6.2.0 lib/danger/ci_source/github_actions.rb
danger-6.1.0 lib/danger/ci_source/github_actions.rb
danger-6.0.9 lib/danger/ci_source/github_actions.rb
danger-6.0.8 lib/danger/ci_source/github_actions.rb
danger-6.0.7 lib/danger/ci_source/github_actions.rb
danger-6.0.6 lib/danger/ci_source/github_actions.rb
danger-6.0.5 lib/danger/ci_source/github_actions.rb
danger-6.0.4 lib/danger/ci_source/github_actions.rb
danger-6.0.3 lib/danger/ci_source/github_actions.rb
danger-6.0.2 lib/danger/ci_source/github_actions.rb
danger-6.0.1 lib/danger/ci_source/github_actions.rb
danger-6.0.0 lib/danger/ci_source/github_actions.rb
danger-5.16.1 lib/danger/ci_source/github_actions.rb
danger-5.16.0 lib/danger/ci_source/github_actions.rb
danger-5.15.0 lib/danger/ci_source/github_actions.rb
danger-5.14.0 lib/danger/ci_source/github_actions.rb