Class: SupportOps::GitLab::Events

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

Overview

TODO:

Document attribute definitions

Defines the class Events 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

#action_nameString

Returns the current value of action_name.

Returns:

  • (String)

    the current value of action_name



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def action_name
  @action_name
end

#authorHash

Returns the current value of author.

Returns:

  • (Hash)

    the current value of author



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def author
  @author
end

#author_idInteger

Returns the current value of author_id.

Returns:

  • (Integer)

    the current value of author_id



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def author_id
  @author_id
end

#author_usernameString

Returns the current value of author_username.

Returns:

  • (String)

    the current value of author_username



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def author_username
  @author_username
end

#created_atString

Returns the current value of created_at.

Returns:

  • (String)

    the current value of created_at



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def created_at
  @created_at
end

#idInteger

Returns the current value of id.

Returns:

  • (Integer)

    the current value of id



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def id
  @id
end

#importedBoolean

Returns the current value of imported.

Returns:

  • (Boolean)

    the current value of imported



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def imported
  @imported
end

#imported_fromString

Returns the current value of imported_from.

Returns:

  • (String)

    the current value of imported_from



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def imported_from
  @imported_from
end

#project_idInteger

Returns the current value of project_id.

Returns:

  • (Integer)

    the current value of project_id



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def project_id
  @project_id
end

#target_idInteger

Returns the current value of target_id.

Returns:

  • (Integer)

    the current value of target_id



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def target_id
  @target_id
end

#target_iidInteger

Returns the current value of target_iid.

Returns:

  • (Integer)

    the current value of target_iid



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def target_iid
  @target_iid
end

#target_titleString

Returns the current value of target_title.

Returns:

  • (String)

    the current value of target_title



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def target_title
  @target_title
end

#target_typeString

Returns the current value of target_type.

Returns:

  • (String)

    the current value of target_type



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def target_type
  @target_type
end

#titleString

Returns the current value of title.

Returns:

  • (String)

    the current value of title



28
29
30
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 28

def title
  @title
end

Class Method Details

.list(key: value) ⇒ Array

List all visible events for a project

Examples:

require 'support_ops_gitlab'

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

events = SupportOps::GitLab::Events.list(project_id: 123456)
pp events.count
# => 48
pp events.last.action_name
# => "opened"

Parameters:

  • project_id (Integer or String required)

    The ID or URL-encoded path of the project to get events for

  • action (String optional)

    If defined, returns events with the specified action type (approved, closed, commented, created, destroyed, expired, joined, left, merge, pushed, reopened, updated)

  • after (String optional)

    If defined, returns tokens created after the specified date (expects ISO 8601 format)

  • before (String optional)

    If defined, returns tokens created before the specified date (expects ISO 8601 format)

  • sort (String optional)

    Direction to sort the results by creation date; possible values: asc, desc

  • target_type (String optional)

    If defined, returns events with the specified target type (epic, issue, merge_request, milestone, note, project, snippet, user)

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 140

def self.list_project(**args)
  raise 'You have to provide a project_id' if args[:project_id].nil?
  args[:action] = nil unless args[:action]
  args[:after] = nil unless args[:after]
  args[:before] = nil unless args[:before]
  args[:sort] = nil unless args[:sort]
  args[:target_type] = nil unless args[:target_type]
  params = ''
  params += "action=#{args[:action]}&" unless args[:action].nil?
  params += "after=#{args[:after]}&" unless args[:after].nil?
  params += "before=#{args[:before]}&" unless args[:before].nil?
  params += "sort=#{args[:sort]}&" unless args[:sort].nil?
  params += "target_type=#{args[:target_type]}&" unless args[:target_type].nil?
  array = []
  page = 1
  loop do
    response = client.connection.get("projects/#{args[:project_id]}/events?#{params}&page=#{page}&per_page=100")
    body = Oj.load(response.body)
    array += body.map { |e| Events.new(e) }
    break if body.count < 100

    page += 1
  end
  array
end

.list(key: value) ⇒ Array

Get contribution events for a user

Examples:

require 'support_ops_gitlab'

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

events = SupportOps::GitLab::Events.list(user_id: 123456)
pp events.count
# => 30
pp events.last.action_name
# => "closed"

Parameters:

  • user_id (Integer or String required)

    The ID or username of the user to get events for

  • action (String optional)

    If defined, returns events with the specified action type (approved, closed, commented, created, destroyed, expired, joined, left, merge, pushed, reopened, updated)

  • after (String optional)

    If defined, returns tokens created after the specified date (expects ISO 8601 format)

  • before (String optional)

    If defined, returns tokens created before the specified date (expects ISO 8601 format)

  • sort (String optional)

    Direction to sort the results by creation date; possible values: asc, desc

  • target_type (String optional)

    If defined, returns events with the specified target type (epic, issue, merge_request, milestone, note, project, snippet, user)

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/support_ops_gitlab/gitlab/events.rb', line 76

def self.list_user(**args)
  raise 'You have to provide a user_id' if args[:user_id].nil?
  args[:action] = nil unless args[:action]
  args[:after] = nil unless args[:after]
  args[:before] = nil unless args[:before]
  args[:sort] = nil unless args[:sort]
  args[:target_type] = nil unless args[:target_type]
  params = ''
  params += "action=#{args[:action]}&" unless args[:action].nil?
  params += "after=#{args[:after]}&" unless args[:after].nil?
  params += "before=#{args[:before]}&" unless args[:before].nil?
  params += "sort=#{args[:sort]}&" unless args[:sort].nil?
  params += "target_type=#{args[:target_type]}&" unless args[:target_type].nil?
  array = []
  page = 1
  loop do
    response = client.connection.get("users/#{args[:user_id]}/events?#{params}&page=#{page}&per_page=100")
    body = Oj.load(response.body)
    array += body.map { |e| Events.new(e) }
    break if body.count < 100

    page += 1
  end
  array
end