class Danger::Appcenter

### CI Setup

Add a script step to your appcenter-post-build.sh:

“‘shell

#!/usr/bin/env bash
bundle install
bundle exec danger

“‘

### Token Setup

Add the ‘DANGER_GITHUB_API_TOKEN` to your environment variables.

Public Class Methods

new(env) click to toggle source
# File lib/danger/ci_source/appcenter.rb, line 49
def initialize(env)
  self.pull_request_id = self.class.pr_from_env(env)
  self.repo_url = env["BUILD_REPOSITORY_URI"]
  self.repo_slug = self.class.repo_identifier_for_github(env)
end
owner_for_github(env) click to toggle source
# File lib/danger/ci_source/appcenter.rb, line 29
def self.owner_for_github(env)
  URI.parse(env["BUILD_REPOSITORY_URI"]).path.split("/")[1]
end
pr_from_env(env) click to toggle source

Hopefully it’s a temporary workaround (same as in Codeship integration) because App Center doesn’t expose PR’s ID. There’s a future request github.com/Microsoft/appcenter/issues/79

# File lib/danger/ci_source/appcenter.rb, line 41
def self.pr_from_env(env)
  Danger::RequestSources::GitHub.new(nil, env).get_pr_from_branch(repo_identifier_for_github(env), env["BUILD_SOURCEBRANCHNAME"], owner_for_github(env))
end
repo_identifier_for_github(env) click to toggle source
# File lib/danger/ci_source/appcenter.rb, line 33
def self.repo_identifier_for_github(env)
  repo_name = env["BUILD_REPOSITORY_NAME"]
  owner = owner_for_github(env)
  "#{owner}/#{repo_name}"
end
validates_as_ci?(env) click to toggle source
# File lib/danger/ci_source/appcenter.rb, line 21
def self.validates_as_ci?(env)
  env.key? "APPCENTER_BUILD_ID"
end
validates_as_pr?(env) click to toggle source
# File lib/danger/ci_source/appcenter.rb, line 25
def self.validates_as_pr?(env)
  return env["BUILD_REASON"] == "PullRequest"
end

Public Instance Methods

supported_request_sources() click to toggle source
# File lib/danger/ci_source/appcenter.rb, line 45
def supported_request_sources
  @supported_request_sources ||= [Danger::RequestSources::GitHub]
end