Class: SupportOps::GitLab::Notes

Inherits:
Base
  • Object
show all
Defined in:
lib/support_ops_gitlab/gitlab/notes.rb

Overview

TODO:
TODO:
TODO:
TODO:
TODO:

Get single wiki page note (projects) => docs.gitlab.com/api/notes/#get-single-wiki-page-note

TODO:

Get single wiki page note (groups) => docs.gitlab.com/api/notes/#get-single-wiki-page-note-1

TODO:

Create/update for notes other than Issue and MergeRequest

TODO:

Document save!

TODO:

Document delete!

Defines the class Notes within the module SupportOps::GitLab.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#activate!, #approve!, attributes, #badges, #ban!, #block!, client, #client=, #commits, configure, #contributors, #create_support_pin!, #deactivate!, define_attributes, #delete!, #diffs, #disable_2fa!, #discussions, #emails, #encoded_path, #events, #find, #find!, #gpg_keys, #hard_delete!, #impersonations, #initialize, #issues, #jobs, #latest_pipeline, #members, #memberships, #merge_requests, #move!, #notes, #paid?, #pats, #pipeline_variables, #pipelines, #preferences, #projects, readonly_attributes, #reject!, #revoke!, #rotate!, #save!, #ssh_keys, #status, #store_original_attributes, #subscribe!, #support_pin, to_hash, #tokens, #unban!, #unblock!, #unsubscribe!, #webhooks

Constructor Details

This class inherits a constructor from SupportOps::GitLab::Base

Instance Attribute Details

#authorHash

Information about the author of a note

Returns:

  • (Hash)

    the current value of author



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def author
  @author
end

#bodyString

The content of a note

Returns:

  • (String)

    the current value of body



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def body
  @body
end

#confidentialBoolean

If the note is confidential or not

Returns:

  • (Boolean)

    the current value of confidential



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def confidential
  @confidential
end

#created_atString

The timestamp of when the note was created

Returns:

  • (String)

    the current value of created_at



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def created_at
  @created_at
end

#idInteger

The ID of the note

Returns:

  • (Integer)

    the current value of id



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def id
  @id
end

#importedBoolean

If the note was imported or not

Returns:

  • (Boolean)

    the current value of imported



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def imported
  @imported
end

#imported_fromString

Where the note was imported from

Returns:

  • (String)

    the current value of imported_from



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def imported_from
  @imported_from
end

#internalBoolean

If the note is internal or not

Returns:

  • (Boolean)

    the current value of internal



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def internal
  @internal
end

#merge_request_diff_head_shaString

The SHA of the head commit, which ensures the merge request wasn’t updated after the API request was sent

Returns:

  • (String)

    the current value of merge_request_diff_head_sha



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def merge_request_diff_head_sha
  @merge_request_diff_head_sha
end

#noteable_idInteger

The ID of the item the note is attached to

Returns:

  • (Integer)

    the current value of noteable_id



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def noteable_id
  @noteable_id
end

#noteable_iidInteger

The IID of the item the note is attached to

Returns:

  • (Integer)

    the current value of noteable_iid



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def noteable_iid
  @noteable_iid
end

#noteable_typeString

The type of item the note is attached to

Returns:

  • (String)

    the current value of noteable_type



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def noteable_type
  @noteable_type
end

#project_idInteger

The project ID the note is within

Returns:

  • (Integer)

    the current value of project_id



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def project_id
  @project_id
end

#resolvableBoolean

If the note is resolvable or not

Returns:

  • (Boolean)

    the current value of resolvable



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def resolvable
  @resolvable
end

#systemBoolean

If the note is from the system or not

Returns:

  • (Boolean)

    the current value of system



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def system
  @system
end

#updated_atString

The timestamp of when the note was last updated

Returns:

  • (String)

    the current value of updated_at



37
38
39
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 37

def updated_at
  @updated_at
end

Class Method Details

.base_url(type, type_id, project_id = nil, group_id = nil) ⇒ Object

Since:

  • 1.0.0



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 48

def self.base_url(type, type_id, project_id = nil, group_id = nil)
  return "projects/#{project_id}/issues/#{type_id}/notes" if type == 'Issue'
  return "projects/#{project_id}/snippets/#{type_id}/notes" if type == 'Snippet'
  return "projects/#{project_id}/merge_requests/#{type_id}/notes" if type == 'MergeRequest'
  return "groups/#{group_id}/epics/#{type_id}/notes" if type == 'Epic'
  return "groups/#{group_id}/epics/#{type_id}/notes" if type == 'Epic'
  if type == 'WikiPage::Meta'
    return "projects/#{project_id}/wiki_pages/#{type_id}/notes" if group_id.nil?
    return "groups/#{project_id}/wiki_pages/#{type_id}/notes" if project_id.nil?
  end
  raise "Unable to determine based on type of '#{type}'"
end

.list(key: value) ⇒ Array

Lists notes (comments)

Examples:

require 'support_ops_gitlab'

SupportOps::GitLab::Configuration.configure do |config|
  config.url = 'https://gitlab.example.com/api/v4'
  config.token = 'abc123'
end

xxx = SupportOps::GitLab::Notes.list(xxx)
pp xxx.count
# => 30
pp xxx.last.author['id']
# => 123

Parameters:

  • type (String required)

    The place to look for the notes, can be one of the following: Issue, Snippet, MergeRequest, Epic, WikiPage::Meta

  • group_id (Integer semi-optional)

    The group ID to look within; required when type is Epic, WikiPage::Meta (for project wikis)

  • project_id (Integer semi-optional)

    The project ID to look within; required when type is Issue, Snippet, MergeRequest, WikiPage::Meta (for project wikis)

  • type_id (Integer required)

    The ID of the type to look within

  • limit (Integer optional)

    The limit to the number of users returned. Default to 0 (i.e. no limit)

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/support_ops_gitlab/gitlab/notes.rb', line 106

def self.list(**args)
  args[:type] = nil unless args[:type_id]
  args[:group_id] = nil unless args[:type_id]
  args[:project_id] = nil unless args[:type_id]
  args[:type_id] = nil unless args[:type_id]
  args[:limit] = 0 unless args[:limit]
  raise 'You must provide a type' if args[:type].nil?
  raise 'You must provide a type_id' if args[:type_id].nil?
  raise 'You must provide a project_id' if ['Issue', 'Snippet', 'MergeRequest', 'WikiPage::Meta'].include?(args[:type]) && args[:project_id].nil?
  raise 'You must provide a group_id' if ['Epic', 'WikiPage::Meta'].include?(args[:type]) && args[:group_id].nil?
  url = base_url(args[:type], args[:type_id], args[:project_id], args[:group_id])
  array = []
  page = 1
  loop do
    response = client.connection.get("#{url}?page=#{page}&per_page=100")
    body = Oj.load(response.body)
    array += body.map { |n| Notes.new(n) }
    break if args[:limit].to_i.positive? && array.count >= args[:limit].to_i
    break if body.count < 100
  end
  return array if args[:limit].to_i.zero?
  
  array.first(args[:limit].to_i)
end