Sha256: 24e26754df36a57f3b0a222be0217fff111ce325eb43c752db7b55d78178613f

Contents?: true

Size: 1.32 KB

Versions: 46

Compression:

Stored size: 1.32 KB

Contents

require "danger/request_sources/github/github"

module Danger
  # ### CI Setup
  #
  # You can use `danger/danger` Action in your `.github/workflows/xxx.yml`.
  # And so, you can use GITHUB_TOKEN secret as `DANGER_GITHUB_API_TOKEN` environment variable.
  #
  #  ```yml
  #  ...
  #    steps:
  #      - uses: actions/checkout@v3
  #      - uses: danger/danger@master
  #        env:
  #          DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  #  ```
  #
  class GitHubActions < CI
    def self.validates_as_ci?(env)
      env.key? "GITHUB_ACTION"
    end

    def self.validates_as_pr?(env)
      value = env["GITHUB_EVENT_NAME"]
      ["pull_request", "pull_request_target"].include?(value)
    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

46 entries across 46 versions & 2 rubygems

Version Path
danger-additional-logging-0.0.23 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.22 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.21 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.20 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.19 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.18 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.17 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.16 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.15 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.14 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.13 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.12 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.11 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.10 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.9 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.8 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.7 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.6 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.5 lib/danger/ci_source/github_actions.rb
danger-additional-logging-0.0.4 lib/danger/ci_source/github_actions.rb