Sha256: 3e3c5825984ba594ca5f9bcc60968df632ca39e2bac787d53f534e44ac3540aa

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

require "danger/request_sources/github/github"

module Danger
  # ### CI Setup
  #
  # You can use `duck8823/actions/danger` Action in your .github/main.workflow.
  #
  #  ```
  # action "Danger" {
  #    uses = "duck8823/actions/danger"
  # }
  #  ```
  #
  # ### Token Setup
  #
  # Set DANGER_GITHUB_API_TOKEN to secrets, or you can also use GITHUB_TOKEN.
  #
  # ```
  # action "Danger" {
  #    uses = "duck8823/actions/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

2 entries across 2 versions & 1 rubygems

Version Path
danger-5.11.1 lib/danger/ci_source/github_actions.rb
danger-5.11.0 lib/danger/ci_source/github_actions.rb