Class: Danger::GitHubActions

Inherits:
CI
  • Object
show all
Defined in:
lib/danger/ci_source/github_actions.rb

Overview

### 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.

```
...
  steps:
    - uses: actions/checkout@v1
    - uses: danger/danger@master
      env:
        DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

Instance Attribute Summary

Attributes inherited from CI

#pull_request_id, #repo_slug, #repo_url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CI

available_ci_sources, inherited, #supports?

Constructor Details

#initialize(env) ⇒ GitHubActions

Returns a new instance of GitHubActions.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/danger/ci_source/github_actions.rb', line 31

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

Class Method Details

.validates_as_ci?(env) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/danger/ci_source/github_actions.rb', line 19

def self.validates_as_ci?(env)
  env.key? "GITHUB_ACTION"
end

.validates_as_pr?(env) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/danger/ci_source/github_actions.rb', line 23

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

Instance Method Details

#supported_request_sourcesObject



27
28
29
# File 'lib/danger/ci_source/github_actions.rb', line 27

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