Class: BitbucketServer::Representation::PullRequest

Inherits:
Base
  • Object
show all
Defined in:
lib/bitbucket_server/representation/pull_request.rb

Instance Attribute Summary

Attributes inherited from Base

#raw

Instance Method Summary collapse

Methods inherited from Base

convert_timestamp, decorate, #initialize

Constructor Details

This class inherits a constructor from BitbucketServer::Representation::Base

Instance Method Details

#authorObject



6
7
8
# File 'lib/bitbucket_server/representation/pull_request.rb', line 6

def author
  raw.dig('author', 'user', 'name')
end

#author_emailObject



10
11
12
# File 'lib/bitbucket_server/representation/pull_request.rb', line 10

def author_email
  raw.dig('author', 'user', 'emailAddress')
end

#author_usernameObject



14
15
16
17
18
# File 'lib/bitbucket_server/representation/pull_request.rb', line 14

def author_username
  raw.dig('author', 'user', 'username') ||
    raw.dig('author', 'user', 'slug') ||
    raw.dig('author', 'user', 'displayName')
end

#created_atObject



47
48
49
# File 'lib/bitbucket_server/representation/pull_request.rb', line 47

def created_at
  self.class.convert_timestamp(created_date)
end

#descriptionObject



20
21
22
# File 'lib/bitbucket_server/representation/pull_request.rb', line 20

def description
  raw['description']
end

#iidObject



28
29
30
# File 'lib/bitbucket_server/representation/pull_request.rb', line 28

def iid
  raw['id']
end

#merged?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/bitbucket_server/representation/pull_request.rb', line 43

def merged?
  state == 'merged'
end

#reviewersObject



24
25
26
# File 'lib/bitbucket_server/representation/pull_request.rb', line 24

def reviewers
  raw['reviewers']
end

#source_branch_nameObject



59
60
61
# File 'lib/bitbucket_server/representation/pull_request.rb', line 59

def source_branch_name
  raw.dig('fromRef', 'id')
end

#source_branch_shaObject



63
64
65
# File 'lib/bitbucket_server/representation/pull_request.rb', line 63

def source_branch_sha
  raw.dig('fromRef', 'latestCommit')
end

#stateObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/bitbucket_server/representation/pull_request.rb', line 32

def state
  case raw['state']
  when 'MERGED'
    'merged'
  when 'DECLINED'
    'closed'
  else
    'opened'
  end
end

#target_branch_nameObject



67
68
69
# File 'lib/bitbucket_server/representation/pull_request.rb', line 67

def target_branch_name
  raw.dig('toRef', 'id')
end

#target_branch_shaObject



71
72
73
# File 'lib/bitbucket_server/representation/pull_request.rb', line 71

def target_branch_sha
  raw.dig('toRef', 'latestCommit')
end

#titleObject



55
56
57
# File 'lib/bitbucket_server/representation/pull_request.rb', line 55

def title
  raw['title']
end

#to_hashObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/bitbucket_server/representation/pull_request.rb', line 75

def to_hash
  {
    iid: iid,
    author: author,
    author_email: author_email,
    author_username: author_username,
    description: description,
    reviewers: reviewers,
    created_at: created_at,
    updated_at: updated_at,
    state: state,
    title: title,
    source_branch_name: source_branch_name,
    source_branch_sha: source_branch_sha,
    target_branch_name: target_branch_name,
    target_branch_sha: target_branch_sha
  }
end

#updated_atObject



51
52
53
# File 'lib/bitbucket_server/representation/pull_request.rb', line 51

def updated_at
  self.class.convert_timestamp(updated_date)
end