Class: Danger::RequestSources::BitbucketServer

Inherits:
RequestSource show all
Includes:
Helpers::CommentsHelper
Defined in:
lib/danger/request_source/bitbucket_server.rb

Constant Summary

Constants inherited from RequestSource

RequestSource::DANGER_REPO_NAME

Instance Attribute Summary collapse

Attributes inherited from RequestSource

#ci_source, #environment, #ignored_violations

Instance Method Summary collapse

Methods included from Helpers::CommentsHelper

#apply_template, #character_from_emoji, #generate_comment, #generate_description, #generate_inline_comment_body, #generate_inline_markdown_body, #markdown_link_to_message, #markdown_parser, #messages_are_equivalent, #parse_comment, #process_markdown, #random_compliment, #table

Methods included from Helpers::CommentsParsingHelper

#parse_comment, #parse_message_from_row, #parse_tables_from_comment, #table_kind_from_title, #violations_from_table

Methods inherited from RequestSource

available_request_sources, #file_url, inherited

Constructor Details

#initialize(ci_source, environment) ⇒ BitbucketServer

Returns a new instance of BitbucketServer.



10
11
12
13
14
15
16
# File 'lib/danger/request_source/bitbucket_server.rb', line 10

def initialize(ci_source, environment)
  self.ci_source = ci_source
  self.environment = environment

  project, slug = ci_source.repo_slug.split("/")
  @api = BitbucketServerAPI.new(project, slug, ci_source.pull_request_id, environment)
end

Instance Attribute Details

#pr_jsonObject

Returns the value of attribute pr_json.



8
9
10
# File 'lib/danger/request_source/bitbucket_server.rb', line 8

def pr_json
  @pr_json
end

Instance Method Details

#delete_old_comments(danger_id: "danger") ⇒ Object



71
72
73
74
75
# File 'lib/danger/request_source/bitbucket_server.rb', line 71

def delete_old_comments(danger_id: "danger")
  @api.fetch_last_comments.each do |c|
    @api.delete_comment(c[:id], c[:version]) if c[:text] =~ /generated_by_#{danger_id}/
  end
end

#fetch_detailsObject



35
36
37
# File 'lib/danger/request_source/bitbucket_server.rb', line 35

def fetch_details
  self.pr_json = @api.fetch_pr_json
end

#hostObject



31
32
33
# File 'lib/danger/request_source/bitbucket_server.rb', line 31

def host
  @host ||= @api.host
end

#organisationObject



51
52
53
# File 'lib/danger/request_source/bitbucket_server.rb', line 51

def organisation
  nil
end

#scmObject



27
28
29
# File 'lib/danger/request_source/bitbucket_server.rb', line 27

def scm
  @scm ||= GitRepo.new
end

#setup_danger_branchesObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/danger/request_source/bitbucket_server.rb', line 39

def setup_danger_branches
  base_commit = self.pr_json[:toRef][:latestCommit]
  head_commit = self.pr_json[:fromRef][:latestCommit]

  # Next, we want to ensure that we have a version of the current branch at a known location
  self.scm.exec "branch #{EnvironmentManager.danger_base_branch} #{base_commit}"

  # OK, so we want to ensure that we have a known head branch, this will always represent
  # the head of the PR ( e.g. the most recent commit that will be merged. )
  self.scm.exec "branch #{EnvironmentManager.danger_head_branch} #{head_commit}"
end

#update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger") ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/danger/request_source/bitbucket_server.rb', line 55

def update_pull_request!(warnings: [], errors: [], messages: [], markdowns: [], danger_id: "danger")
  delete_old_comments(danger_id: danger_id)

  comment = generate_description(warnings: warnings, errors: errors)
  comment += "\n\n"
  comment += generate_comment(warnings: warnings,
                               errors: errors,
                             messages: messages,
                            markdowns: markdowns,
                  previous_violations: {},
                            danger_id: danger_id,
                             template: "bitbucket_server")

  @api.post_comment(comment)
end

#validates_as_api_source?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/danger/request_source/bitbucket_server.rb', line 23

def validates_as_api_source?
  @api.credentials_given?
end

#validates_as_ci?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/danger/request_source/bitbucket_server.rb', line 18

def validates_as_ci?
  # TODO: ???
  true
end