Class: Worklog::Github::PullRequestReviewEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/github/pull_request_review_event.rb

Overview

Event representing a pull request review

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ PullRequestReviewEvent

Returns a new instance of PullRequestReviewEvent.



29
30
31
32
33
# File 'lib/github/pull_request_review_event.rb', line 29

def initialize(params = {})
  params.each do |key, value|
    send("#{key}=", value) if respond_to?("#{key}=")
  end
end

Instance Attribute Details

#created_atTime

Returns the creation time of the pull request review, not the pull request itself.

Returns:

  • (Time)

    the creation time of the pull request review, not the pull request itself



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/github/pull_request_review_event.rb', line 26

class PullRequestReviewEvent
  attr_accessor :repository, :number, :url, :title, :description, :creator, :created_at, :state

  def initialize(params = {})
    params.each do |key, value|
      send("#{key}=", value) if respond_to?("#{key}=")
    end
  end

  # Whether the pull request review was approved
  # @return [Boolean]
  def approved?
    state.downcase == 'approved'
  end

  # Convert the PullRequestReviewEvent to a LogEntry
  # @return [LogEntry]
  def to_log_entry(people_storage = nil)
    handle = resolve_username(people_storage) || creator

    message = String.new 'Reviewed '
    message << 'and approved ' if approved?
    message << "PR ##{number} #{handle}: #{title}"
    LogEntry.new(
      key: Hasher.sha256("#{repository}-#{number}-#{state}"),
      source: 'github',
      time: created_at,
      message: message,
      url: url
    )
  end

  # String representation of the PullRequestReviewEvent
  # @return [String]
  def to_s
    "#<PullRequestReviewEvent repository=#{repository} number=#{number} state=#{state} creator=#{creator} created_at=#{created_at}>" # rubocop:disable Layout/LineLength
  end

  private

  # Resolve the GitHub username to a person handle using the provided PeopleStorage
  # @param [PeopleStorage, nil] people_storage The PeopleStorage instance to use for resolution
  # @return [String, nil] The person handle if found, otherwise nil
  # @example
  #  resolve_username(people_storage) #=> "~johndoe"
  def resolve_username(people_storage)
    return if people_storage.nil?

    person = people_storage.find_by_github_username(creator)
    person ? "~#{person.handle}" : nil
  end
end

#creatorString

Returns:

  • (String)

    the description of the pull request

  • (String)

    the username of the pull request creator



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/github/pull_request_review_event.rb', line 26

class PullRequestReviewEvent
  attr_accessor :repository, :number, :url, :title, :description, :creator, :created_at, :state

  def initialize(params = {})
    params.each do |key, value|
      send("#{key}=", value) if respond_to?("#{key}=")
    end
  end

  # Whether the pull request review was approved
  # @return [Boolean]
  def approved?
    state.downcase == 'approved'
  end

  # Convert the PullRequestReviewEvent to a LogEntry
  # @return [LogEntry]
  def to_log_entry(people_storage = nil)
    handle = resolve_username(people_storage) || creator

    message = String.new 'Reviewed '
    message << 'and approved ' if approved?
    message << "PR ##{number} #{handle}: #{title}"
    LogEntry.new(
      key: Hasher.sha256("#{repository}-#{number}-#{state}"),
      source: 'github',
      time: created_at,
      message: message,
      url: url
    )
  end

  # String representation of the PullRequestReviewEvent
  # @return [String]
  def to_s
    "#<PullRequestReviewEvent repository=#{repository} number=#{number} state=#{state} creator=#{creator} created_at=#{created_at}>" # rubocop:disable Layout/LineLength
  end

  private

  # Resolve the GitHub username to a person handle using the provided PeopleStorage
  # @param [PeopleStorage, nil] people_storage The PeopleStorage instance to use for resolution
  # @return [String, nil] The person handle if found, otherwise nil
  # @example
  #  resolve_username(people_storage) #=> "~johndoe"
  def resolve_username(people_storage)
    return if people_storage.nil?

    person = people_storage.find_by_github_username(creator)
    person ? "~#{person.handle}" : nil
  end
end

#descriptionString

Returns:

  • (String)

    the description of the pull request

  • (String)

    the username of the pull request creator



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/github/pull_request_review_event.rb', line 26

class PullRequestReviewEvent
  attr_accessor :repository, :number, :url, :title, :description, :creator, :created_at, :state

  def initialize(params = {})
    params.each do |key, value|
      send("#{key}=", value) if respond_to?("#{key}=")
    end
  end

  # Whether the pull request review was approved
  # @return [Boolean]
  def approved?
    state.downcase == 'approved'
  end

  # Convert the PullRequestReviewEvent to a LogEntry
  # @return [LogEntry]
  def to_log_entry(people_storage = nil)
    handle = resolve_username(people_storage) || creator

    message = String.new 'Reviewed '
    message << 'and approved ' if approved?
    message << "PR ##{number} #{handle}: #{title}"
    LogEntry.new(
      key: Hasher.sha256("#{repository}-#{number}-#{state}"),
      source: 'github',
      time: created_at,
      message: message,
      url: url
    )
  end

  # String representation of the PullRequestReviewEvent
  # @return [String]
  def to_s
    "#<PullRequestReviewEvent repository=#{repository} number=#{number} state=#{state} creator=#{creator} created_at=#{created_at}>" # rubocop:disable Layout/LineLength
  end

  private

  # Resolve the GitHub username to a person handle using the provided PeopleStorage
  # @param [PeopleStorage, nil] people_storage The PeopleStorage instance to use for resolution
  # @return [String, nil] The person handle if found, otherwise nil
  # @example
  #  resolve_username(people_storage) #=> "~johndoe"
  def resolve_username(people_storage)
    return if people_storage.nil?

    person = people_storage.find_by_github_username(creator)
    person ? "~#{person.handle}" : nil
  end
end

#numberInteger

Returns the pull request number.

Returns:

  • (Integer)

    the pull request number



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/github/pull_request_review_event.rb', line 26

class PullRequestReviewEvent
  attr_accessor :repository, :number, :url, :title, :description, :creator, :created_at, :state

  def initialize(params = {})
    params.each do |key, value|
      send("#{key}=", value) if respond_to?("#{key}=")
    end
  end

  # Whether the pull request review was approved
  # @return [Boolean]
  def approved?
    state.downcase == 'approved'
  end

  # Convert the PullRequestReviewEvent to a LogEntry
  # @return [LogEntry]
  def to_log_entry(people_storage = nil)
    handle = resolve_username(people_storage) || creator

    message = String.new 'Reviewed '
    message << 'and approved ' if approved?
    message << "PR ##{number} #{handle}: #{title}"
    LogEntry.new(
      key: Hasher.sha256("#{repository}-#{number}-#{state}"),
      source: 'github',
      time: created_at,
      message: message,
      url: url
    )
  end

  # String representation of the PullRequestReviewEvent
  # @return [String]
  def to_s
    "#<PullRequestReviewEvent repository=#{repository} number=#{number} state=#{state} creator=#{creator} created_at=#{created_at}>" # rubocop:disable Layout/LineLength
  end

  private

  # Resolve the GitHub username to a person handle using the provided PeopleStorage
  # @param [PeopleStorage, nil] people_storage The PeopleStorage instance to use for resolution
  # @return [String, nil] The person handle if found, otherwise nil
  # @example
  #  resolve_username(people_storage) #=> "~johndoe"
  def resolve_username(people_storage)
    return if people_storage.nil?

    person = people_storage.find_by_github_username(creator)
    person ? "~#{person.handle}" : nil
  end
end

#repositoryString

Returns the repository name.

Returns:

  • (String)

    the repository name



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/github/pull_request_review_event.rb', line 26

class PullRequestReviewEvent
  attr_accessor :repository, :number, :url, :title, :description, :creator, :created_at, :state

  def initialize(params = {})
    params.each do |key, value|
      send("#{key}=", value) if respond_to?("#{key}=")
    end
  end

  # Whether the pull request review was approved
  # @return [Boolean]
  def approved?
    state.downcase == 'approved'
  end

  # Convert the PullRequestReviewEvent to a LogEntry
  # @return [LogEntry]
  def to_log_entry(people_storage = nil)
    handle = resolve_username(people_storage) || creator

    message = String.new 'Reviewed '
    message << 'and approved ' if approved?
    message << "PR ##{number} #{handle}: #{title}"
    LogEntry.new(
      key: Hasher.sha256("#{repository}-#{number}-#{state}"),
      source: 'github',
      time: created_at,
      message: message,
      url: url
    )
  end

  # String representation of the PullRequestReviewEvent
  # @return [String]
  def to_s
    "#<PullRequestReviewEvent repository=#{repository} number=#{number} state=#{state} creator=#{creator} created_at=#{created_at}>" # rubocop:disable Layout/LineLength
  end

  private

  # Resolve the GitHub username to a person handle using the provided PeopleStorage
  # @param [PeopleStorage, nil] people_storage The PeopleStorage instance to use for resolution
  # @return [String, nil] The person handle if found, otherwise nil
  # @example
  #  resolve_username(people_storage) #=> "~johndoe"
  def resolve_username(people_storage)
    return if people_storage.nil?

    person = people_storage.find_by_github_username(creator)
    person ? "~#{person.handle}" : nil
  end
end

#stateString

Returns the state of the review (e.g., ‘approved’, ‘changes_requested’, etc.).

Returns:

  • (String)

    the state of the review (e.g., ‘approved’, ‘changes_requested’, etc.)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/github/pull_request_review_event.rb', line 26

class PullRequestReviewEvent
  attr_accessor :repository, :number, :url, :title, :description, :creator, :created_at, :state

  def initialize(params = {})
    params.each do |key, value|
      send("#{key}=", value) if respond_to?("#{key}=")
    end
  end

  # Whether the pull request review was approved
  # @return [Boolean]
  def approved?
    state.downcase == 'approved'
  end

  # Convert the PullRequestReviewEvent to a LogEntry
  # @return [LogEntry]
  def to_log_entry(people_storage = nil)
    handle = resolve_username(people_storage) || creator

    message = String.new 'Reviewed '
    message << 'and approved ' if approved?
    message << "PR ##{number} #{handle}: #{title}"
    LogEntry.new(
      key: Hasher.sha256("#{repository}-#{number}-#{state}"),
      source: 'github',
      time: created_at,
      message: message,
      url: url
    )
  end

  # String representation of the PullRequestReviewEvent
  # @return [String]
  def to_s
    "#<PullRequestReviewEvent repository=#{repository} number=#{number} state=#{state} creator=#{creator} created_at=#{created_at}>" # rubocop:disable Layout/LineLength
  end

  private

  # Resolve the GitHub username to a person handle using the provided PeopleStorage
  # @param [PeopleStorage, nil] people_storage The PeopleStorage instance to use for resolution
  # @return [String, nil] The person handle if found, otherwise nil
  # @example
  #  resolve_username(people_storage) #=> "~johndoe"
  def resolve_username(people_storage)
    return if people_storage.nil?

    person = people_storage.find_by_github_username(creator)
    person ? "~#{person.handle}" : nil
  end
end

#titleString

Returns the title of the pull request.

Returns:

  • (String)

    the title of the pull request



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/github/pull_request_review_event.rb', line 26

class PullRequestReviewEvent
  attr_accessor :repository, :number, :url, :title, :description, :creator, :created_at, :state

  def initialize(params = {})
    params.each do |key, value|
      send("#{key}=", value) if respond_to?("#{key}=")
    end
  end

  # Whether the pull request review was approved
  # @return [Boolean]
  def approved?
    state.downcase == 'approved'
  end

  # Convert the PullRequestReviewEvent to a LogEntry
  # @return [LogEntry]
  def to_log_entry(people_storage = nil)
    handle = resolve_username(people_storage) || creator

    message = String.new 'Reviewed '
    message << 'and approved ' if approved?
    message << "PR ##{number} #{handle}: #{title}"
    LogEntry.new(
      key: Hasher.sha256("#{repository}-#{number}-#{state}"),
      source: 'github',
      time: created_at,
      message: message,
      url: url
    )
  end

  # String representation of the PullRequestReviewEvent
  # @return [String]
  def to_s
    "#<PullRequestReviewEvent repository=#{repository} number=#{number} state=#{state} creator=#{creator} created_at=#{created_at}>" # rubocop:disable Layout/LineLength
  end

  private

  # Resolve the GitHub username to a person handle using the provided PeopleStorage
  # @param [PeopleStorage, nil] people_storage The PeopleStorage instance to use for resolution
  # @return [String, nil] The person handle if found, otherwise nil
  # @example
  #  resolve_username(people_storage) #=> "~johndoe"
  def resolve_username(people_storage)
    return if people_storage.nil?

    person = people_storage.find_by_github_username(creator)
    person ? "~#{person.handle}" : nil
  end
end

#urlString

Returns the URL of the pull request review.

Returns:

  • (String)

    the URL of the pull request review



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/github/pull_request_review_event.rb', line 26

class PullRequestReviewEvent
  attr_accessor :repository, :number, :url, :title, :description, :creator, :created_at, :state

  def initialize(params = {})
    params.each do |key, value|
      send("#{key}=", value) if respond_to?("#{key}=")
    end
  end

  # Whether the pull request review was approved
  # @return [Boolean]
  def approved?
    state.downcase == 'approved'
  end

  # Convert the PullRequestReviewEvent to a LogEntry
  # @return [LogEntry]
  def to_log_entry(people_storage = nil)
    handle = resolve_username(people_storage) || creator

    message = String.new 'Reviewed '
    message << 'and approved ' if approved?
    message << "PR ##{number} #{handle}: #{title}"
    LogEntry.new(
      key: Hasher.sha256("#{repository}-#{number}-#{state}"),
      source: 'github',
      time: created_at,
      message: message,
      url: url
    )
  end

  # String representation of the PullRequestReviewEvent
  # @return [String]
  def to_s
    "#<PullRequestReviewEvent repository=#{repository} number=#{number} state=#{state} creator=#{creator} created_at=#{created_at}>" # rubocop:disable Layout/LineLength
  end

  private

  # Resolve the GitHub username to a person handle using the provided PeopleStorage
  # @param [PeopleStorage, nil] people_storage The PeopleStorage instance to use for resolution
  # @return [String, nil] The person handle if found, otherwise nil
  # @example
  #  resolve_username(people_storage) #=> "~johndoe"
  def resolve_username(people_storage)
    return if people_storage.nil?

    person = people_storage.find_by_github_username(creator)
    person ? "~#{person.handle}" : nil
  end
end

Instance Method Details

#approved?Boolean

Whether the pull request review was approved

Returns:

  • (Boolean)


37
38
39
# File 'lib/github/pull_request_review_event.rb', line 37

def approved?
  state.downcase == 'approved'
end

#to_log_entry(people_storage = nil) ⇒ LogEntry

Convert the PullRequestReviewEvent to a LogEntry

Returns:

  • (LogEntry)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/github/pull_request_review_event.rb', line 43

def to_log_entry(people_storage = nil)
  handle = resolve_username(people_storage) || creator

  message = String.new 'Reviewed '
  message << 'and approved ' if approved?
  message << "PR ##{number} #{handle}: #{title}"
  LogEntry.new(
    key: Hasher.sha256("#{repository}-#{number}-#{state}"),
    source: 'github',
    time: created_at,
    message: message,
    url: url
  )
end

#to_sString

String representation of the PullRequestReviewEvent

Returns:

  • (String)


60
61
62
# File 'lib/github/pull_request_review_event.rb', line 60

def to_s
  "#<PullRequestReviewEvent repository=#{repository} number=#{number} state=#{state} creator=#{creator} created_at=#{created_at}>" # rubocop:disable Layout/LineLength
end