class Publisher::Providers::Github

Github implementation

Public Class Methods

run_id() click to toggle source

Run id

@return [String]

# File lib/allure_report_publisher/lib/providers/github.rb, line 17
def self.run_id
  @run_id ||= ENV["GITHUB_RUN_ID"]
end

Public Instance Methods

executor_info() click to toggle source

Executor info

@return [Hash]

# File lib/allure_report_publisher/lib/providers/github.rb, line 31
def executor_info
  {
    name: "Github",
    type: "github",
    reportName: "AllureReport",
    url: server_url,
    reportUrl: report_url,
    buildUrl: build_url,
    buildOrder: run_id,
    buildName: build_name
  }
end
pr?() click to toggle source

Pull request run

@return [Boolean]

# File lib/allure_report_publisher/lib/providers/github.rb, line 24
def pr?
  ENV["GITHUB_EVENT_NAME"] == "pull_request"
end

Private Instance Methods

add_comment() click to toggle source

Add comment with report url

@return [void]

# File lib/allure_report_publisher/lib/providers/github.rb, line 67
def add_comment
  return client.add_comment(repository, pr_id, report_urls.comment_body) unless comment

  client.update_comment(repository, comment[:id], report_urls.comment_body(comment[:body]))
end
build_name() click to toggle source

Job name

@return [String]

# File lib/allure_report_publisher/lib/providers/github.rb, line 120
def build_name
  @build_name ||= ENV[ALLURE_JOB_NAME] || ENV["GITHUB_JOB"]
end
build_url() click to toggle source

Build url

@return [String]

# File lib/allure_report_publisher/lib/providers/github.rb, line 113
def build_url
  @build_url ||= "#{server_url}/#{repository}/actions/runs/#{run_id}"
end
client() click to toggle source

Github api client

@return [Octokit::Client]

# File lib/allure_report_publisher/lib/providers/github.rb, line 49
def client
  @client ||= begin
    raise("Missing GITHUB_AUTH_TOKEN environment variable!") unless ENV["GITHUB_AUTH_TOKEN"]

    Octokit::Client.new(access_token: ENV["GITHUB_AUTH_TOKEN"], api_endpoint: ENV["GITHUB_API_URL"])
  end
end
comment() click to toggle source

Existing comment with allure urls

@return [Sawyer::Resource]

# File lib/allure_report_publisher/lib/providers/github.rb, line 76
def comment
  @comment ||= client.issue_comments(repository, pr_id).detect do |comment|
    UrlSectionBuilder.match?(comment[:body])
  end
end
github_event() click to toggle source

Github event

@return [Hash]

# File lib/allure_report_publisher/lib/providers/github.rb, line 85
def github_event
  @github_event ||= JSON.parse(File.read(ENV["GITHUB_EVENT_PATH"]), symbolize_names: true)
end
pr_description() click to toggle source

Pull request description

@return [String]

# File lib/allure_report_publisher/lib/providers/github.rb, line 92
def pr_description
  @pr_description ||= client.pull_request(repository, pr_id)[:body]
end
pr_id() click to toggle source

Pull request id

@return [Integer]

# File lib/allure_report_publisher/lib/providers/github.rb, line 99
def pr_id
  @pr_id ||= github_event[:number]
end
repository() click to toggle source

Github repository

@return [String]

# File lib/allure_report_publisher/lib/providers/github.rb, line 127
def repository
  @repository ||= ENV["GITHUB_REPOSITORY"]
end
server_url() click to toggle source

Server url

@return [String]

# File lib/allure_report_publisher/lib/providers/github.rb, line 106
def server_url
  @server_url ||= ENV["GITHUB_SERVER_URL"]
end
sha_url() click to toggle source

Commit sha url

@return [String]

# File lib/allure_report_publisher/lib/providers/github.rb, line 134
def sha_url
  sha = github_event.dig(:pull_request, :head, :sha)
  short_sha = sha[0..7]

  "[#{short_sha}](#{server_url}/#{repository}/pull/#{pr_id}/commits/#{sha})"
end
update_pr_description() click to toggle source

Update pull request description

@return [void]

# File lib/allure_report_publisher/lib/providers/github.rb, line 60
def update_pr_description
  client.update_pull_request(repository, pr_id, body: report_urls.updated_pr_description(pr_description))
end